strong_migrations 2.7.0 → 2.8.0
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/CHANGELOG.md +4 -0
- data/README.md +33 -0
- data/lib/strong_migrations/checker.rb +2 -0
- data/lib/strong_migrations/checks.rb +8 -0
- data/lib/strong_migrations/error_messages.rb +14 -0
- data/lib/strong_migrations/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 506dc7670dbae5a7f4bb621d39da43e67098b9629cc76a854d2677d006f0919a
|
|
4
|
+
data.tar.gz: 3cfd8d8f74a1575b23485ca16ef26f04de5f52b8c059fcded94d1a42410afc41
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0b55091991fdba05bbc088a3b8967a66473e150ccce62f2065d671fa1b61f2dc70b0cd149f5a9645135b9fdcc9e10f344b7ea548e391ab9bcca371bdff35443c
|
|
7
|
+
data.tar.gz: '09a1b778c608aa600a3e84ca99da6fb8ad5771cec839092b2f77e0788e6dc6a0940442665de94ec5ea07487fcdb7b665bc41a258c44266f79f322616336986e9'
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -80,6 +80,7 @@ Postgres-specific checks:
|
|
|
80
80
|
- [adding a json column](#adding-a-json-column)
|
|
81
81
|
- [adding a column with a volatile default value](#adding-a-column-with-a-volatile-default-value)
|
|
82
82
|
- [setting NOT NULL on an existing column](#setting-not-null-on-an-existing-column)
|
|
83
|
+
- [renaming an enum value](#renaming-an-enum-value)
|
|
83
84
|
- [renaming a schema](#renaming-a-schema)
|
|
84
85
|
|
|
85
86
|
MySQL and MariaDB-specific checks:
|
|
@@ -686,6 +687,38 @@ class ValidateSomeColumnNotNull < ActiveRecord::Migration[8.1]
|
|
|
686
687
|
end
|
|
687
688
|
```
|
|
688
689
|
|
|
690
|
+
### Renaming an enum value
|
|
691
|
+
|
|
692
|
+
#### Bad
|
|
693
|
+
|
|
694
|
+
Renaming an enum value that’s in use will cause errors in your application.
|
|
695
|
+
|
|
696
|
+
```ruby
|
|
697
|
+
class RenameDoneToCompleted < ActiveRecord::Migration[8.1]
|
|
698
|
+
def change
|
|
699
|
+
rename_enum_value :status, from: "done", to: "completed"
|
|
700
|
+
end
|
|
701
|
+
end
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
#### Good
|
|
705
|
+
|
|
706
|
+
A safer approach is to:
|
|
707
|
+
|
|
708
|
+
1. Add a new enum value before or after the old value
|
|
709
|
+
2. Update application code to handle both values and write the new value
|
|
710
|
+
3. Backfill data from the old value to the new value
|
|
711
|
+
|
|
712
|
+
```ruby
|
|
713
|
+
class AddCompletedToStatus < ActiveRecord::Migration[8.1]
|
|
714
|
+
def up
|
|
715
|
+
add_enum_value :status, "completed", after: "done"
|
|
716
|
+
end
|
|
717
|
+
end
|
|
718
|
+
```
|
|
719
|
+
|
|
720
|
+
Removing enum values is not supported in Postgres (without creating a new enum).
|
|
721
|
+
|
|
689
722
|
### Renaming a schema
|
|
690
723
|
|
|
691
724
|
#### Bad
|
|
@@ -467,6 +467,14 @@ module StrongMigrations
|
|
|
467
467
|
raise_error :rename_column
|
|
468
468
|
end
|
|
469
469
|
|
|
470
|
+
def check_rename_enum_value(*args)
|
|
471
|
+
options = args.extract_options!
|
|
472
|
+
type_name, _ = args
|
|
473
|
+
|
|
474
|
+
raise_error :rename_enum_value,
|
|
475
|
+
command: command_str("add_enum_value", [type_name, options[:to], {after: options[:from]}])
|
|
476
|
+
end
|
|
477
|
+
|
|
470
478
|
def check_rename_schema
|
|
471
479
|
raise_error :rename_schema
|
|
472
480
|
end
|
|
@@ -117,6 +117,20 @@ in your application. A safer approach is to:
|
|
|
117
117
|
5. Stop writing to the old column
|
|
118
118
|
6. Drop the old column",
|
|
119
119
|
|
|
120
|
+
rename_enum_value:
|
|
121
|
+
"Renaming an enum value that's in use will cause errors
|
|
122
|
+
in your application. A safer approach is to:
|
|
123
|
+
|
|
124
|
+
1. Add a new enum value before or after the old value
|
|
125
|
+
2. Update application code to handle both values and write the new value
|
|
126
|
+
3. Backfill data from the old value to the new value
|
|
127
|
+
|
|
128
|
+
class %{migration_name} < ActiveRecord::Migration%{migration_suffix}
|
|
129
|
+
def up
|
|
130
|
+
%{command}
|
|
131
|
+
end
|
|
132
|
+
end",
|
|
133
|
+
|
|
120
134
|
rename_schema:
|
|
121
135
|
"Renaming a schema that's in use will cause errors
|
|
122
136
|
in your application. A safer approach is to:
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: strong_migrations
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrew Kane
|
|
@@ -72,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
72
72
|
- !ruby/object:Gem::Version
|
|
73
73
|
version: '0'
|
|
74
74
|
requirements: []
|
|
75
|
-
rubygems_version: 4.0.
|
|
75
|
+
rubygems_version: 4.0.10
|
|
76
76
|
specification_version: 4
|
|
77
77
|
summary: Catch unsafe migrations in development
|
|
78
78
|
test_files: []
|