diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 7766fb35..39a0338a 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -4,13 +4,12 @@ on: push: branches: - master - pull_request: jobs: - build: + postgres: runs-on: ubuntu-latest - name: Ruby ${{ matrix.ruby }} + name: Ruby ${{ matrix.ruby }} with PostgreSQL strategy: matrix: ruby: @@ -19,10 +18,13 @@ jobs: postgres: image: postgres:latest env: + DATABASE_ADAPTER: postgresql + DATABASE_PORT: 5432 POSTGRES_USER: outboxer_developer POSTGRES_PASSWORD: outboxer_password POSTGRES_DB: outboxer_test - ports: ['5432:5432'] + ports: + - 5432:5432 options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: - uses: actions/checkout@v3 @@ -38,5 +40,57 @@ jobs: psql -h localhost -U outboxer_developer -d outboxer_test -c 'SELECT version();' - name: Run Database Migrations run: RAILS_ENV=test bin/rake outboxer:db:migrate - - name: Run the default task + - name: Run Tests run: RAILS_ENV=test bin/rspec spec + + mysql: + runs-on: ubuntu-latest + name: Ruby ${{ matrix.ruby }} with MySQL + strategy: + matrix: + ruby: + - '3.3.0' + services: + mysql: + image: mysql:latest + env: + DATABASE_ADAPTER: mysql2 + DATABASE_PORT: 3306 + MYSQL_ROOT_PASSWORD: outboxer_password + MYSQL_DATABASE: outboxer_test + MYSQL_USER: outboxer_developer + MYSQL_PASSWORD: outboxer_password + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping --silent" + --health-interval=10s + --health-timeout=5s + --health-retries=5 + steps: + - uses: actions/checkout@v3 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Check MySQL + run: | + sudo apt-get -qq install -y mysql-client + export MYSQL_PWD=outboxer_password + mysql -h 127.0.0.1 -P 3306 -u outboxer_developer -poutboxer_password outboxer_test -e 'SELECT VERSION();' + - name: Run Database Migrations + env: + RAILS_ENV: test + DATABASE_ADAPTER: mysql2 + DATABASE_HOST: 127.0.0.1 + DATABASE_PORT: 3306 + run: | + bin/rake outboxer:db:migrate + - name: Run Tests + env: + RAILS_ENV: test + DATABASE_ADAPTER: mysql2 + DATABASE_PORT: 3306 + DATABASE_HOST: 127.0.0.1 + run: bin/rspec spec diff --git a/Gemfile b/Gemfile index 052f995c..d1168d1b 100644 --- a/Gemfile +++ b/Gemfile @@ -10,6 +10,7 @@ gem "rubocop", "~> 1.55" gem "yard", "~> 0.9.34" gem "pg", "~> 1.5" +gem 'mysql2', '~> 0.5.6' gem "activerecord", "~> 7.1", ">= 7.1.2" gem "sidekiq", "~> 7.2" diff --git a/Gemfile.lock b/Gemfile.lock index f9a03fc4..0ea36c40 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -75,6 +75,7 @@ GEM method_source (1.0.0) minitest (5.20.0) mutex_m (0.2.0) + mysql2 (0.5.6) nokogiri (1.16.2-arm64-darwin) racc (~> 1.4) nokogiri (1.16.2-x86_64-darwin) @@ -85,7 +86,7 @@ GEM parser (3.2.2.3) ast (~> 2.4.1) racc - pg (1.5.3) + pg (1.5.6) pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) @@ -162,6 +163,7 @@ DEPENDENCIES database_cleaner (~> 2.0, >= 2.0.2) factory_bot (~> 6.4, >= 6.4.6) foreman (~> 0.87.2) + mysql2 (~> 0.5.6) outboxer! pg (~> 1.5) pry-byebug (~> 3.10) diff --git a/config/database.yml b/config/database.yml index 345bd188..6a8c6a97 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,19 +1,19 @@ development: - adapter: postgresql - encoding: unicode - host: localhost - port: 5432 + adapter: <%= ENV.fetch('DATABASE_ADAPTER') { 'postgresql' } %> + encoding: utf8 + host: <%= ENV.fetch('DATABASE_HOST') { 'localhost' } %> + port: <%= ENV.fetch('DATABASE_PORT') { 5432 } %> username: outboxer_developer password: outboxer_password database: outboxer_development - pool: <%= ENV.fetch('RAILS_MAX_THREADS') { 26 } %> + pool: <%= ENV.fetch('DATABASE_POOL') { 5 } %> test: - adapter: postgresql - encoding: unicode - host: localhost - port: 5432 + adapter: <%= ENV.fetch('DATABASE_ADAPTER') { 'postgresql' } %> + encoding: utf8 + host: <%= ENV.fetch('DATABASE_HOST') { 'localhost' } %> + port: <%= ENV.fetch('DATABASE_PORT') { 5432 } %> username: outboxer_developer password: outboxer_password database: outboxer_test - pool: <%= ENV.fetch('RAILS_MAX_THREADS') { 26 } %> + pool: <%= ENV.fetch('DATABASE_POOL') { 5 } %> diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 57ff2444..f697f712 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -31,7 +31,9 @@ DatabaseCleaner.clean ActiveRecord::Base.connection.tables.each do |table| - ActiveRecord::Base.connection.reset_pk_sequence!(table) + if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' + ActiveRecord::Base.connection.reset_pk_sequence!(table) + end end rescue ActiveRecord::DatabaseConnectionError, ActiveRecord::ConnectionNotEstablished,