rails_async_migrations 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +15 -15
- data/lib/rails_async_migrations/{mutators.rb → class_mutators.rb} +14 -12
- data/lib/rails_async_migrations/instance_mutators.rb +11 -0
- data/lib/rails_async_migrations/migration/fire_migration.rb +1 -1
- data/lib/rails_async_migrations/mutators/base.rb +3 -15
- data/lib/rails_async_migrations/mutators/turn_async.rb +3 -3
- data/lib/rails_async_migrations/version.rb +1 -1
- data/lib/rails_async_migrations.rb +4 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4253ed996632677655f41d68a099fa59f1140d8e6d45e5082ac67d5ae240fb52
|
4
|
+
data.tar.gz: 4a7fe84133fe9a0e9361c0d47cef3fc48045a6031bf0f3a0cfcfc99e648fc12f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76ae01899644674ef8f62a4718d263e261f0322d33617c85483dee36debfb5bdd209e58296080d77e8fef4c832994e0dc0cfa9990dc2ce7281cc87a827243dc0
|
7
|
+
data.tar.gz: 94efe3c86bca71bcfb78c4630fed9fffbcaaa5b6d4258d1a46e29052dec5bd5f4468f56d13689a03bbe286ff254e8a81f4351f4282d7642a3af49c31b0f58608
|
data/Gemfile.lock
CHANGED
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
|
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
|
-
#
|
17
|
-
#
|
18
|
-
#
|
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
|
-
|
21
|
-
|
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
|
@@ -1,21 +1,9 @@
|
|
1
1
|
module RailsAsyncMigrations
|
2
2
|
module Mutators
|
3
3
|
class Base
|
4
|
-
#
|
5
|
-
#
|
6
|
-
|
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 :
|
4
|
+
attr_reader :migration_class
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@
|
6
|
+
def initialize(migration_class)
|
7
|
+
@migration_class = migration_class
|
8
8
|
end
|
9
9
|
|
10
10
|
def perform
|
@@ -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/
|
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.
|
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.
|
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-
|
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
|