strong_migrations 2.4.0 → 2.5.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 +5 -0
- data/README.md +26 -0
- data/lib/strong_migrations/checker.rb +15 -1
- data/lib/strong_migrations/checks.rb +4 -0
- data/lib/strong_migrations/error_messages.rb +11 -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: 971d5d1eabb91dc04c72cc99a24f8b92f1b0d31d8d28369577f48c283b8d8624
|
4
|
+
data.tar.gz: '08a413578f564ada7f9768aeaf469719ca051e4c37057be6324e593c73fb3144'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8ca27268e166609ec8253ce686c6fe9cbe6d7c4b298f8c80ce7f1690e76a2c997fad2806cce52c9765f6ee92e7e389fdf6c830d3ca8ebb0241574adc02c4b57
|
7
|
+
data.tar.gz: 18731d2b1bdd12698d6b860a470249a24ea12aaa0b5b74b6510d41527ef2126c46b27ef4aa7c7adb1437bd7a006d0bb7c46490d24ec15720009723e5b0d8eca4
|
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
|
- [setting NOT NULL on an existing column](#setting-not-null-on-an-existing-column)
|
82
82
|
- [adding a column with a volatile default value](#adding-a-column-with-a-volatile-default-value)
|
83
|
+
- [renaming a schema](#renaming-a-schema)
|
83
84
|
|
84
85
|
Config-specific checks:
|
85
86
|
|
@@ -658,6 +659,31 @@ end
|
|
658
659
|
|
659
660
|
Then [backfill the data](#backfilling-data).
|
660
661
|
|
662
|
+
### Renaming a schema
|
663
|
+
|
664
|
+
#### Bad
|
665
|
+
|
666
|
+
Renaming a schema that’s in use will cause errors in your application.
|
667
|
+
|
668
|
+
```ruby
|
669
|
+
class RenameUsersToCustomers < ActiveRecord::Migration[8.1]
|
670
|
+
def change
|
671
|
+
rename_schema :users, :customers
|
672
|
+
end
|
673
|
+
end
|
674
|
+
```
|
675
|
+
|
676
|
+
#### Good
|
677
|
+
|
678
|
+
A safer approach is to:
|
679
|
+
|
680
|
+
1. Create a new schema
|
681
|
+
2. Write to both schemas
|
682
|
+
3. Backfill data from the old schema to the new schema
|
683
|
+
4. Move reads from the old schema to the new schema
|
684
|
+
5. Stop writing to the old schema
|
685
|
+
6. Drop the old schema
|
686
|
+
|
661
687
|
### Changing the default value of a column
|
662
688
|
|
663
689
|
#### Bad
|
@@ -79,6 +79,8 @@ module StrongMigrations
|
|
79
79
|
check_remove_index(*args)
|
80
80
|
when :rename_column
|
81
81
|
check_rename_column
|
82
|
+
when :rename_schema
|
83
|
+
check_rename_schema
|
82
84
|
when :rename_table
|
83
85
|
check_rename_table
|
84
86
|
when :validate_check_constraint
|
@@ -111,7 +113,7 @@ module StrongMigrations
|
|
111
113
|
end
|
112
114
|
|
113
115
|
# outdated statistics + a new index can hurt performance of existing queries
|
114
|
-
if StrongMigrations.auto_analyze && direction == :up && method
|
116
|
+
if StrongMigrations.auto_analyze && direction == :up && adds_index?(method, *args)
|
115
117
|
adapter.analyze_table(args[0])
|
116
118
|
end
|
117
119
|
|
@@ -256,6 +258,18 @@ module StrongMigrations
|
|
256
258
|
end
|
257
259
|
end
|
258
260
|
|
261
|
+
def adds_index?(method, *args)
|
262
|
+
case method
|
263
|
+
when :add_index
|
264
|
+
true
|
265
|
+
when :add_reference, :add_belongs_to
|
266
|
+
options = args.extract_options!
|
267
|
+
!!options.fetch(:index, true)
|
268
|
+
else
|
269
|
+
false
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
259
273
|
# REINDEX INDEX CONCURRENTLY leaves a new invalid index if it fails, so use remove_index instead
|
260
274
|
def remove_invalid_index_if_needed(*args)
|
261
275
|
options = args.extract_options!
|
@@ -102,6 +102,17 @@ in your application. A safer approach is to:
|
|
102
102
|
5. Stop writing to the old column
|
103
103
|
6. Drop the old column",
|
104
104
|
|
105
|
+
rename_schema:
|
106
|
+
"Renaming a schema that's in use will cause errors
|
107
|
+
in your application. A safer approach is to:
|
108
|
+
|
109
|
+
1. Create a new schema
|
110
|
+
2. Write to both schemas
|
111
|
+
3. Backfill data from the old schema to the new schema
|
112
|
+
4. Move reads from the old schema to the new schema
|
113
|
+
5. Stop writing to the old schema
|
114
|
+
6. Drop the old schema",
|
115
|
+
|
105
116
|
rename_table:
|
106
117
|
"Renaming a table that's in use will cause errors
|
107
118
|
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.5.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: 3.6.
|
75
|
+
rubygems_version: 3.6.9
|
76
76
|
specification_version: 4
|
77
77
|
summary: Catch unsafe migrations in development
|
78
78
|
test_files: []
|