diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index 9813e15..5688bb6 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -13,20 +13,33 @@ jobs: BUNDLE_JOBS: 4 BUNDLE_RETRY: 3 BUNDLE_GEMFILE: ${{ matrix.gemfile }} - DATABASE_URL: postgres://postgres:postgres@localhost:5432 + POSTGRES_URL: postgres://postgres:postgres@localhost:5432 + MYSQL_URL: mysql2://rails:rails@127.0.0.1:3306 + DB: ${{ matrix.db }} + DB_NAME: slotted_counters_test CI: true strategy: fail-fast: false matrix: ruby: ["3.0"] gemfile: ["gemfiles/rails7.gemfile"] + db: ["mysql"] include: - ruby: "2.7" gemfile: "gemfiles/rails6.gemfile" + db: "postgres" - ruby: "3.1" gemfile: "gemfiles/railsmaster.gemfile" + db: "postgres" - ruby: "3.0" gemfile: "gemfiles/rails7.gemfile" + db: "postgres" + - ruby: "2.7" + gemfile: "gemfiles/rails6.gemfile" + db: "mysql" + - ruby: "3.1" + gemfile: "gemfiles/railsmaster.gemfile" + db: "mysql" services: postgres: image: postgres:14 @@ -38,6 +51,19 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 + mysql: + image: mysql:8 + ports: [ "3306:3306" ] + env: + MYSQL_PASSWORD: rails + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: slotted_counters_test + MYSQL_USER: rails + options: >- + --health-cmd "mysqladmin ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 steps: - uses: actions/checkout@v3 - name: Install system deps diff --git a/gemfiles/rails6.gemfile b/gemfiles/rails6.gemfile index adfac56..0c57570 100644 --- a/gemfiles/rails6.gemfile +++ b/gemfiles/rails6.gemfile @@ -1,5 +1,6 @@ source "https://rubygems.org" gem "rails", "~> 6.0" +gem "mysql2" gemspec path: ".." diff --git a/gemfiles/rails7.gemfile b/gemfiles/rails7.gemfile index 8aebf01..9ef939e 100644 --- a/gemfiles/rails7.gemfile +++ b/gemfiles/rails7.gemfile @@ -1,5 +1,6 @@ source "https://rubygems.org" gem "rails", "~> 7.0" +gem "mysql2" gemspec path: ".." diff --git a/gemfiles/railsmaster.gemfile b/gemfiles/railsmaster.gemfile index 46812d4..5efbfc6 100644 --- a/gemfiles/railsmaster.gemfile +++ b/gemfiles/railsmaster.gemfile @@ -1,5 +1,6 @@ source "https://rubygems.org" gem "rails", github: "rails/rails" +gem "mysql2" gemspec path: ".." diff --git a/spec/support/active_record_init.rb b/spec/support/active_record_init.rb index 39d2244..8eb4df1 100644 --- a/spec/support/active_record_init.rb +++ b/spec/support/active_record_init.rb @@ -1,22 +1,29 @@ # frozen_string_literal: true -connection_params = - if ENV.key?("DATABASE_URL") - {"url" => ENV["DATABASE_URL"]} - else - { - "host" => ENV.fetch("DB_HOST", "localhost"), - "username" => ENV.fetch("DB_USER", "postgres"), - "port" => ENV.fetch("DB_PORT", "9339").to_i - } +DB_CONFIG = + if ENV["DB"] == "postgres" || ENV["DB"] == "mysql" + require "active_record/database_configurations" + url = ENV.fetch("DATABASE_URL") do + case ENV["DB"] + when "postgres" + ENV.fetch("POSTGRES_URL") + when "mysql" + ENV.fetch("MYSQL_URL") + end + end + + config = ActiveRecord::DatabaseConfigurations::UrlConfig.new( + "test", + "primary", + url, + {"database" => ENV.fetch("DB_NAME", "slotted_counters_test")} + ) + config.respond_to?(:configuration_hash) ? config.configuration_hash : config.config end -ActiveRecord::Base.establish_connection( - { - "adapter" => "postgresql", - "database" => "slotted_counters_test" - }.merge(connection_params) -) +$stdout.puts "⚙️ Using #{DB_CONFIG[:adapter]} adapter for a database" + +ActiveRecord::Base.establish_connection(**DB_CONFIG) ActiveRecord::Schema.define do create_table "views", force: :cascade do |t|