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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d290d3cb9db86b312fcdeb417aa4b24838f9135df9526dff1e525e12484ae160
4
- data.tar.gz: e169be188a233de23f961b4aefe3997e71666a37fcc581d3cc95973b20b1642e
3
+ metadata.gz: 971d5d1eabb91dc04c72cc99a24f8b92f1b0d31d8d28369577f48c283b8d8624
4
+ data.tar.gz: '08a413578f564ada7f9768aeaf469719ca051e4c37057be6324e593c73fb3144'
5
5
  SHA512:
6
- metadata.gz: 61adf361956734e8944d8dea110ee77b22db8e24cde13085a5b90f35b09f684632b33ab040632f4dc0656853f12d1255204e6736881656a50a462e041f1e56f1
7
- data.tar.gz: 7f0d1650bbb8e16e062c24defe37fec194d0f98ccd458d21db39d7664ffa51c8340a017d6ce8c1ace8018ba86da7795df881dfb19d31d578a41870ad82d55a52
6
+ metadata.gz: b8ca27268e166609ec8253ce686c6fe9cbe6d7c4b298f8c80ce7f1690e76a2c997fad2806cce52c9765f6ee92e7e389fdf6c830d3ca8ebb0241574adc02c4b57
7
+ data.tar.gz: 18731d2b1bdd12698d6b860a470249a24ea12aaa0b5b74b6510d41527ef2126c46b27ef4aa7c7adb1437bd7a006d0bb7c46490d24ec15720009723e5b0d8eca4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 2.5.0 (2025-07-27)
2
+
3
+ - Added check for `rename_schema`
4
+ - Made `auto_analyze` apply to `add_reference`
5
+
1
6
  ## 2.4.0 (2025-06-23)
2
7
 
3
8
  - 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 == :add_index
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!
@@ -384,6 +384,10 @@ module StrongMigrations
384
384
  raise_error :rename_column
385
385
  end
386
386
 
387
+ def check_rename_schema
388
+ raise_error :rename_schema
389
+ end
390
+
387
391
  def check_rename_table
388
392
  raise_error :rename_table
389
393
  end
@@ -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,3 +1,3 @@
1
1
  module StrongMigrations
2
- VERSION = "2.4.0"
2
+ VERSION = "2.5.0"
3
3
  end
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.0
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.7
75
+ rubygems_version: 3.6.9
76
76
  specification_version: 4
77
77
  summary: Catch unsafe migrations in development
78
78
  test_files: []