diff --git a/bin/setup b/bin/setup index 3c3c02fdc..5a3eda882 100755 --- a/bin/setup +++ b/bin/setup @@ -58,6 +58,24 @@ needs_seeding() { fi } + +setup_database() { + local adapter="$1" + local reset="$2" + local label="${adapter:+ ($adapter)}" + local env_cmd="${adapter:+env DATABASE_ADAPTER=$adapter}" + + 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 " ∘˚˳°∘° 𝒻𝒾𝓏𝓏𝓎 °∘°˳˚∘ " @@ -100,27 +118,16 @@ else fi fi -if [ -n "$SAAS" ]; then - if [[ $* == *--reset* ]]; then - step "Resetting the database" rails db:reset - else - step "Preparing the database" rails db:prepare +reset_flag="" +[[ $* == *--reset* ]] && reset_flag="true" - if needs_seeding; then - step "Seeding the database" rails db:seed - fi - fi +if [ -n "$SAAS" ]; then + for adapter in saas sqlite; do + setup_database "$adapter" "$reset_flag" + done else for adapter in sqlite mysql; do - if [[ $* == *--reset* ]]; then - step "Resetting the database ($adapter)" env DATABASE_ADAPTER=$adapter rails db:reset - else - step "Preparing the database ($adapter)" env DATABASE_ADAPTER=$adapter rails db:prepare - - if needs_seeding; then - step "Seeding the database ($adapter)" env DATABASE_ADAPTER=$adapter rails db:seed - fi - fi + setup_database "$adapter" "$reset_flag" done fi diff --git a/config/ci.rb b/config/ci.rb index b642c2534..d4bdfd9ea 100644 --- a/config/ci.rb +++ b/config/ci.rb @@ -2,6 +2,9 @@ require_relative "../lib/fizzy" +OSS_ENV = "SAAS=false BUNDLE_GEMFILE=Gemfile" +SAAS_ENV = "SAAS=true BUNDLE_GEMFILE=Gemfile.saas" + CI.run do step "Setup", "bin/setup --skip-server" @@ -12,13 +15,13 @@ CI.run do step "Security: Brakeman audit", "bin/brakeman --quiet --no-pager --exit-on-warn --exit-on-error" if Fizzy.saas? - step "Tests: SaaS", "SAAS=true BUNDLE_GEMFILE=Gemfile.saas bin/rails test:all" + step "Tests: SaaS", "#{SAAS_ENV} bin/rails test:all" + step "Tests: SQLite", "#{OSS_ENV} DATABASE_ADAPTER=sqlite bin/rails test:all" else - step "Tests: MySQL", "SAAS=false BUNDLE_GEMFILE=Gemfile DATABASE_ADAPTER=mysql bin/rails test:all" - step "Tests: SQLite", "SAAS=false BUNDLE_GEMFILE=Gemfile DATABASE_ADAPTER=sqlite bin/rails test:all" + step "Tests: MySQL", "#{OSS_ENV} DATABASE_ADAPTER=mysql bin/rails test:all" + step "Tests: SQLite", "#{OSS_ENV} DATABASE_ADAPTER=sqlite bin/rails test:all" end - if success? step "Signoff: All systems go. Ready for merge and deploy.", "gh signoff" else