From 12de5641763e3f9871069e140cfd44daf3deaded Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Mon, 1 Dec 2025 12:46:37 +0100 Subject: [PATCH] Remove MySQL from default local development setup https://3.basecamp.com/2914079/buckets/37331921/chats/9301300227@9334968661 --- README.md | 9 ++++--- bin/setup | 69 +++++++++++++++++----------------------------------- config/ci.rb | 8 ++---- 3 files changed, 29 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index e88bca3c3..e0c2218b4 100644 --- a/README.md +++ b/README.md @@ -35,14 +35,15 @@ The full continuous integration tests can be run with: ### Database configuration -Fizzy supports SQLite (default, recommended for most scenarios) and MySQL. You can switch adapters with the `DATABASE_ADAPTER` environment variable. +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: ```sh -DATABASE_ADAPTER=mysql bin/rails -DATABASE_ADAPTER=mysql bin/test -bin/ci # Runs tests against both SQLite and MySQL +DATABASE_ADAPTER=mysql bin/setup --reset +DATABASE_ADAPTER=mysql bin/ci ``` +The remote CI pipeline will run tests against both SQLite and MySQL. + ### Outbound Emails You can view email previews at http://fizzy.localhost:3006/rails/mailers. diff --git a/bin/setup b/bin/setup index b89de589d..af296c2bf 100755 --- a/bin/setup +++ b/bin/setup @@ -59,30 +59,6 @@ needs_seeding() { } -setup_database() { - local adapter="$1" - local reset="$2" - local label="${adapter:+ ($adapter)}" - local env_cmd="${adapter:+env DATABASE_ADAPTER=$adapter}" - - # When setting up sqlite in SAAS mode, we need to disable SAAS so that - # database.yml will use database.sqlite.yml instead of the fizzy-saas config. - # We also unset BUNDLE_GEMFILE so the standard Gemfile is used (without fizzy-saas). - if [ -n "$SAAS" ] && [ "$adapter" = "sqlite" ]; then - env_cmd="env DATABASE_ADAPTER=$adapter SAAS=false BUNDLE_GEMFILE=" - fi - - if [ "$reset" = "true" ]; then - step "Resetting the database$label" $env_cmd rails db:reset - else - step "Preparing the database$label" $env_cmd rails db:prepare - - if needs_seeding; then - step "Seeding the database$label" $env_cmd rails db:seed - fi - fi -} - echo gum style --foreground 153 " ˚ ∘ ∘ ˚ " gum style --foreground 111 --bold " ∘˚˳°∘° 𝒻𝒾𝓏𝓏𝓎 °∘°˳˚∘ " @@ -108,34 +84,33 @@ if [ -n "$SAAS" ]; then saas_setup=$(bundle show fizzy-saas)/bin/setup source "$saas_setup" else - 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)" - ' + 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 fi fi -reset_flag="" -[[ $* == *--reset* ]] && reset_flag="true" - -if [ -n "$SAAS" ]; then - for adapter in saas sqlite; do - setup_database "$adapter" "$reset_flag" - done +if [[ $* == *--reset* ]]; then + step "Resetting the database" rails db:reset else - for adapter in sqlite mysql; do - setup_database "$adapter" "$reset_flag" - done + step "Preparing the database" rails db:prepare + + if needs_seeding; then + step "Seeding the database" rails db:seed + fi fi step "Cleaning up logs and tempfiles" rails log:clear tmp:clear diff --git a/config/ci.rb b/config/ci.rb index aeab8a647..053fe2682 100644 --- a/config/ci.rb +++ b/config/ci.rb @@ -19,13 +19,9 @@ CI.run do if Fizzy.saas? step "Tests: SaaS", "#{SAAS_ENV} bin/rails test" step "Tests: SaaS System", "#{SAAS_ENV} #{SYSTEM_TEST_ENV} bin/rails test:system" - step "Tests: SQLite", "#{OSS_ENV} DATABASE_ADAPTER=sqlite bin/rails test" - step "Tests: SQLite System", "#{OSS_ENV} DATABASE_ADAPTER=sqlite #{SYSTEM_TEST_ENV} bin/rails test:system" else - step "Tests: MySQL", "#{OSS_ENV} DATABASE_ADAPTER=mysql bin/rails test" - step "Tests: MySQL System", "#{OSS_ENV} DATABASE_ADAPTER=mysql #{SYSTEM_TEST_ENV} bin/rails test:system" - step "Tests: SQLite", "#{OSS_ENV} DATABASE_ADAPTER=sqlite bin/rails test" - step "Tests: SQLite System", "#{OSS_ENV} DATABASE_ADAPTER=sqlite #{SYSTEM_TEST_ENV} bin/rails test:system" + step "Tests: SQLite", "#{OSS_ENV} bin/rails test" + step "Tests: SQLite System", "#{OSS_ENV} #{SYSTEM_TEST_ENV} bin/rails test:system" end if success?