zero_downtime_migrations 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/zero_downtime_migrations/dsl.rb +2 -2
- data/lib/zero_downtime_migrations/migration.rb +5 -5
- data/lib/zero_downtime_migrations/validation/find_each.rb +2 -2
- data/lib/zero_downtime_migrations/validation.rb +6 -3
- data/zero_downtime_migrations.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c54176ffa5402b379ae752cfb6a16a47213f31f6
|
4
|
+
data.tar.gz: 61c5e351d8d8540725c9c296df00cdc4ff70efb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a79a860e93a831230f19886aefd0cc53e965175f18ce2e2701b60c19fe716e0f2837531cb8015dd180c75ab139feab0f71555f2e2893578afd0c8566b781a553
|
7
|
+
data.tar.gz: fe960c837d456b92dafa3236bd0051d910bf0e5b2b66527aa0c1ab5dcc6d8bae14ea655d30c12f1f3efa4a2af441934474334c823cdeedf32e9ca861ccaa4790
|
data/Gemfile.lock
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module ZeroDowntimeMigrations
|
2
2
|
module DSL
|
3
|
-
attr_accessor :data, :ddl, :index, :
|
3
|
+
attr_accessor :current, :data, :ddl, :index, :safe
|
4
4
|
|
5
5
|
def data?
|
6
6
|
!!@data
|
@@ -15,7 +15,7 @@ module ZeroDowntimeMigrations
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def migrating?
|
18
|
-
!!@
|
18
|
+
!!@current
|
19
19
|
end
|
20
20
|
|
21
21
|
def mixed?
|
@@ -11,24 +11,24 @@ module ZeroDowntimeMigrations
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def define(*)
|
14
|
-
Migration.
|
14
|
+
Migration.current = self
|
15
15
|
Migration.safe = true
|
16
|
-
super
|
16
|
+
super.tap { Migration.current = nil }
|
17
17
|
end
|
18
18
|
|
19
19
|
def migrate(direction)
|
20
20
|
@direction = direction
|
21
21
|
|
22
|
+
Migration.current = self
|
22
23
|
Migration.data = false
|
23
24
|
Migration.ddl = false
|
24
25
|
Migration.index = false
|
25
|
-
Migration.migrating = true
|
26
26
|
Migration.safe ||= reverse_migration? || rollup_migration?
|
27
27
|
|
28
28
|
super.tap do
|
29
29
|
validate(:ddl_migration)
|
30
30
|
validate(:mixed_migration)
|
31
|
-
Migration.
|
31
|
+
Migration.current = nil
|
32
32
|
Migration.safe = false
|
33
33
|
end
|
34
34
|
end
|
@@ -94,7 +94,7 @@ module ZeroDowntimeMigrations
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def validate(type, *args)
|
97
|
-
Validation.validate!(type,
|
97
|
+
Validation.validate!(type, *args)
|
98
98
|
rescue UndefinedValidationError
|
99
99
|
nil
|
100
100
|
end
|
@@ -19,10 +19,10 @@ module ZeroDowntimeMigrations
|
|
19
19
|
If you're 100% positive that this migration is already safe, then wrap the
|
20
20
|
call to `each` in a `safety_assured` block.
|
21
21
|
|
22
|
-
class
|
22
|
+
class #{migration_name} < ActiveRecord::Migration
|
23
23
|
def change
|
24
24
|
safety_assured do
|
25
|
-
# use .each in this block
|
25
|
+
# use ActiveRecord::Relation.each in this block
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module ZeroDowntimeMigrations
|
2
2
|
class Validation
|
3
|
-
def self.validate!(type,
|
3
|
+
def self.validate!(type, *args)
|
4
4
|
return unless Migration.migrating? && Migration.unsafe?
|
5
5
|
|
6
6
|
begin
|
7
7
|
validator = type.to_s.classify
|
8
|
-
const_get(validator).new(
|
8
|
+
const_get(validator).new(Migration.current, *args).validate!
|
9
9
|
rescue NameError
|
10
10
|
raise UndefinedValidationError.new(validator)
|
11
11
|
end
|
@@ -19,7 +19,10 @@ module ZeroDowntimeMigrations
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def error!(message)
|
22
|
-
|
22
|
+
error = UnsafeMigrationError
|
23
|
+
debug = "#{error}: #{migration_name} is unsafe!"
|
24
|
+
message = [message, debug, nil].join("\n")
|
25
|
+
raise error.new(message)
|
23
26
|
end
|
24
27
|
|
25
28
|
def migration_name
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.required_ruby_version = ">= 2.0.0"
|
12
12
|
s.summary = "Zero downtime migrations with ActiveRecord and PostgreSQL"
|
13
13
|
s.test_files = `git ls-files -- spec/*`.split("\n")
|
14
|
-
s.version = "0.0.
|
14
|
+
s.version = "0.0.4"
|
15
15
|
|
16
16
|
s.add_dependency "activerecord"
|
17
17
|
end
|