online_migrations 0.5.2 → 0.5.3
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 +7 -0
- data/lib/online_migrations/command_checker.rb +9 -4
- data/lib/online_migrations/config.rb +3 -7
- data/lib/online_migrations/error_messages.rb +10 -0
- data/lib/online_migrations/schema_statements.rb +13 -2
- data/lib/online_migrations/utils.rb +4 -2
- data/lib/online_migrations/version.rb +1 -1
- 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: 0ac8a2eb2657fcc3536a9b56d16298f90f8e1a5e626ba52a6e9703b5bcaa7df0
|
4
|
+
data.tar.gz: c5357f94854fb43d1b8404ed9dcfafc2178430aeb9c6d69555f50629a94da3bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ccbc274c76ab01f8ece559b3fee27c1c5c0c495225b393c3a4afb7941f0b61d3aab9ef2885195be78ed00f29bd5e6b18e3fe0cb044b745cd791aacf34283492
|
7
|
+
data.tar.gz: 04fb250e30e7620ac1bd06fddf24a5fdfe616f285422e47e19423e23be0c8117e57d45e45029a2e1212cc5e6ad9baf3605fac8b038152fdc73b2d9a818ba211c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
## master (unreleased)
|
2
2
|
|
3
|
+
## 0.5.3 (2022-11-10)
|
4
|
+
|
5
|
+
- Fix removing index by name
|
6
|
+
- Fix multiple databases support for `start_after` and `target_version` configs
|
7
|
+
- Fix error when `Rails` defined without `Rails.env`
|
8
|
+
- Improve error message for adding column with a NULL default for PostgreSQL < 11
|
9
|
+
|
3
10
|
## 0.5.2 (2022-10-04)
|
4
11
|
|
5
12
|
- Fix sequence resetting in tests that use fixtures
|
@@ -177,10 +177,15 @@ module OnlineMigrations
|
|
177
177
|
if !new_or_small_table?(table_name) && options.key?(:default) &&
|
178
178
|
(postgresql_version < Gem::Version.new("11") || (!default.nil? && (volatile_default = Utils.volatile_default?(connection, type, default))))
|
179
179
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
180
|
+
if default.nil?
|
181
|
+
raise_error :add_column_with_default_null,
|
182
|
+
code: command_str(:add_column, table_name, column_name, type, options.except(:default))
|
183
|
+
else
|
184
|
+
raise_error :add_column_with_default,
|
185
|
+
code: command_str(:add_column_with_default, table_name, column_name, type, options),
|
186
|
+
not_null: options[:null] == false,
|
187
|
+
volatile_default: volatile_default
|
188
|
+
end
|
184
189
|
end
|
185
190
|
|
186
191
|
if type == :json
|
@@ -185,7 +185,7 @@ module OnlineMigrations
|
|
185
185
|
@small_tables = []
|
186
186
|
@check_down = false
|
187
187
|
@enabled_checks = @error_messages.keys.map { |k| [k, {}] }.to_h
|
188
|
-
@verbose_sql_logs = defined?(Rails) && Rails.env.production?
|
188
|
+
@verbose_sql_logs = defined?(Rails.env) && Rails.env.production?
|
189
189
|
end
|
190
190
|
|
191
191
|
def lock_retrier=(value)
|
@@ -262,17 +262,13 @@ module OnlineMigrations
|
|
262
262
|
private
|
263
263
|
def ensure_supports_multiple_dbs
|
264
264
|
unless Utils.supports_multiple_dbs?
|
265
|
-
raise "
|
265
|
+
raise "OnlineMigrations does not support multiple databases for Active Record < 6.1"
|
266
266
|
end
|
267
267
|
end
|
268
268
|
|
269
269
|
def db_config_name
|
270
270
|
connection = OnlineMigrations.current_migration.connection
|
271
|
-
|
272
|
-
connection.pool.spec.name
|
273
|
-
else
|
274
|
-
connection.pool.db_config.name
|
275
|
-
end
|
271
|
+
connection.pool.db_config.name
|
276
272
|
end
|
277
273
|
end
|
278
274
|
end
|
@@ -74,6 +74,16 @@ class <%= migration_name %> < <%= migration_parent %>
|
|
74
74
|
end
|
75
75
|
<% end %>",
|
76
76
|
|
77
|
+
add_column_with_default_null:
|
78
|
+
"Adding a column with a null default blocks reads and writes while the entire table is rewritten.
|
79
|
+
Instead, add the column without a default value.
|
80
|
+
|
81
|
+
class <%= migration_name %> < <%= migration_parent %>
|
82
|
+
def change
|
83
|
+
<%= code %>
|
84
|
+
end
|
85
|
+
end",
|
86
|
+
|
77
87
|
add_column_json:
|
78
88
|
"There's no equality operator for the json column type, which can cause errors for
|
79
89
|
existing SELECT DISTINCT queries in your application. Use jsonb instead.
|
@@ -689,7 +689,18 @@ module OnlineMigrations
|
|
689
689
|
index_name = options[:name]
|
690
690
|
index_name ||= index_name(table_name, column_names)
|
691
691
|
|
692
|
-
|
692
|
+
index_exists =
|
693
|
+
if Utils.ar_version <= 5.0
|
694
|
+
# Older Active Record is unable to handle blank columns correctly in `index_exists?`,
|
695
|
+
# so we need to use `index_name_exists?`.
|
696
|
+
index_name_exists?(table_name, index_name, nil)
|
697
|
+
elsif Utils.ar_version <= 6.0
|
698
|
+
index_name_exists?(table_name, index_name)
|
699
|
+
else
|
700
|
+
index_exists?(table_name, column_names, **options)
|
701
|
+
end
|
702
|
+
|
703
|
+
if index_exists
|
693
704
|
disable_statement_timeout do
|
694
705
|
# "DROP INDEX CONCURRENTLY" requires a "SHARE UPDATE EXCLUSIVE" lock.
|
695
706
|
# It only conflicts with constraint validations, other creating/removing indexes,
|
@@ -932,7 +943,7 @@ module OnlineMigrations
|
|
932
943
|
def __index_column_names(column_names)
|
933
944
|
if column_names.is_a?(String) && /\W/.match(column_names)
|
934
945
|
column_names
|
935
|
-
|
946
|
+
elsif column_names.present?
|
936
947
|
Array(column_names)
|
937
948
|
end
|
938
949
|
end
|
@@ -9,7 +9,7 @@ module OnlineMigrations
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def developer_env?
|
12
|
-
defined?(Rails) && (Rails.env.development? || Rails.env.test?)
|
12
|
+
defined?(Rails.env) && (Rails.env.development? || Rails.env.test?)
|
13
13
|
end
|
14
14
|
|
15
15
|
def say(message)
|
@@ -26,7 +26,9 @@ module OnlineMigrations
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def supports_multiple_dbs?
|
29
|
-
|
29
|
+
# Technically, Active Record 6.0+ supports multiple databases,
|
30
|
+
# but we can not get the database spec name for this version.
|
31
|
+
ar_version >= 6.1
|
30
32
|
end
|
31
33
|
|
32
34
|
def migration_parent
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: online_migrations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fatkodima
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10
|
11
|
+
date: 2022-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
103
|
requirements: []
|
104
|
-
rubygems_version: 3.
|
104
|
+
rubygems_version: 3.1.6
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: Catch unsafe PostgreSQL migrations in development and run them easier in
|