strong_migrations 2.4.0 → 2.5.1
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 +9 -0
- data/README.md +26 -0
- data/lib/strong_migrations/checker.rb +25 -4
- data/lib/strong_migrations/checks.rb +4 -0
- data/lib/strong_migrations/error_messages.rb +11 -0
- data/lib/strong_migrations/migrator.rb +5 -1
- 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: 9fa65b489492df55a19b402db34b26e6a8e4369ad0bd1078622e130d07813a85
|
4
|
+
data.tar.gz: 5ce0a9af74812f962a277ac87fefed4322448b3da5bf7bfbe778e83b5bbd1c88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bec4fce43c3f0dd2a8c8e0f74c7aa09d0a4fadf05132285ad91496266476faef87323076fab6067499d9688100b81a78f274e7769af730bc9502f706e6ea5ebb
|
7
|
+
data.tar.gz: 9cebe149959161a5bf1abd62ff69e553187f867da3f49837c95f4843077e9880654eafe41786ff913e1fdba02cc2dd4c8eaf7d35996ce190779d62003a8314fc
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 2.5.1 (2025-10-13)
|
2
|
+
|
3
|
+
- Fixed `transaction_timeout` option with DDL transaction
|
4
|
+
|
5
|
+
## 2.5.0 (2025-07-27)
|
6
|
+
|
7
|
+
- Added check for `rename_schema`
|
8
|
+
- Made `auto_analyze` apply to `add_reference`
|
9
|
+
|
1
10
|
## 2.4.0 (2025-06-23)
|
2
11
|
|
3
12
|
- Added `remove_invalid_indexes` option to install generator
|
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
|
|
@@ -149,6 +151,16 @@ module StrongMigrations
|
|
149
151
|
StrongMigrations.skipped_databases.map(&:to_s).include?(db_config_name)
|
150
152
|
end
|
151
153
|
|
154
|
+
def set_transaction_timeout
|
155
|
+
return if defined?(@transaction_timeout_set)
|
156
|
+
|
157
|
+
if StrongMigrations.transaction_timeout
|
158
|
+
adapter.set_transaction_timeout(StrongMigrations.transaction_timeout)
|
159
|
+
end
|
160
|
+
|
161
|
+
@transaction_timeout_set = true
|
162
|
+
end
|
163
|
+
|
152
164
|
private
|
153
165
|
|
154
166
|
def check_adapter
|
@@ -181,9 +193,6 @@ module StrongMigrations
|
|
181
193
|
if StrongMigrations.statement_timeout
|
182
194
|
adapter.set_statement_timeout(StrongMigrations.statement_timeout)
|
183
195
|
end
|
184
|
-
if StrongMigrations.transaction_timeout
|
185
|
-
adapter.set_transaction_timeout(StrongMigrations.transaction_timeout)
|
186
|
-
end
|
187
196
|
if StrongMigrations.lock_timeout
|
188
197
|
adapter.set_lock_timeout(StrongMigrations.lock_timeout)
|
189
198
|
end
|
@@ -256,6 +265,18 @@ module StrongMigrations
|
|
256
265
|
end
|
257
266
|
end
|
258
267
|
|
268
|
+
def adds_index?(method, *args)
|
269
|
+
case method
|
270
|
+
when :add_index
|
271
|
+
true
|
272
|
+
when :add_reference, :add_belongs_to
|
273
|
+
options = args.extract_options!
|
274
|
+
!!options.fetch(:index, true)
|
275
|
+
else
|
276
|
+
false
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
259
280
|
# REINDEX INDEX CONCURRENTLY leaves a new invalid index if it fails, so use remove_index instead
|
260
281
|
def remove_invalid_index_if_needed(*args)
|
261
282
|
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:
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module StrongMigrations
|
2
2
|
module Migrator
|
3
3
|
def ddl_transaction(migration, ...)
|
4
|
-
|
4
|
+
retries = StrongMigrations.lock_timeout_retries > 0 && use_transaction?(migration)
|
5
|
+
return super unless retries || StrongMigrations.transaction_timeout
|
5
6
|
|
6
7
|
# handle MigrationProxy class
|
7
8
|
migration = migration.send(:migration) if !migration.is_a?(ActiveRecord::Migration) && migration.respond_to?(:migration, true)
|
@@ -9,6 +10,9 @@ module StrongMigrations
|
|
9
10
|
checker = migration.send(:strong_migrations_checker)
|
10
11
|
return super if checker.skip?
|
11
12
|
|
13
|
+
checker.set_transaction_timeout
|
14
|
+
return super unless retries
|
15
|
+
|
12
16
|
# retry migration since the entire transaction needs to be rerun
|
13
17
|
checker.retry_lock_timeouts(check_committed: true) do
|
14
18
|
# failed transaction reverts timeout, so need to re-apply
|
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.1
|
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: []
|