online_migrations 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +9 -9
- data/lib/online_migrations/background_migration.rb +2 -2
- data/lib/online_migrations/background_migrations/background_migration_class_validator.rb +1 -1
- data/lib/online_migrations/background_migrations/config.rb +1 -1
- data/lib/online_migrations/background_migrations/delete_associated_records.rb +1 -1
- data/lib/online_migrations/background_migrations/delete_orphaned_records.rb +1 -1
- data/lib/online_migrations/background_migrations/migration_job_status_validator.rb +2 -2
- data/lib/online_migrations/background_migrations/migration_status_validator.rb +2 -2
- data/lib/online_migrations/background_migrations/reset_counters.rb +2 -2
- data/lib/online_migrations/batch_iterator.rb +3 -3
- data/lib/online_migrations/change_column_type_helpers.rb +33 -24
- data/lib/online_migrations/command_checker.rb +22 -19
- data/lib/online_migrations/command_recorder.rb +4 -4
- data/lib/online_migrations/config.rb +1 -1
- data/lib/online_migrations/error_messages.rb +3 -3
- data/lib/online_migrations/migration.rb +1 -1
- data/lib/online_migrations/schema_statements.rb +2 -2
- data/lib/online_migrations/utils.rb +1 -1
- data/lib/online_migrations/verbose_sql_logs.rb +7 -1
- 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: b4f89ce12461dd3b786e98ecbc1afc315a5013a0967e90b9307d47b080924723
|
4
|
+
data.tar.gz: 797f19c861514e843a7d6e6f3222d19f36b77fc30ff3cc1ac2808591fa339f75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4458f5096fc180bb27411fc800db6dce588473373c0945abf2121b67591dc031badb498582681e55128055a85105600be1de8851818e93bf1108f42d43dd24c
|
7
|
+
data.tar.gz: ec49dd203d5ded9638d623af2b35b6ca1980a182a54ecf57bcbaf9d910cfe8f3e2cbd0f90c7e4d94f76236be91ef373b50e29a65e59be6e12ef6b55ad21de91b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
## master (unreleased)
|
2
2
|
|
3
|
+
## 0.8.2 (2023-09-26)
|
4
|
+
|
5
|
+
- Promote check constraint to `NOT NULL` on PostgreSQL >= 12 when changing column type
|
6
|
+
- Fix `safety_assured` with `revert`
|
7
|
+
|
3
8
|
## 0.8.1 (2023-08-04)
|
4
9
|
|
5
10
|
- Fix `update_columns_in_batches` when multiple columns are passed
|
@@ -8,7 +13,7 @@
|
|
8
13
|
## 0.8.0 (2023-07-24)
|
9
14
|
|
10
15
|
- Add check for `change_column_default`
|
11
|
-
- Add check for `
|
16
|
+
- Add check for `add_unique_constraint` (Active Record >= 7.1)
|
12
17
|
- Add check for `add_column` with stored generated columns
|
13
18
|
|
14
19
|
## 0.7.3 (2023-05-30)
|
data/README.md
CHANGED
@@ -143,7 +143,7 @@ Potentially dangerous operations:
|
|
143
143
|
- [adding a reference](#adding-a-reference)
|
144
144
|
- [adding a foreign key](#adding-a-foreign-key)
|
145
145
|
- [adding an exclusion constraint](#adding-an-exclusion-constraint)
|
146
|
-
- [adding a unique
|
146
|
+
- [adding a unique constraint](#adding-a-unique-constraint)
|
147
147
|
- [adding a json column](#adding-a-json-column)
|
148
148
|
- [adding a stored generated column](#adding-a-stored-generated-column)
|
149
149
|
- [using primary key with short integer type](#using-primary-key-with-short-integer-type)
|
@@ -880,16 +880,16 @@ end
|
|
880
880
|
|
881
881
|
[Let us know](https://github.com/fatkodima/online_migrations/issues/new) if you have a safe way to do this (exclusion constraints cannot be marked `NOT VALID`).
|
882
882
|
|
883
|
-
### Adding a unique
|
883
|
+
### Adding a unique constraint
|
884
884
|
|
885
885
|
:x: **Bad**
|
886
886
|
|
887
|
-
Adding a unique
|
887
|
+
Adding a unique constraint blocks reads and writes while the underlying index is being built.
|
888
888
|
|
889
889
|
```ruby
|
890
|
-
class
|
890
|
+
class AddUniqueConstraint < ActiveRecord::Migration[7.1]
|
891
891
|
def change
|
892
|
-
|
892
|
+
add_unique_constraint :sections, :position, deferrable: :deferred
|
893
893
|
end
|
894
894
|
end
|
895
895
|
```
|
@@ -899,7 +899,7 @@ end
|
|
899
899
|
A safer approach is to create a unique index first, and then create a unique key using that index.
|
900
900
|
|
901
901
|
```ruby
|
902
|
-
class
|
902
|
+
class AddUniqueConstraintAddIndex < ActiveRecord::Migration[7.1]
|
903
903
|
disable_ddl_transaction!
|
904
904
|
|
905
905
|
def change
|
@@ -909,13 +909,13 @@ end
|
|
909
909
|
```
|
910
910
|
|
911
911
|
```ruby
|
912
|
-
class
|
912
|
+
class AddUniqueConstraint < ActiveRecord::Migration[7.1]
|
913
913
|
def up
|
914
|
-
|
914
|
+
add_unique_constraint :sections, :position, deferrable: :deferred, using_index: "index_sections_on_position"
|
915
915
|
end
|
916
916
|
|
917
917
|
def down
|
918
|
-
|
918
|
+
remove_unique_constraint :sections, :position
|
919
919
|
end
|
920
920
|
end
|
921
921
|
```
|
@@ -21,8 +21,8 @@ module OnlineMigrations
|
|
21
21
|
migration = "#{namespace}::#{name}".safe_constantize ||
|
22
22
|
"#{internal_namespace}::#{name}".safe_constantize
|
23
23
|
|
24
|
-
raise NotFoundError.new("Background Migration #{name} not found", name)
|
25
|
-
|
24
|
+
raise NotFoundError.new("Background Migration #{name} not found", name) if migration.nil?
|
25
|
+
if !(migration.is_a?(Class) && migration < self)
|
26
26
|
raise NotFoundError.new("#{name} is not a Background Migration", name)
|
27
27
|
end
|
28
28
|
|
@@ -8,7 +8,7 @@ module OnlineMigrations
|
|
8
8
|
relation = record.migration_relation
|
9
9
|
migration_name = record.migration_name
|
10
10
|
|
11
|
-
|
11
|
+
if !relation.is_a?(ActiveRecord::Relation)
|
12
12
|
record.errors.add(
|
13
13
|
:migration_name,
|
14
14
|
"#{migration_name}#relation must return an ActiveRecord::Relation object"
|
@@ -16,7 +16,7 @@ module OnlineMigrations
|
|
16
16
|
# https://github.com/rails/rails/pull/34727
|
17
17
|
associations.inject(model.unscoped) do |relation, association|
|
18
18
|
reflection = model.reflect_on_association(association)
|
19
|
-
|
19
|
+
if reflection.nil?
|
20
20
|
raise ArgumentError, "'#{model.name}' has no association called '#{association}'"
|
21
21
|
end
|
22
22
|
|
@@ -11,12 +11,12 @@ module OnlineMigrations
|
|
11
11
|
}
|
12
12
|
|
13
13
|
def validate(record)
|
14
|
-
return
|
14
|
+
return if !record.status_changed?
|
15
15
|
|
16
16
|
previous_status, new_status = record.status_change
|
17
17
|
valid_new_statuses = VALID_STATUS_TRANSITIONS.fetch(previous_status, [])
|
18
18
|
|
19
|
-
|
19
|
+
if !valid_new_statuses.include?(new_status)
|
20
20
|
record.errors.add(
|
21
21
|
:status,
|
22
22
|
"cannot transition background migration job from status #{previous_status} to #{new_status}"
|
@@ -29,12 +29,12 @@ module OnlineMigrations
|
|
29
29
|
}
|
30
30
|
|
31
31
|
def validate(record)
|
32
|
-
return
|
32
|
+
return if !record.status_changed?
|
33
33
|
|
34
34
|
previous_status, new_status = record.status_change
|
35
35
|
valid_new_statuses = VALID_STATUS_TRANSITIONS.fetch(previous_status, [])
|
36
36
|
|
37
|
-
|
37
|
+
if !valid_new_statuses.include?(new_status)
|
38
38
|
record.errors.add(
|
39
39
|
:status,
|
40
40
|
"cannot transition background migration from status #{previous_status} to #{new_status}"
|
@@ -59,7 +59,7 @@ module OnlineMigrations
|
|
59
59
|
def has_many_association(counter_association) # rubocop:disable Naming/PredicateName
|
60
60
|
has_many_association = model.reflect_on_association(counter_association)
|
61
61
|
|
62
|
-
|
62
|
+
if !has_many_association
|
63
63
|
has_many = model.reflect_on_all_associations(:has_many)
|
64
64
|
|
65
65
|
has_many_association = has_many.find do |association|
|
@@ -74,7 +74,7 @@ module OnlineMigrations
|
|
74
74
|
|
75
75
|
counter_association = has_many_association.plural_name if has_many_association
|
76
76
|
end
|
77
|
-
raise ArgumentError, "'#{model.name}' has no association called '#{counter_association}'"
|
77
|
+
raise ArgumentError, "'#{model.name}' has no association called '#{counter_association}'" if !has_many_association
|
78
78
|
|
79
79
|
if has_many_association.is_a?(ActiveRecord::Reflection::ThroughReflection)
|
80
80
|
has_many_association = has_many_association.through_reflection
|
@@ -14,7 +14,7 @@ module OnlineMigrations
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def each_batch(of: 1000, column: relation.primary_key, start: nil, finish: nil, order: :asc)
|
17
|
-
|
17
|
+
if ![:asc, :desc].include?(order)
|
18
18
|
raise ArgumentError, ":order must be :asc or :desc, got #{order.inspect}"
|
19
19
|
end
|
20
20
|
|
@@ -26,7 +26,7 @@ module OnlineMigrations
|
|
26
26
|
|
27
27
|
start_row = base_relation.uncached { base_relation.first }
|
28
28
|
|
29
|
-
return
|
29
|
+
return if !start_row
|
30
30
|
|
31
31
|
start_id = start_row[column]
|
32
32
|
arel_table = relation.arel_table
|
@@ -67,7 +67,7 @@ module OnlineMigrations
|
|
67
67
|
# Retaining the results in the query cache would undermine the point of batching.
|
68
68
|
batch_relation.uncached { yield batch_relation, index }
|
69
69
|
|
70
|
-
break
|
70
|
+
break if !stop_row
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -113,21 +113,22 @@ module OnlineMigrations
|
|
113
113
|
|
114
114
|
if raw_connection.server_version >= 11_00_00
|
115
115
|
if primary_key(table_name) == column_name.to_s && old_col.type == :integer
|
116
|
-
#
|
117
|
-
#
|
118
|
-
#
|
119
|
-
#
|
116
|
+
# For PG < 11 and Primary Key conversions, setting a column as the PK
|
117
|
+
# converts even check constraints to NOT NULL column constraints
|
118
|
+
# and forces an inline re-verification of the whole table.
|
119
|
+
# To avoid this, we instead set it to `NOT NULL DEFAULT 0` and we'll
|
120
|
+
# copy the correct values when backfilling.
|
120
121
|
add_column(table_name, tmp_column_name, new_type,
|
121
122
|
**old_col_options.merge(column_options).merge(default: old_col.default || 0, null: false))
|
122
123
|
else
|
123
|
-
|
124
|
+
if !old_col.default.nil?
|
124
125
|
old_col_options = old_col_options.merge(default: old_col.default, null: old_col.null)
|
125
126
|
end
|
126
127
|
add_column(table_name, tmp_column_name, new_type, **old_col_options.merge(column_options))
|
127
128
|
end
|
128
129
|
else
|
129
130
|
add_column(table_name, tmp_column_name, new_type, **old_col_options.merge(column_options))
|
130
|
-
change_column_default(table_name, tmp_column_name, old_col.default)
|
131
|
+
change_column_default(table_name, tmp_column_name, old_col.default) if !old_col.default.nil?
|
131
132
|
end
|
132
133
|
end
|
133
134
|
|
@@ -247,22 +248,7 @@ module OnlineMigrations
|
|
247
248
|
|
248
249
|
# At this point we are sure there are no NULLs in this column
|
249
250
|
transaction do
|
250
|
-
|
251
|
-
# converts even check constraints to NOT NULL column constraints
|
252
|
-
# and forces an inline re-verification of the whole table.
|
253
|
-
#
|
254
|
-
# For PG >= 12 we can "promote" CHECK constraint to NOT NULL constraint,
|
255
|
-
# but for older versions we can set attribute as NOT NULL directly
|
256
|
-
# through PG internal tables.
|
257
|
-
# In-depth analysis of implications of this was made, so this approach
|
258
|
-
# is considered safe - https://habr.com/ru/company/haulmont/blog/493954/ (in russian).
|
259
|
-
execute(<<-SQL.strip_heredoc)
|
260
|
-
UPDATE pg_catalog.pg_attribute
|
261
|
-
SET attnotnull = true
|
262
|
-
WHERE attrelid = #{quote(table_name)}::regclass
|
263
|
-
AND attname = #{quote(tmp_column_name)}
|
264
|
-
SQL
|
265
|
-
|
251
|
+
__set_not_null(table_name, tmp_column_name)
|
266
252
|
remove_not_null_constraint(table_name, tmp_column_name)
|
267
253
|
end
|
268
254
|
end
|
@@ -389,7 +375,7 @@ module OnlineMigrations
|
|
389
375
|
options.each do |option|
|
390
376
|
if column.respond_to?(option)
|
391
377
|
value = column.public_send(option)
|
392
|
-
result[option] = value
|
378
|
+
result[option] = value if !value.nil?
|
393
379
|
end
|
394
380
|
end
|
395
381
|
result
|
@@ -417,7 +403,7 @@ module OnlineMigrations
|
|
417
403
|
end
|
418
404
|
|
419
405
|
# This is necessary as we can't properly rename indexes such as "taggings_idx".
|
420
|
-
|
406
|
+
if !index.name.include?(from_column)
|
421
407
|
raise "The index #{index.name} can not be copied as it does not " \
|
422
408
|
"mention the old column. You have to rename this index manually first."
|
423
409
|
end
|
@@ -482,6 +468,29 @@ module OnlineMigrations
|
|
482
468
|
end
|
483
469
|
end
|
484
470
|
|
471
|
+
def __set_not_null(table_name, column_name)
|
472
|
+
# For PG >= 12 we can "promote" CHECK constraint to NOT NULL constraint:
|
473
|
+
# https://github.com/postgres/postgres/commit/bbb96c3704c041d139181c6601e5bc770e045d26
|
474
|
+
if raw_connection.server_version >= 12_00_00
|
475
|
+
execute(<<-SQL.strip_heredoc)
|
476
|
+
ALTER TABLE #{quote_table_name(table_name)}
|
477
|
+
ALTER #{quote_column_name(column_name)}
|
478
|
+
SET NOT NULL
|
479
|
+
SQL
|
480
|
+
else
|
481
|
+
# For older versions we can set attribute as NOT NULL directly
|
482
|
+
# through PG internal tables.
|
483
|
+
# In-depth analysis of implications of this was made, so this approach
|
484
|
+
# is considered safe - https://habr.com/ru/company/haulmont/blog/493954/ (in russian).
|
485
|
+
execute(<<-SQL.strip_heredoc)
|
486
|
+
UPDATE pg_catalog.pg_attribute
|
487
|
+
SET attnotnull = true
|
488
|
+
WHERE attrelid = #{quote(table_name)}::regclass
|
489
|
+
AND attname = #{quote(column_name)}
|
490
|
+
SQL
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
485
494
|
def __check_constraints_for(table_name, column_name)
|
486
495
|
__check_constraints(table_name).select { |c| c["column_name"] == column_name }
|
487
496
|
end
|
@@ -7,11 +7,22 @@ require "set"
|
|
7
7
|
module OnlineMigrations
|
8
8
|
# @private
|
9
9
|
class CommandChecker
|
10
|
+
class << self
|
11
|
+
attr_accessor :safe
|
12
|
+
|
13
|
+
def safety_assured
|
14
|
+
prev_value = safe
|
15
|
+
self.safe = true
|
16
|
+
yield
|
17
|
+
ensure
|
18
|
+
self.safe = prev_value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
10
22
|
attr_accessor :direction
|
11
23
|
|
12
24
|
def initialize(migration)
|
13
25
|
@migration = migration
|
14
|
-
@safe = false
|
15
26
|
@new_tables = []
|
16
27
|
@new_columns = []
|
17
28
|
@lock_timeout_checked = false
|
@@ -19,19 +30,11 @@ module OnlineMigrations
|
|
19
30
|
@removed_indexes = []
|
20
31
|
end
|
21
32
|
|
22
|
-
def safety_assured
|
23
|
-
prev_value = @safe
|
24
|
-
@safe = true
|
25
|
-
yield
|
26
|
-
ensure
|
27
|
-
@safe = prev_value
|
28
|
-
end
|
29
|
-
|
30
33
|
def check(command, *args, &block)
|
31
34
|
check_database_version
|
32
35
|
check_lock_timeout
|
33
36
|
|
34
|
-
|
37
|
+
if !safe?
|
35
38
|
do_check(command, *args, &block)
|
36
39
|
|
37
40
|
run_custom_checks(command, args)
|
@@ -101,7 +104,7 @@ module OnlineMigrations
|
|
101
104
|
end
|
102
105
|
|
103
106
|
def safe?
|
104
|
-
|
107
|
+
self.class.safe ||
|
105
108
|
ENV["SAFETY_ASSURED"] ||
|
106
109
|
(direction == :down && !OnlineMigrations.config.check_down) ||
|
107
110
|
version <= OnlineMigrations.config.start_after
|
@@ -477,7 +480,7 @@ module OnlineMigrations
|
|
477
480
|
bad_foreign_key: bad_foreign_key
|
478
481
|
end
|
479
482
|
|
480
|
-
|
483
|
+
if !options[:polymorphic]
|
481
484
|
type = (options[:type] || (Utils.ar_version >= 5.1 ? :bigint : :integer)).to_sym
|
482
485
|
column_name = "#{ref_name}_id"
|
483
486
|
|
@@ -507,9 +510,9 @@ module OnlineMigrations
|
|
507
510
|
existing_indexes = connection.indexes(table_name)
|
508
511
|
|
509
512
|
@removed_indexes.each do |removed_index|
|
510
|
-
next
|
513
|
+
next if !removed_index.intersect?(index)
|
511
514
|
|
512
|
-
|
515
|
+
if existing_indexes.none? { |existing_index| removed_index.covered_by?(existing_index) }
|
513
516
|
raise_error :replace_index
|
514
517
|
end
|
515
518
|
end
|
@@ -560,7 +563,7 @@ module OnlineMigrations
|
|
560
563
|
end
|
561
564
|
|
562
565
|
def add_exclusion_constraint(table_name, _expression, **_options)
|
563
|
-
|
566
|
+
if !new_or_small_table?(table_name)
|
564
567
|
raise_error :add_exclusion_constraint
|
565
568
|
end
|
566
569
|
end
|
@@ -575,15 +578,15 @@ module OnlineMigrations
|
|
575
578
|
end
|
576
579
|
end
|
577
580
|
|
578
|
-
def
|
581
|
+
def add_unique_constraint(table_name, column_name = nil, **options)
|
579
582
|
return if new_or_small_table?(table_name) || options[:using_index] || !column_name
|
580
583
|
|
581
584
|
index_name = index_name(table_name, column_name)
|
582
585
|
|
583
|
-
raise_error :
|
586
|
+
raise_error :add_unique_constraint,
|
584
587
|
add_index_code: command_str(:add_index, table_name, column_name, unique: true, name: index_name, algorithm: :concurrently),
|
585
|
-
add_code: command_str(:
|
586
|
-
remove_code: command_str(:
|
588
|
+
add_code: command_str(:add_unique_constraint, table_name, **options.merge(using_index: index_name)),
|
589
|
+
remove_code: command_str(:remove_unique_constraint, table_name, column_name)
|
587
590
|
end
|
588
591
|
|
589
592
|
# Implementation is from Active Record
|
@@ -98,7 +98,7 @@ module OnlineMigrations
|
|
98
98
|
|
99
99
|
def invert_revert_initialize_columns_rename(args)
|
100
100
|
_table, old_new_column_hash = args
|
101
|
-
|
101
|
+
if !old_new_column_hash
|
102
102
|
raise ActiveRecord::IrreversibleMigration,
|
103
103
|
"revert_initialize_columns_rename is only reversible if given a hash of old and new columns."
|
104
104
|
end
|
@@ -107,7 +107,7 @@ module OnlineMigrations
|
|
107
107
|
|
108
108
|
def invert_finalize_table_rename(args)
|
109
109
|
_table_name, new_name = args
|
110
|
-
|
110
|
+
if !new_name
|
111
111
|
raise ActiveRecord::IrreversibleMigration,
|
112
112
|
"finalize_table_rename is only reversible if given a new_name."
|
113
113
|
end
|
@@ -115,7 +115,7 @@ module OnlineMigrations
|
|
115
115
|
end
|
116
116
|
|
117
117
|
def invert_revert_initialize_column_type_change(args)
|
118
|
-
|
118
|
+
if !args[2]
|
119
119
|
raise ActiveRecord::IrreversibleMigration,
|
120
120
|
"revert_initialize_column_type_change is only reversible if given a new_type."
|
121
121
|
end
|
@@ -141,7 +141,7 @@ module OnlineMigrations
|
|
141
141
|
end
|
142
142
|
|
143
143
|
def invert_remove_text_limit_constraint(args)
|
144
|
-
|
144
|
+
if !args[2]
|
145
145
|
raise ActiveRecord::IrreversibleMigration, "remove_text_limit_constraint is only reversible if given a limit."
|
146
146
|
end
|
147
147
|
|
@@ -261,7 +261,7 @@ module OnlineMigrations
|
|
261
261
|
|
262
262
|
private
|
263
263
|
def ensure_supports_multiple_dbs
|
264
|
-
|
264
|
+
if !Utils.supports_multiple_dbs?
|
265
265
|
raise "OnlineMigrations does not support multiple databases for Active Record < 6.1"
|
266
266
|
end
|
267
267
|
end
|
@@ -438,9 +438,9 @@ class <%= migration_name %> < <%= migration_parent %>
|
|
438
438
|
end
|
439
439
|
end",
|
440
440
|
|
441
|
-
|
442
|
-
"Adding a unique
|
443
|
-
A safer approach is to create a unique index first, and then create a unique
|
441
|
+
add_unique_constraint:
|
442
|
+
"Adding a unique constraint blocks reads and writes while the underlying index is being built.
|
443
|
+
A safer approach is to create a unique index first, and then create a unique constraint using that index.
|
444
444
|
|
445
445
|
class <%= migration_name %>AddIndex < <%= migration_parent %>
|
446
446
|
disable_ddl_transaction!
|
@@ -87,7 +87,7 @@ module OnlineMigrations
|
|
87
87
|
value = Arel.sql(value.call.to_s) if value.is_a?(Proc)
|
88
88
|
|
89
89
|
# Ignore subqueries in conditions
|
90
|
-
|
90
|
+
if !value.is_a?(Arel::Nodes::SqlLiteral) || value.to_s !~ /select\s+/i
|
91
91
|
arel_column = model.arel_table[column_name]
|
92
92
|
if value.nil?
|
93
93
|
arel_column.not_eq(nil)
|
@@ -665,7 +665,7 @@ module OnlineMigrations
|
|
665
665
|
__ensure_not_in_transaction!
|
666
666
|
|
667
667
|
column_name = "#{ref_name}_id"
|
668
|
-
|
668
|
+
if !column_exists?(table_name, column_name)
|
669
669
|
type = options[:type] || (Utils.ar_version >= 5.1 ? :bigint : :integer)
|
670
670
|
allow_null = options.fetch(:null, true)
|
671
671
|
add_column(table_name, column_name, type, null: allow_null)
|
@@ -139,7 +139,7 @@ module OnlineMigrations
|
|
139
139
|
private_constant :FUNCTION_CALL_RE
|
140
140
|
|
141
141
|
def volatile_default?(connection, type, value)
|
142
|
-
return false
|
142
|
+
return false if !(value.is_a?(Proc) || (type.to_s == "uuid" && value.is_a?(String)))
|
143
143
|
|
144
144
|
value = value.call if value.is_a?(Proc)
|
145
145
|
return false if !value.is_a?(String)
|
@@ -13,7 +13,13 @@ module OnlineMigrations
|
|
13
13
|
stdout_logger.level = @activerecord_logger_was.level
|
14
14
|
stdout_logger = ActiveSupport::TaggedLogging.new(stdout_logger)
|
15
15
|
|
16
|
-
combined_logger =
|
16
|
+
combined_logger =
|
17
|
+
# Broadcasting logs API was changed in https://github.com/rails/rails/pull/48615.
|
18
|
+
if Utils.ar_version >= 7.1
|
19
|
+
ActiveSupport::BroadcastLogger.new(stdout_logger, @activerecord_logger_was)
|
20
|
+
else
|
21
|
+
stdout_logger.extend(ActiveSupport::Logger.broadcast(@activerecord_logger_was))
|
22
|
+
end
|
17
23
|
|
18
24
|
ActiveRecord::Base.logger = combined_logger
|
19
25
|
set_verbose_query_logs(false)
|
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.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fatkodima
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
|
-
rubygems_version: 3.4.
|
105
|
+
rubygems_version: 3.4.10
|
106
106
|
signing_key:
|
107
107
|
specification_version: 4
|
108
108
|
summary: Catch unsafe PostgreSQL migrations in development and run them easier in
|