zero_downtime_migrations 0.0.2 → 0.0.3
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/error.rb +0 -4
- data/lib/zero_downtime_migrations/validation.rb +5 -5
- data/lib/zero_downtime_migrations/validation/add_column.rb +4 -3
- data/lib/zero_downtime_migrations/validation/add_index.rb +4 -3
- data/lib/zero_downtime_migrations/validation/ddl_migration.rb +4 -3
- data/lib/zero_downtime_migrations/validation/find_each.rb +4 -3
- data/lib/zero_downtime_migrations/validation/mixed_migration.rb +4 -3
- data/spec/zero_downtime_migrations/validation_spec.rb +4 -4
- 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: b7c11ffb1f189aa72d6e3f293ed8b002a237fd0a
|
4
|
+
data.tar.gz: 9c21a8f52fa53bcc6e37968e98934f1eed21cae5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0f57e9b8d06259aaec58f60145ec790188b847e3c78e824b65be954e16a9da44f053d439718cf8edda9e1c55d375258435d72ffa5b0054404f7c50389fa7ae2
|
7
|
+
data.tar.gz: acddd8d588ffdb007be328a1b932a96583b6762be95859cfd7860afd4d7db3191c561989676360db8ed3641ee8ce64ff9249a7874c4c7782e216e4fb31cef76b
|
data/Gemfile.lock
CHANGED
@@ -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
|
-
|
6
|
+
begin
|
7
|
+
validator = type.to_s.classify
|
8
8
|
const_get(validator).new(migration, *args).validate!
|
9
|
-
|
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!(
|
22
|
-
raise UnsafeMigrationError.new(
|
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
|
7
|
-
error!(message, correction)
|
6
|
+
error!(message)
|
8
7
|
end
|
9
8
|
|
10
9
|
private
|
11
10
|
|
12
|
-
def
|
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
|
7
|
-
error!(message, correction)
|
6
|
+
error!(message)
|
8
7
|
end
|
9
8
|
|
10
9
|
private
|
11
10
|
|
12
|
-
def
|
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
|
7
|
-
error!(message, correction)
|
6
|
+
error!(message)
|
8
7
|
end
|
9
8
|
|
10
9
|
private
|
11
10
|
|
12
|
-
def
|
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
|
6
|
-
error!(message, correction)
|
5
|
+
error!(message)
|
7
6
|
end
|
8
7
|
|
9
8
|
private
|
10
9
|
|
11
|
-
def
|
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
|
7
|
-
error!(message, correction)
|
6
|
+
error!(message)
|
8
7
|
end
|
9
8
|
|
10
9
|
private
|
11
10
|
|
12
|
-
def
|
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!(
|
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.
|
14
|
+
s.version = "0.0.3"
|
15
15
|
|
16
16
|
s.add_dependency "activerecord"
|
17
17
|
end
|