From cc6dcb6c5b6e15abd72a6ec3b5745e21454d7a1d Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Mon, 1 Dec 2025 12:48:35 +0100 Subject: [PATCH] Extract mysql setup to function --- README.md | 2 +- bin/setup | 33 ++++++++++++++++++--------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index e0c2218b4..b668747e9 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ The full continuous integration tests can be run with: ### Database configuration -Fizzy works on SQLite by default and supports MySQL too. You can switch adapters with the `DATABASE_ADAPTER` environment variable. For example, to develop locally against MySQL: +Fizzy works with SQLite by default and supports MySQL too. You can switch adapters with the `DATABASE_ADAPTER` environment variable. For example, to develop locally against MySQL: ```sh DATABASE_ADAPTER=mysql bin/setup --reset diff --git a/bin/setup b/bin/setup index af296c2bf..c29d5e1d6 100755 --- a/bin/setup +++ b/bin/setup @@ -58,6 +58,23 @@ needs_seeding() { fi } +oss_mysql_setup() { + if ! nc -z localhost 3306 2>/dev/null; then + if docker ps -aq -f name=fizzy-mysql | grep -q .; then + step "Starting MySQL" docker start fizzy-mysql + else + step "Setting up MySQL" bash -c ' + docker pull mysql:8.4 + docker run -d \ + --name fizzy-mysql \ + -e MYSQL_ALLOW_EMPTY_PASSWORD=yes \ + -p 3306:3306 \ + mysql:8.4 + echo "MySQL is starting… (it may take a few seconds)" + ' + fi + fi +} echo gum style --foreground 153 " ˚ ∘ ∘ ˚ " @@ -85,21 +102,7 @@ if [ -n "$SAAS" ]; then source "$saas_setup" else if [ "$DATABASE_ADAPTER" = "mysql" ]; then - if ! nc -z localhost 3306 2>/dev/null; then - if docker ps -aq -f name=fizzy-mysql | grep -q .; then - step "Starting MySQL" docker start fizzy-mysql - else - step "Setting up MySQL" bash -c ' - docker pull mysql:8.4 - docker run -d \ - --name fizzy-mysql \ - -e MYSQL_ALLOW_EMPTY_PASSWORD=yes \ - -p 3306:3306 \ - mysql:8.4 - echo "MySQL is starting… (it may take a few seconds)" - ' - fi - fi + oss_mysql_setup fi fi