zero_downtime_migrations 0.0.3 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7c11ffb1f189aa72d6e3f293ed8b002a237fd0a
4
- data.tar.gz: 9c21a8f52fa53bcc6e37968e98934f1eed21cae5
3
+ metadata.gz: c54176ffa5402b379ae752cfb6a16a47213f31f6
4
+ data.tar.gz: 61c5e351d8d8540725c9c296df00cdc4ff70efb9
5
5
  SHA512:
6
- metadata.gz: a0f57e9b8d06259aaec58f60145ec790188b847e3c78e824b65be954e16a9da44f053d439718cf8edda9e1c55d375258435d72ffa5b0054404f7c50389fa7ae2
7
- data.tar.gz: acddd8d588ffdb007be328a1b932a96583b6762be95859cfd7860afd4d7db3191c561989676360db8ed3641ee8ce64ff9249a7874c4c7782e216e4fb31cef76b
6
+ metadata.gz: a79a860e93a831230f19886aefd0cc53e965175f18ce2e2701b60c19fe716e0f2837531cb8015dd180c75ab139feab0f71555f2e2893578afd0c8566b781a553
7
+ data.tar.gz: fe960c837d456b92dafa3236bd0051d910bf0e5b2b66527aa0c1ab5dcc6d8bae14ea655d30c12f1f3efa4a2af441934474334c823cdeedf32e9ca861ccaa4790
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zero_downtime_migrations (0.0.3)
4
+ zero_downtime_migrations (0.0.4)
5
5
  activerecord
6
6
 
7
7
  GEM
@@ -1,6 +1,6 @@
1
1
  module ZeroDowntimeMigrations
2
2
  module DSL
3
- attr_accessor :data, :ddl, :index, :migrating, :safe
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
- !!@migrating
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.migrating = true
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.migrating = false
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, self, *args)
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 YourMigration < ActiveRecord::Migration
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, migration = nil, *args)
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(migration, *args).validate!
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
- raise UnsafeMigrationError.new(message)
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.3"
14
+ s.version = "0.0.4"
15
15
 
16
16
  s.add_dependency "activerecord"
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zero_downtime_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - LendingHome