Skip to content

Commit

Permalink
Feature: allow disabling in config & bump to 2.0.3 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanLF authored Nov 8, 2021
1 parent c9aa783 commit 68a1436
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 37 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby 2.7.2
ruby 3.0.2
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
28 changes: 16 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
rails_async_migrations (2.0.0)
rails_async_migrations (2.0.3)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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|
Expand All @@ -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

Expand All @@ -101,14 +101,17 @@ 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

# 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
```

Expand All @@ -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

Expand Down Expand Up @@ -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!
Expand Down
1 change: 1 addition & 0 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/rails_async_migrations/class_mutators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/rails_async_migrations/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_async_migrations/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
module RailsAsyncMigrations
VERSION = "2.0.2"
VERSION = "2.0.3"
end
8 changes: 4 additions & 4 deletions rails_async_migrations.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 8 additions & 5 deletions spec/rails_async_migrations/mutators/turn_async_spec.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true
require 'bundler/setup'
require 'pry'
require 'debug'
require 'rails_async_migrations'

require 'logger'
Expand Down
6 changes: 6 additions & 0 deletions spec/support/utils_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 68a1436

Please sign in to comment.