rails_async_migrations 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3950f1a87294b305b11d6b4f72fe89140ac5ca037b0d63634b93883efac2226
4
- data.tar.gz: bc23163e9ec84a71472a786388372461d3437316c56286d03c8f231462fd9770
3
+ metadata.gz: 4253ed996632677655f41d68a099fa59f1140d8e6d45e5082ac67d5ae240fb52
4
+ data.tar.gz: 4a7fe84133fe9a0e9361c0d47cef3fc48045a6031bf0f3a0cfcfc99e648fc12f
5
5
  SHA512:
6
- metadata.gz: f197bd6a02bca2bc548c5a68a8ac29145461d97dc88217e399aa1183c329a476d4658f610460106261ef2e3b89f792f25de1a084d259079c64288443edc626d5
7
- data.tar.gz: fc3b0b75a80a3840c8bd9f2b488f5cebd4cc30ed2d011d65a6e88571cc4ce05949f4e97b5f2058519bbc0879d6169669d1f362150a9c5b55f32e0bb2026ce184
6
+ metadata.gz: 76ae01899644674ef8f62a4718d263e261f0322d33617c85483dee36debfb5bdd209e58296080d77e8fef4c832994e0dc0cfa9990dc2ce7281cc87a827243dc0
7
+ data.tar.gz: 94efe3c86bca71bcfb78c4630fed9fffbcaaa5b6d4258d1a46e29052dec5bd5f4468f56d13689a03bbe286ff254e8a81f4351f4282d7642a3af49c31b0f58608
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_async_migrations (1.0.3)
4
+ rails_async_migrations (1.0.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -15,6 +15,19 @@ Most people turn heavy data changes into `rake tasks` or split workers; there ar
15
15
 
16
16
  Turning data changes into a `rake task` can be a good idea, and it's ideal to test it out too, but sometimes you need this **fat ass loop** of **>1,000,000 records** which will be run **once, and only once** to be run fast and without locking down the deployment process itself; making a `rake task` for that is overkill. After all, it will only be used once and within a specific structure / data context. This gem is here to answer this need.
17
17
 
18
+ ## Requirements
19
+
20
+ You can use this library through different background processing technologies
21
+
22
+ | Type | Version | Documentation | Default |
23
+ | ---------------- | ------- | --------------------------------------------- | ------- |
24
+ | **Sidekiq** | 5.2.3 | https://github.com/mperham/sidekiq | YES |
25
+ | **Delayed::Job** | 4.1.3 | https://github.com/collectiveidea/delayed_job | NO |
26
+
27
+ Please install and configure one of those before to use this gem. If you use other libraries to setup your workers, please hit me up and I'll create additional adapters for you.
28
+
29
+ This gem has been tested and is working with `ActiveRecord 5.2.2`, if you notice abnormal behavior with other versions or want it compatible with earlier versions, please hit me up.
30
+
18
31
  ## Installation
19
32
 
20
33
  Add this line to your application's Gemfile:
@@ -119,24 +132,11 @@ You can also manually launch the queue check and fire by using:
119
132
  If your migration crashes, and blocks the rest of your queue but you want to execute them anyway, you can use multiple strategies to do so:
120
133
 
121
134
  - Change the code of the migration file and push it again so it passes
122
- - Remove the matching row in the `async_schema_migrations` table
123
- - Update the matching row with `state = done`
135
+ - Remove the matching row in the `async_schema_migrations` table. In this case, if you `rollback` your migration and run them again, it'll be newly added to the rows
136
+ - Update the matching row with `async_schema_migrations.state = done`. It'll be considered processed and won't ever be tried again.
124
137
 
125
138
  To find the matching migration, be aware the `version` value is always the same as the classic migrations ones, so it's pretty easy to find things around.
126
139
 
127
- ## Compatibility
128
-
129
- You can use this library through different adapters
130
-
131
- | Type | Version | Documentation |
132
- | ---------------- | ------- | --------------------------------------------- |
133
- | **Sidekiq** | 5.2.3 | https://github.com/mperham/sidekiq |
134
- | **Delayed::Job** | 4.1.3 | https://github.com/collectiveidea/delayed_job |
135
-
136
- If you use other technologies to setup your workers, please hit me up and I'll create additional adapters for you.
137
-
138
- The gem has been tested and is working with `ActiveRecord 5.2.2`, if you notice abnormal behavior with other versions or want it compatible with earlier versions, please hit me up.
139
-
140
140
  ## Development
141
141
 
142
142
  I created this library as my company was struggling in its deployment process. It lacks functionalities but this is a good starting point; everything is easily extendable so don't hesitate to add your own needed methods to it.
@@ -6,19 +6,21 @@ require 'rails_async_migrations/mutators/trigger_callback'
6
6
  # the `self` represents the class being ran so we have to be careful as not to conflict
7
7
  # with the original ActiveRecord names
8
8
  module RailsAsyncMigrations
9
- module Mutators
10
- private
11
-
9
+ module ClassMutators
12
10
  def turn_async
13
- TurnAsync.new(self).perform
11
+ Mutators::TurnAsync.new(self).perform
14
12
  end
13
+ end
14
+ end
15
15
 
16
- # # the following methods are internal mechanics
17
- # # do not overwrite those methods if you don't know
18
- # # exactly what you're doing
16
+ # def self.descendants
17
+ # ObjectSpace.each_object(Class).select do
18
+ # |current| current < self
19
+ # end
20
+ # end
21
+ # descendants = self.class.descendants
22
+ # descendants.delete_at descendants.index(ActiveRecord::Migration::Current)
23
+ # real_self = descendants.last
19
24
 
20
- def trigger_callback(method)
21
- TriggerCallback.new(self, method).perform
22
- end
23
- end
24
- end
25
+ # puts "REAL SELF IS #{real_self}"
26
+ #
@@ -0,0 +1,11 @@
1
+ require 'rails_async_migrations/mutators/base'
2
+ require 'rails_async_migrations/mutators/turn_async'
3
+ require 'rails_async_migrations/mutators/trigger_callback'
4
+
5
+ module RailsAsyncMigrations
6
+ module InstanceMutators
7
+ def trigger_callback(method)
8
+ Mutators::TriggerCallback.new(self, method).perform
9
+ end
10
+ end
11
+ end
@@ -34,7 +34,7 @@ module RailsAsyncMigrations
34
34
  def done?
35
35
  if migration.state == 'done'
36
36
  Tracer.new.verbose "Migration #{migration.id} is already `done`, cancelling fire"
37
- return
37
+ return true
38
38
  end
39
39
  end
40
40
 
@@ -1,21 +1,9 @@
1
1
  module RailsAsyncMigrations
2
2
  module Mutators
3
3
  class Base
4
- # in some context we have to guess it from the file and current connection
5
- # for instance when we use class methods such as `turn_async`
6
- def migration_class
7
- fetch_from_file || instance.class
8
- end
9
-
10
- def fetch_from_file
11
- return unless current_migration
12
- require current_migration.filename
13
- current_migration.name.constantize
14
- end
15
-
16
- def current_migration
17
- @current_migration ||= Connection::ActiveRecord.new(:up).current_migration
18
- end
4
+ # def migration_class
5
+ # instance.class
6
+ # end
19
7
  end
20
8
  end
21
9
  end
@@ -1,10 +1,10 @@
1
1
  module RailsAsyncMigrations
2
2
  module Mutators
3
3
  class TurnAsync < Base
4
- attr_reader :instance
4
+ attr_reader :migration_class
5
5
 
6
- def initialize(instance)
7
- @instance = instance
6
+ def initialize(migration_class)
7
+ @migration_class = migration_class
8
8
  end
9
9
 
10
10
  def perform
@@ -1,3 +1,3 @@
1
1
  module RailsAsyncMigrations
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -11,7 +11,8 @@ end
11
11
  require 'rails_async_migrations/connection/active_record'
12
12
  require 'rails_async_migrations/config'
13
13
  require 'rails_async_migrations/migration'
14
- require 'rails_async_migrations/mutators'
14
+ require 'rails_async_migrations/class_mutators'
15
+ require 'rails_async_migrations/instance_mutators'
15
16
  require 'rails_async_migrations/tracer'
16
17
  require 'rails_async_migrations/version'
17
18
  require 'rails_async_migrations/railtie' if defined?(Rails)
@@ -38,5 +39,6 @@ module RailsAsyncMigrations
38
39
  end
39
40
 
40
41
  ActiveSupport.on_load(:active_record) do
41
- ActiveRecord::Migration.prepend RailsAsyncMigrations::Mutators
42
+ ActiveRecord::Migration.extend RailsAsyncMigrations::ClassMutators
43
+ ActiveRecord::Migration.include RailsAsyncMigrations::InstanceMutators
42
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_async_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laurent Schaffner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-03 00:00:00.000000000 Z
11
+ date: 2019-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -143,8 +143,10 @@ files:
143
143
  - lib/generators/rails_async_migrations/install_generator.rb
144
144
  - lib/generators/rails_async_migrations/templates/create_async_schema_migrations.rb
145
145
  - lib/rails_async_migrations.rb
146
+ - lib/rails_async_migrations/class_mutators.rb
146
147
  - lib/rails_async_migrations/config.rb
147
148
  - lib/rails_async_migrations/connection/active_record.rb
149
+ - lib/rails_async_migrations/instance_mutators.rb
148
150
  - lib/rails_async_migrations/migration.rb
149
151
  - lib/rails_async_migrations/migration/check_queue.rb
150
152
  - lib/rails_async_migrations/migration/fire_migration.rb
@@ -154,7 +156,6 @@ files:
154
156
  - lib/rails_async_migrations/migration/run.rb
155
157
  - lib/rails_async_migrations/migration/unlock.rb
156
158
  - lib/rails_async_migrations/models/async_schema_migration.rb
157
- - lib/rails_async_migrations/mutators.rb
158
159
  - lib/rails_async_migrations/mutators/base.rb
159
160
  - lib/rails_async_migrations/mutators/trigger_callback.rb
160
161
  - lib/rails_async_migrations/mutators/turn_async.rb