online_migrations 0.19.1 → 0.19.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 +5 -0
- data/README.md +2 -2
- data/lib/online_migrations/background_migrations/migration_helpers.rb +14 -18
- data/lib/online_migrations/background_migrations/migration_runner.rb +1 -1
- data/lib/online_migrations/schema_statements.rb +4 -3
- data/lib/online_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: aefd589066f5ee8e4d42964683576a6407782d5a065dae55c42336c4b50af8c6
|
4
|
+
data.tar.gz: 1723e4fd7388be89ac5b30095a4431a5829729b90b984054752ba1645c318b68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c964e25e31eed2fab19c6c205c7c0355ca8fbb1eced99898d17a0385b8f5f8411a8cf1822df3973efe5e69a5fbe7620ee8150e97f167996f55347732b9bcb8c4
|
7
|
+
data.tar.gz: c90709c6369c7a3f5d8c36a92f1a4e98099a538957ac7f282ea04b594df1ffb814d1ef5f5a803a4692c377984ae74ef0b4ddd77ec0e32c91c201087d9d0eafe5
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
## master (unreleased)
|
2
2
|
|
3
|
+
## 0.19.2 (2024-07-09)
|
4
|
+
|
5
|
+
- Fix `add_reference_concurrently` to be idempotent when adding a foreign key
|
6
|
+
- Fix `enqueue_background_data_migration` to be idempotent
|
7
|
+
|
3
8
|
## 0.19.1 (2024-05-24)
|
4
9
|
|
5
10
|
- Fix `add_index_in_background` to be idempotent
|
data/README.md
CHANGED
@@ -169,7 +169,7 @@ Config-specific checks:
|
|
169
169
|
|
170
170
|
- [changing the default value of a column](#changing-the-default-value-of-a-column)
|
171
171
|
|
172
|
-
You can also add [custom checks](#custom-checks) or [disable specific checks](#disable-checks).
|
172
|
+
You can also add [custom checks](docs/configuring.md#custom-checks) or [disable specific checks](docs/configuring.md#disable-checks).
|
173
173
|
|
174
174
|
### Removing a column
|
175
175
|
|
@@ -544,7 +544,7 @@ The technique is built on top of database views, using the following steps:
|
|
544
544
|
2. Create a VIEW using the old table name by pointing to the new table name
|
545
545
|
3. Add a workaround for Active Record's schema cache
|
546
546
|
|
547
|
-
For the previous example, to rename `
|
547
|
+
For the previous example, to rename `clients` table to `users`, we can run:
|
548
548
|
|
549
549
|
```sql
|
550
550
|
BEGIN;
|
@@ -440,26 +440,22 @@ module OnlineMigrations
|
|
440
440
|
|
441
441
|
migration_name = migration_name.name if migration_name.is_a?(Class)
|
442
442
|
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
)
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
443
|
+
# Can't use `find_or_create_by` or hash syntax here, because it does not correctly work with json `arguments`.
|
444
|
+
existing_migration = Migration.find_by("migration_name = ? AND arguments = ? AND shard IS NULL", migration_name, arguments.to_json)
|
445
|
+
return existing_migration if existing_migration
|
446
|
+
|
447
|
+
Migration.create!(**options, migration_name: migration_name, arguments: arguments, shard: nil) do |migration|
|
448
|
+
shards = Utils.shard_names(migration.migration_model)
|
449
|
+
if shards.size > 1
|
450
|
+
migration.children = shards.map do |shard|
|
451
|
+
child = migration.dup
|
452
|
+
child.shard = shard
|
453
|
+
child
|
454
|
+
end
|
455
|
+
|
456
|
+
migration.composite = true
|
455
457
|
end
|
456
|
-
|
457
|
-
migration.composite = true
|
458
458
|
end
|
459
|
-
|
460
|
-
# This will save all the records using a transaction.
|
461
|
-
migration.save!
|
462
|
-
migration
|
463
459
|
end
|
464
460
|
end
|
465
461
|
end
|
@@ -13,7 +13,7 @@ module OnlineMigrations
|
|
13
13
|
# Runs one background migration job.
|
14
14
|
def run_migration_job
|
15
15
|
raise "Should not be called on a composite (with sharding) migration" if migration.composite?
|
16
|
-
return if migration.cancelled?
|
16
|
+
return if migration.cancelled? || migration.succeeded?
|
17
17
|
|
18
18
|
mark_as_running if migration.enqueued?
|
19
19
|
migration_payload = notifications_payload(migration)
|
@@ -734,7 +734,7 @@ module OnlineMigrations
|
|
734
734
|
# "DROP INDEX CONCURRENTLY" requires a "SHARE UPDATE EXCLUSIVE" lock.
|
735
735
|
# It only conflicts with constraint validations, other creating/removing indexes,
|
736
736
|
# and some "ALTER TABLE"s.
|
737
|
-
super
|
737
|
+
super
|
738
738
|
else
|
739
739
|
OnlineMigrations.deprecator.warn(<<~MSG)
|
740
740
|
Running `remove_index` without a statement timeout is deprecated.
|
@@ -744,7 +744,7 @@ module OnlineMigrations
|
|
744
744
|
MSG
|
745
745
|
|
746
746
|
disable_statement_timeout do
|
747
|
-
super
|
747
|
+
super
|
748
748
|
end
|
749
749
|
end
|
750
750
|
else
|
@@ -773,7 +773,8 @@ module OnlineMigrations
|
|
773
773
|
# @see https://edgeapi.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_foreign_key
|
774
774
|
#
|
775
775
|
def add_foreign_key(from_table, to_table, **options)
|
776
|
-
|
776
|
+
# Do not consider validation for idempotency.
|
777
|
+
if foreign_key_exists?(from_table, to_table, **options.except(:validate))
|
777
778
|
message = +"Foreign key was not created because it already exists " \
|
778
779
|
"(this can be due to an aborted migration or similar): from_table: #{from_table}, to_table: #{to_table}"
|
779
780
|
message << ", #{options.inspect}" if options.any?
|
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.19.
|
4
|
+
version: 0.19.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fatkodima
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|