strong_migrations 1.4.3 → 1.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 +9 -0
- data/README.md +20 -1
- data/lib/strong_migrations/checks.rb +5 -1
- data/lib/strong_migrations/error_messages.rb +3 -0
- data/lib/strong_migrations/safe_methods.rb +12 -2
- data/lib/strong_migrations/version.rb +1 -1
- data/lib/strong_migrations.rb +14 -14
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b830fe1881c2a85f578d28bb4b938c38204627897639cfc28ae44486f81dfb90
|
4
|
+
data.tar.gz: '09b4ef459fa407a8143120ec2dc19c98b5b02a885b1537cce26d63bea648eeab'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e34db2fb7db9d0b22c9c3c2a8ecca150308cb70b54e1e2b08eec2ccb52460f8aa9818a409aec0d7782678523bda35471fbd693cf4b025bbbd9dffe26a127afb
|
7
|
+
data.tar.gz: aad5de96c3886caa4c34f78a85edd6a8ada109f3acc31d8d72bcc6ff8d3ee41787f052cfcf56598103c30dddccd22a61d958e40ae6ac8bcdafeed22b4bc6d3c3
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 1.5.0 (2023-07-02)
|
2
|
+
|
3
|
+
- Added check for `add_column` with stored generated columns
|
4
|
+
- Fixed `add_reference` with `foreign_key` and `index: false`
|
5
|
+
|
6
|
+
## 1.4.4 (2023-03-08)
|
7
|
+
|
8
|
+
- Fixed `add_foreign_key` with `name` and `column` options with `safe_by_default`
|
9
|
+
|
1
10
|
## 1.4.3 (2023-02-19)
|
2
11
|
|
3
12
|
- Fixed check for `change_column` to account for charset with MySQL and MariaDB
|
data/README.md
CHANGED
@@ -62,6 +62,7 @@ Potentially dangerous operations:
|
|
62
62
|
- [removing a column](#removing-a-column)
|
63
63
|
- [adding a column with a default value](#adding-a-column-with-a-default-value)
|
64
64
|
- [backfilling data](#backfilling-data)
|
65
|
+
- [adding a stored generated column](#adding-a-stored-generated-column) [unreleased]
|
65
66
|
- [changing the type of a column](#changing-the-type-of-a-column)
|
66
67
|
- [renaming a column](#renaming-a-column)
|
67
68
|
- [renaming a table](#renaming-a-table)
|
@@ -191,6 +192,24 @@ class BackfillSomeColumn < ActiveRecord::Migration[7.0]
|
|
191
192
|
end
|
192
193
|
```
|
193
194
|
|
195
|
+
### Adding a stored generated column
|
196
|
+
|
197
|
+
#### Bad
|
198
|
+
|
199
|
+
Adding a stored generated column causes the entire table to be rewritten. During this time, reads and writes are blocked in Postgres, and writes are blocked in MySQL and MariaDB.
|
200
|
+
|
201
|
+
```ruby
|
202
|
+
class AddSomeColumnToUsers < ActiveRecord::Migration[7.0]
|
203
|
+
def change
|
204
|
+
add_column :users, :some_column, :virtual, type: :string, as: "...", stored: true
|
205
|
+
end
|
206
|
+
end
|
207
|
+
```
|
208
|
+
|
209
|
+
#### Good
|
210
|
+
|
211
|
+
Add a non-generated column and use callbacks or triggers instead (or a virtual generated column with MySQL and MariaDB).
|
212
|
+
|
194
213
|
### Changing the type of a column
|
195
214
|
|
196
215
|
#### Bad
|
@@ -224,7 +243,7 @@ And some in MySQL and MariaDB:
|
|
224
243
|
|
225
244
|
Type | Safe Changes
|
226
245
|
--- | ---
|
227
|
-
`string` | Increasing `:limit` from under 63 up to 63, increasing `:limit` from over 63 to the max (the threshold
|
246
|
+
`string` | Increasing `:limit` from under 63 up to 63, increasing `:limit` from over 63 to the max (the threshold can be different if using an encoding other than `utf8mb4` - for instance, it’s 85 for `utf8mb3` and 255 for `latin1`)
|
228
247
|
|
229
248
|
#### Good
|
230
249
|
|
@@ -71,6 +71,10 @@ Then add the NOT NULL constraint in separate migrations."
|
|
71
71
|
raise_error :add_column_json,
|
72
72
|
command: command_str("add_column", [table, column, :jsonb, options])
|
73
73
|
end
|
74
|
+
|
75
|
+
if type.to_s == "virtual" && options[:stored]
|
76
|
+
raise_error :add_column_generated_stored, rewrite_blocks: adapter.rewrite_blocks
|
77
|
+
end
|
74
78
|
end
|
75
79
|
|
76
80
|
def check_add_exclusion_constraint(*args)
|
@@ -147,7 +151,7 @@ Then add the NOT NULL constraint in separate migrations."
|
|
147
151
|
if bad_index || options[:foreign_key]
|
148
152
|
if index_value.is_a?(Hash)
|
149
153
|
options[:index] = options[:index].merge(algorithm: :concurrently)
|
150
|
-
|
154
|
+
elsif index_value
|
151
155
|
options = options.merge(index: {algorithm: :concurrently})
|
152
156
|
end
|
153
157
|
|
@@ -50,6 +50,9 @@ class %{migration_name} < ActiveRecord::Migration%{migration_suffix}
|
|
50
50
|
end
|
51
51
|
end",
|
52
52
|
|
53
|
+
add_column_generated_stored:
|
54
|
+
"Adding a stored generated column blocks %{rewrite_blocks} while the entire table is rewritten.",
|
55
|
+
|
53
56
|
change_column:
|
54
57
|
"Changing the type of an existing column blocks %{rewrite_blocks}
|
55
58
|
while the entire table is rewritten. A safer approach is to:
|
@@ -48,10 +48,20 @@ module StrongMigrations
|
|
48
48
|
dir.up do
|
49
49
|
@migration.add_foreign_key(from_table, to_table, *args, **options.merge(validate: false))
|
50
50
|
disable_transaction
|
51
|
-
|
51
|
+
validate_options = options.slice(:column, :name)
|
52
|
+
if ActiveRecord::VERSION::MAJOR >= 6
|
53
|
+
@migration.validate_foreign_key(from_table, to_table, **validate_options)
|
54
|
+
else
|
55
|
+
@migration.validate_foreign_key(from_table, validate_options.any? ? validate_options : to_table)
|
56
|
+
end
|
52
57
|
end
|
53
58
|
dir.down do
|
54
|
-
|
59
|
+
remove_options = options.slice(:column, :name)
|
60
|
+
if ActiveRecord::VERSION::MAJOR >= 6
|
61
|
+
@migration.remove_foreign_key(from_table, to_table, **remove_options)
|
62
|
+
else
|
63
|
+
@migration.remove_foreign_key(from_table, remove_options.any? ? remove_options : to_table)
|
64
|
+
end
|
55
65
|
end
|
56
66
|
end
|
57
67
|
end
|
data/lib/strong_migrations.rb
CHANGED
@@ -2,22 +2,22 @@
|
|
2
2
|
require "active_support"
|
3
3
|
|
4
4
|
# adapters
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
require_relative "strong_migrations/adapters/abstract_adapter"
|
6
|
+
require_relative "strong_migrations/adapters/mysql_adapter"
|
7
|
+
require_relative "strong_migrations/adapters/mariadb_adapter"
|
8
|
+
require_relative "strong_migrations/adapters/postgresql_adapter"
|
9
9
|
|
10
10
|
# modules
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
require_relative "strong_migrations/checks"
|
12
|
+
require_relative "strong_migrations/safe_methods"
|
13
|
+
require_relative "strong_migrations/checker"
|
14
|
+
require_relative "strong_migrations/database_tasks"
|
15
|
+
require_relative "strong_migrations/migration"
|
16
|
+
require_relative "strong_migrations/migrator"
|
17
|
+
require_relative "strong_migrations/version"
|
18
18
|
|
19
19
|
# integrations
|
20
|
-
|
20
|
+
require_relative "strong_migrations/railtie" if defined?(Rails)
|
21
21
|
|
22
22
|
module StrongMigrations
|
23
23
|
class Error < StandardError; end
|
@@ -86,7 +86,7 @@ module StrongMigrations
|
|
86
86
|
end
|
87
87
|
|
88
88
|
# load error messages
|
89
|
-
|
89
|
+
require_relative "strong_migrations/error_messages"
|
90
90
|
|
91
91
|
ActiveSupport.on_load(:active_record) do
|
92
92
|
ActiveRecord::Migration.prepend(StrongMigrations::Migration)
|
@@ -96,6 +96,6 @@ ActiveSupport.on_load(:active_record) do
|
|
96
96
|
ActiveRecord::Tasks::DatabaseTasks.singleton_class.prepend(StrongMigrations::DatabaseTasks)
|
97
97
|
end
|
98
98
|
|
99
|
-
|
99
|
+
require_relative "strong_migrations/schema_dumper"
|
100
100
|
ActiveRecord::SchemaDumper.prepend(StrongMigrations::SchemaDumper)
|
101
101
|
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: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2023-02
|
13
|
+
date: 2023-07-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
|
-
rubygems_version: 3.4.
|
78
|
+
rubygems_version: 3.4.10
|
79
79
|
signing_key:
|
80
80
|
specification_version: 4
|
81
81
|
summary: Catch unsafe migrations in development
|