zero_downtime_migrations 0.0.2 → 0.0.3

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: c98c1cbcf271026706fc6d40043d1fcba981ef04
4
- data.tar.gz: aa219a884d42a7024256b9763f08decbfb6950d4
3
+ metadata.gz: b7c11ffb1f189aa72d6e3f293ed8b002a237fd0a
4
+ data.tar.gz: 9c21a8f52fa53bcc6e37968e98934f1eed21cae5
5
5
  SHA512:
6
- metadata.gz: 862eaac1afae554f4727fad033c8f1ac023973c3dc2d849535eb715fb2a18ec87c770aca6a591d604417d18fd23c9116f8c02684cf1914ee5d28d3df30950bd0
7
- data.tar.gz: 30bbf4dd92155ae61b48721d8088f9cee339ba502634b775f6169cc5e4b7405d3109261da0d93bd127b1cb5fb72d77628e85e51b7db5a3be6b5e7debb389705b
6
+ metadata.gz: a0f57e9b8d06259aaec58f60145ec790188b847e3c78e824b65be954e16a9da44f053d439718cf8edda9e1c55d375258435d72ffa5b0054404f7c50389fa7ae2
7
+ data.tar.gz: acddd8d588ffdb007be328a1b932a96583b6762be95859cfd7860afd4d7db3191c561989676360db8ed3641ee8ce64ff9249a7874c4c7782e216e4fb31cef76b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zero_downtime_migrations (0.0.2)
4
+ zero_downtime_migrations (0.0.3)
5
5
  activerecord
6
6
 
7
7
  GEM
@@ -6,9 +6,5 @@ module ZeroDowntimeMigrations
6
6
  end
7
7
 
8
8
  class UnsafeMigrationError < Error
9
- def initialize(error, correction)
10
- error_with_type = "#{self.class.name}: #{error}"
11
- super("#{error_with_type}\n\n#{correction}")
12
- end
13
9
  end
14
10
  end
@@ -2,11 +2,11 @@ module ZeroDowntimeMigrations
2
2
  class Validation
3
3
  def self.validate!(type, migration = nil, *args)
4
4
  return unless Migration.migrating? && Migration.unsafe?
5
- validator = type.to_s.classify
6
5
 
7
- if const_defined?(validator)
6
+ begin
7
+ validator = type.to_s.classify
8
8
  const_get(validator).new(migration, *args).validate!
9
- else
9
+ rescue NameError
10
10
  raise UndefinedValidationError.new(validator)
11
11
  end
12
12
  end
@@ -18,8 +18,8 @@ module ZeroDowntimeMigrations
18
18
  @args = args
19
19
  end
20
20
 
21
- def error!(*args)
22
- raise UnsafeMigrationError.new(*args)
21
+ def error!(message)
22
+ raise UnsafeMigrationError.new(message)
23
23
  end
24
24
 
25
25
  def migration_name
@@ -3,14 +3,15 @@ module ZeroDowntimeMigrations
3
3
  class AddColumn < Validation
4
4
  def validate!
5
5
  return if options[:default].nil? # only nil is safe
6
- message = "Adding a column with a default is unsafe!"
7
- error!(message, correction)
6
+ error!(message)
8
7
  end
9
8
 
10
9
  private
11
10
 
12
- def correction
11
+ def message
13
12
  <<-MESSAGE.strip_heredoc
13
+ Adding a column with a default is unsafe!
14
+
14
15
  This action can potentially lock your database table!
15
16
 
16
17
  Instead, let's first add the column without a default.
@@ -3,14 +3,15 @@ module ZeroDowntimeMigrations
3
3
  class AddIndex < Validation
4
4
  def validate!
5
5
  return if concurrent? && migration.ddl_disabled?
6
- message = "Adding a non-concurrent index is unsafe!"
7
- error!(message, correction)
6
+ error!(message)
8
7
  end
9
8
 
10
9
  private
11
10
 
12
- def correction
11
+ def message
13
12
  <<-MESSAGE.strip_heredoc
13
+ Adding a non-concurrent index is unsafe!
14
+
14
15
  This action can potentially lock your database table!
15
16
 
16
17
  Instead, let's add the index concurrently in its own migration with
@@ -3,14 +3,15 @@ module ZeroDowntimeMigrations
3
3
  class DdlMigration < Validation
4
4
  def validate!
5
5
  return unless migration.ddl_disabled? && !Migration.index?
6
- message = "Disabling the DDL transaction is unsafe!"
7
- error!(message, correction)
6
+ error!(message)
8
7
  end
9
8
 
10
9
  private
11
10
 
12
- def correction
11
+ def message
13
12
  <<-MESSAGE.strip_heredoc
13
+ Disabling the DDL transaction is unsafe!
14
+
14
15
  The DDL transaction should only be disabled for migrations that add indexes.
15
16
 
16
17
  Any other data or schema changes must live in their own migration files with
@@ -2,14 +2,15 @@ module ZeroDowntimeMigrations
2
2
  class Validation
3
3
  class FindEach < Validation
4
4
  def validate!
5
- message = "Using `ActiveRecord::Relation#each` is unsafe!"
6
- error!(message, correction)
5
+ error!(message)
7
6
  end
8
7
 
9
8
  private
10
9
 
11
- def correction
10
+ def message
12
11
  <<-MESSAGE.strip_heredoc
12
+ Using `ActiveRecord::Relation#each` is unsafe!
13
+
13
14
  Let's use the `find_each` method to fetch records in batches instead.
14
15
 
15
16
  Otherwise we may accidentally load tens or hundreds of thousands of
@@ -3,14 +3,15 @@ module ZeroDowntimeMigrations
3
3
  class MixedMigration < Validation
4
4
  def validate!
5
5
  return unless Migration.mixed?
6
- message = "Mixing data/index/schema changes in the same migration is unsafe!"
7
- error!(message, correction)
6
+ error!(message)
8
7
  end
9
8
 
10
9
  private
11
10
 
12
- def correction
11
+ def message
13
12
  <<-MESSAGE.strip_heredoc
13
+ Mixing data/index/schema changes in the same migration is unsafe!
14
+
14
15
  Instead, let's split apart these types of migrations into separate files.
15
16
 
16
17
  * Introduce schema changes with methods like `create_table` or `add_column` in one file.
@@ -8,7 +8,7 @@ RSpec.describe ZeroDowntimeMigrations::Validation do
8
8
  let(:error) { ZeroDowntimeMigrations::UndefinedValidationError }
9
9
 
10
10
  it "raises UndefinedValidationError if one does not exist" do
11
- expect { described_class.validate!(:invalid) }.to raise_error(error)
11
+ expect { described_class.validate!(:invalid?) }.to raise_error(error)
12
12
  end
13
13
  end
14
14
 
@@ -18,12 +18,12 @@ RSpec.describe ZeroDowntimeMigrations::Validation do
18
18
  end
19
19
  end
20
20
 
21
- describe "#error" do
22
- let(:args) { [:one, :two] }
21
+ describe "#error!" do
23
22
  let(:error) { ZeroDowntimeMigrations::UnsafeMigrationError }
23
+ let(:message) { "test" }
24
24
 
25
25
  it "raises a new UnsafeMigrationError" do
26
- expect { subject.error!(*args) }.to raise_error(error)
26
+ expect { subject.error!(message) }.to raise_error(error)
27
27
  end
28
28
  end
29
29
 
@@ -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.2"
14
+ s.version = "0.0.3"
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - LendingHome