Skip to content

feat: support of multidb #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 0 additions & 59 deletions .github/workflows/ci-mysql8.yml

This file was deleted.

61 changes: 0 additions & 61 deletions .github/workflows/ci-postgresql.yml

This file was deleted.

80 changes: 80 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: CI

on:
pull_request:
branches:
- master

concurrency:
group: ci-${{ github.head_ref }}
cancel-in-progress: true

jobs:
minitest:
runs-on: ubuntu-latest
name: CI Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }}
services:
postgres:
image: 'postgres:17-alpine'
ports:
- '5432'
env:
POSTGRES_USER: with_advisory
POSTGRES_PASSWORD: with_advisory_pass
POSTGRES_DB: with_advisory_lock_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
mysql:
image: mysql/mysql-server
ports:
- 3306
env:
MYSQL_USER: with_advisory
MYSQL_PASSWORD: with_advisory_pass
MYSQL_DATABASE: with_advisory_lock_test
MYSQL_ROOT_HOST: '%'
strategy:
fail-fast: false
matrix:
ruby:
- '3.3'
- '3.4'
- 'truffleruby'
rails:
- 7.1
- 7.2
- "8.0"
include:
- ruby: jruby
rails: 7.1
env:
ACTIVERECORD_VERSION: ${{ matrix.rails }}
RAILS_ENV: test
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
rubygems: latest

- name: Setup test databases
env:
DATABASE_URL_PG: postgres://with_advisory:with_advisory_pass@localhost:${{ job.services.postgres.ports[5432] }}/with_advisory_lock_test
DATABASE_URL_MYSQL: mysql2://with_advisory:[email protected]:${{ job.services.mysql.ports[3306] }}/with_advisory_lock_test
run: |
cd test/dummy
bundle exec rake db:test:prepare

- name: Test
env:
DATABASE_URL_PG: postgres://with_advisory:with_advisory_pass@localhost:${{ job.services.postgres.ports[5432] }}/with_advisory_lock_test
DATABASE_URL_MYSQL: mysql2://with_advisory:[email protected]:${{ job.services.mysql.ports[3306] }}/with_advisory_lock_test
WITH_ADVISORY_LOCK_PREFIX: ${{ github.run_id }}
run: bin/rails test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -18,4 +18,5 @@ test/tmp
test/version_tmp
tmp
*.iml
.env
.env
test/dummy/log/
33 changes: 0 additions & 33 deletions Appraisals

This file was deleted.

30 changes: 30 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec

gem 'rake'

# Gems that will be removed from default gems in Ruby 3.5.0
gem 'benchmark'
gem 'logger'
gem 'ostruct'

activerecord_version = ENV.fetch('ACTIVERECORD_VERSION', '7.1')

gem 'activerecord', "~> #{activerecord_version}.0"

gem 'dotenv'
gem 'railties'

platforms :ruby do
gem 'mysql2'
gem 'pg'
gem 'trilogy'
end

platforms :jruby do
# JRuby JDBC adapters only support Rails 7.1 currently
if activerecord_version == '7.1'
gem 'activerecord-jdbcmysql-adapter', '~> 71.0'
gem 'activerecord-jdbcpostgresql-adapter', '~> 71.0'
end
end
20 changes: 8 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
.PHONY: test-pg test-mysql
.PHONY: test

test-pg:
docker compose up -d pg
sleep 10 # give some time for the service to start
DATABASE_URL_PG=postgres://with_advisory:with_advisory_pass@localhost/with_advisory_lock_test appraisal rake test
test: setup-db
bin/rails test

test-mysql:
docker compose up -d mysql
sleep 10 # give some time for the service to start
DATABASE_URL_MYSQL=mysql2://with_advisory:[email protected]:3306/with_advisory_lock_test appraisal rake test


test: test-pg test-mysql
setup-db:
docker compose up -d
sleep 2
bundle
bin/setup_test_db
10 changes: 8 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require "bundler/gem_tasks"
# frozen_string_literal: true

require 'bundler/gem_tasks'

require 'yard'
YARD::Rake::YardocTask.new do |t|
@@ -14,4 +16,8 @@ Rake::TestTask.new do |t|
t.verbose = true
end

task :default => :test
# Load Rails tasks from dummy app to get db:test:prepare
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
load 'rails/tasks/engine.rake' if File.exist?(APP_RAKEFILE)

task default: :test
2 changes: 1 addition & 1 deletion bin/rails
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
# This command will automatically be run when you run "rails" with Rails gems
# installed from the root of your application.

ENGINE_ROOT = File.expand_path('../test/dummy', __dir__)
ENGINE_ROOT = File.expand_path('..', __dir__)
APP_PATH = File.expand_path('../test/dummy/config/application', __dir__)

# Set up gems listed in the Gemfile.
20 changes: 20 additions & 0 deletions bin/sanity
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail

check_port() {
local port="$1"
local name="$2"
if nc -z localhost "$port" >/dev/null 2>&1; then
echo "$name running on port $port"
else
echo "ERROR: $name is not running on port $port" >&2
return 1
fi
}

main() {
check_port 5433 "Postgresql"
check_port 3366 "Mysql"
}

main "$@"
Loading