Skip to content

Commit

Permalink
Add running CI with mysql2 adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
prog-supdex committed Oct 19, 2023
1 parent 5b9566a commit 7fd17b0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 16 deletions.
28 changes: 27 additions & 1 deletion .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails6.gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
source "https://rubygems.org"

gem "rails", "~> 6.0"
gem "mysql2"

gemspec path: ".."
1 change: 1 addition & 0 deletions gemfiles/rails7.gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
source "https://rubygems.org"

gem "rails", "~> 7.0"
gem "mysql2"

gemspec path: ".."
1 change: 1 addition & 0 deletions gemfiles/railsmaster.gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
source "https://rubygems.org"

gem "rails", github: "rails/rails"
gem "mysql2"

gemspec path: ".."
37 changes: 22 additions & 15 deletions spec/support/active_record_init.rb
Original file line number Diff line number Diff line change
@@ -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|
Expand Down

0 comments on commit 7fd17b0

Please sign in to comment.