diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 8219711..71b552c 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -7,15 +7,15 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - name: Set up Ruby 2.7.2 + - uses: actions/checkout@v2 + - name: Set up Ruby 3.0.2 uses: actions/setup-ruby@v1 with: - ruby-version: 2.7.2 + ruby-version: 3.0.2 - name: Build run: | sudo apt-get install libsqlite3-dev - gem install bundler:2.2.15 + gem install bundler:2.2.30 bundle install --jobs 4 --retry 3 - name: Run tests run: bundle exec rspec diff --git a/.rubocop.yml b/.rubocop.yml index d68eb36..1ababa7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,7 +4,7 @@ inherit_gem: rubocop-shopify: rubocop.yml AllCops: - TargetRubyVersion: 2.7.2 + TargetRubyVersion: 3.0.2 # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop # to ignore them, so only the ones explicitly set in this file are enabled. DisabledByDefault: true diff --git a/.tool-versions b/.tool-versions index 9eb38ed..a2e7782 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -ruby 2.7.2 +ruby 3.0.2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 31f7901..93c170a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v2.0.3 + +- new config option: `disable_async_migrations` to disable async migrations + ## v2.0.2 - `slack_git_url_mapping_for_envs` has become `slack_git_url`, and now accepts only a single URL diff --git a/Gemfile.lock b/Gemfile.lock index 2f811ba..ac0f452 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - rails_async_migrations (2.0.0) + rails_async_migrations (2.0.3) GEM remote: https://rubygems.org/ @@ -67,7 +67,6 @@ GEM zeitwerk (~> 2.3) ast (2.4.2) builder (3.2.4) - coderay (1.1.3) concurrent-ruby (1.1.8) connection_pool (2.2.3) crass (1.0.6) @@ -77,6 +76,9 @@ GEM activerecord (>= 5.a) database_cleaner-core (~> 2.0.0) database_cleaner-core (2.0.1) + debug (1.3.4) + irb (>= 1.3.6) + reline (>= 0.2.7) delayed_job (4.1.9) activesupport (>= 3.0, < 6.2) delayed_job_active_record (4.1.6) @@ -91,6 +93,9 @@ GEM activesupport (>= 4.2.0) i18n (1.8.10) concurrent-ruby (~> 1.0) + io-console (0.5.9) + irb (1.3.7) + reline (>= 0.2.7) loofah (2.9.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -106,9 +111,6 @@ GEM parallel (1.20.1) parser (3.0.0.0) ast (~> 2.4.1) - pry (0.14.0) - coderay (~> 1.1) - method_source (~> 1.0) racc (1.5.2) rack (2.2.3) rack-test (1.1.0) @@ -143,6 +145,8 @@ GEM rake (13.0.3) redis (4.2.5) regexp_parser (2.1.1) + reline (0.2.7) + io-console (~> 0.5) rexml (3.2.4) rspec (3.10.0) rspec-core (~> 3.10.0) @@ -174,8 +178,8 @@ GEM rubocop-shopify (2.0.1) rubocop (~> 1.11) ruby-progressbar (1.11.0) - shoulda-matchers (4.5.1) - activesupport (>= 4.2.0) + shoulda-matchers (5.0.0) + activesupport (>= 5.2.0) sidekiq (6.2.0) connection_pool (>= 2.2.2) rack (~> 2.0) @@ -204,19 +208,19 @@ PLATFORMS DEPENDENCIES activerecord (~> 6.1) database_cleaner (~> 2.0) + debug (~> 1.3) delayed_job_active_record (~> 4.1) - fantaskspec (~> 1) - pry (~> 0.14) - rails (~> 6.1) + fantaskspec (~> 1.2) + rails (~> 6.1, < 7.0.0) rails_async_migrations! rake (~> 13) rspec (~> 3.10) rspec-sidekiq (~> 3.1) rubocop-shopify - shoulda-matchers (~> 4) + shoulda-matchers (~> 5) sidekiq (~> 6.2) slack-notifier (~> 2.3) sqlite3 (~> 1.4.2) BUNDLED WITH - 2.2.15 + 2.2.30 diff --git a/README.md b/README.md index 9d5a29b..8d6124f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # RailsAsyncMigrations -`ActiveRecord::Migration` extension to turn your migrations asynschonous in a simple and straight forward way. +`ActiveRecord::Migration` extension to turn your migrations asynchronous in a simple and straight forward way. ## Motives @@ -61,7 +61,7 @@ After the gem has been installed, use the generator to add the needed changes This will add a new migration for the table `async_schema_migrations` which will be used by the gem. You can also add the migration yourself like so: -``` +```ruby class CreateAsyncSchemaMigrations < ActiveRecord::Migration[6.0] def change create_table :async_schema_migrations do |t| @@ -79,7 +79,7 @@ end To turn some of your migrations asynchronous, generate a migration as you would normally do and use the `turn_async` keyword. -``` +```ruby class Test < ActiveRecord::Migration[6.0] turn_async @@ -101,7 +101,7 @@ What is turned asynchronous is executed exactly the same way as a classical migr Add the following lines into your `config/initializer/` folder -``` +```ruby RailsAsyncMigrations.config do |config| # :verbose can be used if you want a full log of the execution config.mode = :quiet @@ -109,6 +109,9 @@ RailsAsyncMigrations.config do |config| # which adapter worker you want to use for this library # for now you have two options: :delayed_job or :sidekiq config.workers = :sidekiq + + ## You can disable the gem using the following configuration option: + # config.disable_async_migrations = true end ``` @@ -125,7 +128,7 @@ You can also manually launch the queue check and fire by using: $ rake rails_async_migrations:check_queue -**For now, there is no rollback mechanism authorized. It means if you rollback the asynchronous migrations will be simply ignored. Handling multiple directions complexifies the build up logic and may not be needed in asynchronous cases.** +**For now, there is no rollback mechanism authorized. It means if you rollback the asynchronous migrations will be simply ignored. Handling multiple directions renders the build up logic more complex and may not be needed in asynchronous cases.** ## States @@ -180,6 +183,11 @@ rspec [Laurent Schaffner](http://www.laurentschaffner.com) +## Contributors + +[@SeanLF](https://github.com/SeanLF) +[@nept](https://github.com/nept) + ## Credits This project and its idea was inspired by [Kir Shatrov article](https://kirshatrov.com/2018/04/01/async-migrations/) on the matter, it's worth a look! diff --git a/bin/console b/bin/console index eb55a7d..96ac490 100755 --- a/bin/console +++ b/bin/console @@ -2,6 +2,7 @@ require "bundler/setup" require "rails_async_migrations" +require "debug" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. diff --git a/docker-compose.yml b/docker-compose.yml index bda7581..26090d7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,8 +6,8 @@ services: context: . dockerfile: Dockerfile args: - RUBY_VERSION: "2.7.2" - BUNDLER_VERSION: "2.2.15" + RUBY_VERSION: "3.0.2" + BUNDLER_VERSION: "2.2.30" image: rails-async-migrations tmpfs: - /tmp diff --git a/lib/rails_async_migrations/class_mutators.rb b/lib/rails_async_migrations/class_mutators.rb index f15f20a..a97d43b 100644 --- a/lib/rails_async_migrations/class_mutators.rb +++ b/lib/rails_async_migrations/class_mutators.rb @@ -9,6 +9,8 @@ module RailsAsyncMigrations module ClassMutators def turn_async + return if RailsAsyncMigrations.config.disable_async_migrations + Mutators::TurnAsync.new(self).perform end end diff --git a/lib/rails_async_migrations/config.rb b/lib/rails_async_migrations/config.rb index b7cd374..c3e64c2 100644 --- a/lib/rails_async_migrations/config.rb +++ b/lib/rails_async_migrations/config.rb @@ -3,13 +3,14 @@ # default values set here module RailsAsyncMigrations class Config - attr_accessor :taken_methods, :mode, :workers, :queue, :slack_webhook_url, :slack_title_message, :slack_git_url + attr_accessor :taken_methods, :mode, :workers, :queue, :slack_webhook_url, :slack_title_message, :slack_git_url, :disable_async_migrations def initialize @taken_methods = %i[change up down] @mode = :quiet # :verbose, :quiet @workers = :sidekiq # :delayed_job @queue = :default + @disable_async_migrations = false end def slack_git_url=(value) diff --git a/lib/rails_async_migrations/version.rb b/lib/rails_async_migrations/version.rb index 8f02133..10dd3d2 100644 --- a/lib/rails_async_migrations/version.rb +++ b/lib/rails_async_migrations/version.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true module RailsAsyncMigrations - VERSION = "2.0.2" + VERSION = "2.0.3" end diff --git a/rails_async_migrations.gemspec b/rails_async_migrations.gemspec index 1242cbf..29d84b0 100644 --- a/rails_async_migrations.gemspec +++ b/rails_async_migrations.gemspec @@ -19,14 +19,14 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.add_development_dependency 'pry', '~> 0.14' + spec.add_development_dependency 'debug', '~> 1.3' spec.add_development_dependency 'rubocop-shopify' - spec.add_development_dependency 'rails', '~> 6.1' + spec.add_development_dependency 'rails', '~> 6.1', "< 7.0.0" spec.add_development_dependency 'rake', '~> 13' spec.add_development_dependency 'sqlite3', '~> 1.4.2' spec.add_development_dependency 'rspec', '~> 3.10' spec.add_development_dependency 'database_cleaner', '~> 2.0' spec.add_development_dependency 'rspec-sidekiq', '~> 3.1' - spec.add_development_dependency 'shoulda-matchers', '~> 4' - spec.add_development_dependency 'fantaskspec', '~> 1' + spec.add_development_dependency 'shoulda-matchers', '~> 5' + spec.add_development_dependency 'fantaskspec', '~> 1.2' end diff --git a/spec/rails_async_migrations/mutators/turn_async_spec.rb b/spec/rails_async_migrations/mutators/turn_async_spec.rb index ec86673..6d4d2f8 100644 --- a/spec/rails_async_migrations/mutators/turn_async_spec.rb +++ b/spec/rails_async_migrations/mutators/turn_async_spec.rb @@ -1,10 +1,13 @@ # frozen_string_literal: true RSpec.describe(RailsAsyncMigrations::Mutators::TurnAsync) do - let(:instance) { described_class.new(migration_class) } - let(:migration_class) { FakeMigration } + + describe '#perform' do + let(:instance) { described_class.new(migration_class) } + let(:migration_class) { FakeMigration } - context '#perform' do - subject { instance.perform } - it { is_expected.to(be_truthy) } + context "async migrations enabled" do + subject { instance.perform } + it { is_expected.to(be_truthy) } + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4c006ef..db5184e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true require 'bundler/setup' -require 'pry' +require 'debug' require 'rails_async_migrations' require 'logger' diff --git a/spec/support/utils_helpers.rb b/spec/support/utils_helpers.rb index c43c3b3..9d262e4 100644 --- a/spec/support/utils_helpers.rb +++ b/spec/support/utils_helpers.rb @@ -36,6 +36,12 @@ def fake_migration_proxy! FakeMigrationProxy.new )) end + + def disable_async_migrations! + RailsAsyncMigrations.config do |config| + config.disable_async_migrations = true + end + end end class FakeMigrationProxy