online_migrations 0.27.1 → 0.28.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 +5 -0
- data/lib/generators/online_migrations/templates/initializer.rb.tt +3 -0
- data/lib/online_migrations/background_schema_migrations/migration_helpers.rb +7 -6
- data/lib/online_migrations/schema_cache.rb +13 -7
- 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: bcbf178b59ac7d856b8b3b44640aa30bd5bb0bc61c334d90925562da1ca23782
|
4
|
+
data.tar.gz: 3034174c45f26e4e70a338faa8074bcb4c926160202f6dd85dc43d6ffc5b7101
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 228cbf5deacedaf2017b86a7c6f005c89d454be0fdfe05358d1c33414fa1349cac46fa602901bdb9cf16f2b9bc8f73b6f7e8a935ff754a623182083032d649a4
|
7
|
+
data.tar.gz: 3b05af5c90a084eb64ef0f711e0d9ecb88a0e28d73ae3aa3720bbea525454a63061525aa56c56d251fc8044c6741f9cc94258f6eaf2b1cbd4325c01be86390e7
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
## master (unreleased)
|
2
2
|
|
3
|
+
## 0.28.0 (2025-06-26)
|
4
|
+
|
5
|
+
- Support renaming columns and tables for tables within custom schemas
|
6
|
+
- Include operation name into the background schema migrations names
|
7
|
+
|
3
8
|
## 0.27.1 (2025-05-08)
|
4
9
|
|
5
10
|
- Fix background data migrations to enumerate using the correct shard
|
@@ -110,6 +110,9 @@ OnlineMigrations.configure do |config|
|
|
110
110
|
# The number of seconds that must pass before the cancelling or pausing data migration is considered stuck.
|
111
111
|
config.background_data_migrations.stuck_timeout = 5.minutes
|
112
112
|
|
113
|
+
# The pause interval between each data migration's `process` method execution (in seconds).
|
114
|
+
config.background_data_migrations.iteration_pause = Rails.env.production? ? 0.02 : 0
|
115
|
+
|
113
116
|
# The callback to perform when an error occurs during the data migration.
|
114
117
|
# config.background_data_migrations.error_handler = ->(error, errored_migration) do
|
115
118
|
# Bugsnag.notify(error) do |notification|
|
@@ -28,7 +28,7 @@ module OnlineMigrations
|
|
28
28
|
schema_creation = ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaCreation.new(self)
|
29
29
|
definition = schema_creation.accept(create_index)
|
30
30
|
|
31
|
-
enqueue_background_schema_migration(index.name, table_name, definition: definition, **migration_options)
|
31
|
+
enqueue_background_schema_migration("Add index #{index.name}", table_name, definition: definition, **migration_options)
|
32
32
|
end
|
33
33
|
|
34
34
|
def remove_index_in_background(table_name, column_name = nil, name:, **options)
|
@@ -42,7 +42,7 @@ module OnlineMigrations
|
|
42
42
|
end
|
43
43
|
|
44
44
|
definition = "DROP INDEX CONCURRENTLY IF EXISTS #{quote_column_name(name)}"
|
45
|
-
enqueue_background_schema_migration(name, table_name, definition: definition, **migration_options)
|
45
|
+
enqueue_background_schema_migration("Remove index #{name}", table_name, definition: definition, **migration_options)
|
46
46
|
end
|
47
47
|
|
48
48
|
def validate_foreign_key_in_background(from_table, to_table = nil, **options)
|
@@ -62,7 +62,7 @@ module OnlineMigrations
|
|
62
62
|
ALTER TABLE #{quote_table_name(table_name)}
|
63
63
|
VALIDATE CONSTRAINT #{quote_table_name(constraint_name)}
|
64
64
|
SQL
|
65
|
-
enqueue_background_schema_migration(constraint_name, table_name, definition: definition, **options)
|
65
|
+
enqueue_background_schema_migration("Validate #{constraint_name}", table_name, definition: definition, **options)
|
66
66
|
end
|
67
67
|
|
68
68
|
# Ensures that the background schema migration with the provided migration name succeeded.
|
@@ -78,7 +78,7 @@ module OnlineMigrations
|
|
78
78
|
# ensure_background_schema_migration_succeeded("index_users_on_email")
|
79
79
|
#
|
80
80
|
def ensure_background_schema_migration_succeeded(migration_name)
|
81
|
-
migrations = Migration.where(migration_name
|
81
|
+
migrations = Migration.where("migration_name ILIKE ?", "%#{migration_name}%").to_a
|
82
82
|
|
83
83
|
if migrations.empty?
|
84
84
|
Utils.raise_in_prod_or_say_in_dev("Could not find background schema migration(s): '#{migration_name}'.")
|
@@ -97,12 +97,13 @@ module OnlineMigrations
|
|
97
97
|
if connection_class_name
|
98
98
|
klass = connection_class_name.constantize
|
99
99
|
connection_class = Utils.find_connection_class(klass)
|
100
|
-
# Normalize to the real connection class name.
|
101
|
-
connection_class_name = connection_class.name
|
102
100
|
else
|
103
101
|
connection_class = ActiveRecord::Base
|
104
102
|
end
|
105
103
|
|
104
|
+
# Normalize to the real connection class name.
|
105
|
+
connection_class_name = connection_class.name
|
106
|
+
|
106
107
|
shards = Utils.shard_names(connection_class)
|
107
108
|
shards = [nil] if shards.size == 1
|
108
109
|
|
@@ -52,15 +52,14 @@ module OnlineMigrations
|
|
52
52
|
private
|
53
53
|
def renamed_table?(connection, table_name)
|
54
54
|
table_renames = OnlineMigrations.config.table_renames
|
55
|
-
if table_renames.key?(table_name)
|
56
|
-
|
57
|
-
table_renames[table_name] if views.include?(table_name)
|
55
|
+
if table_renames.key?(table_name) && connection.view_exists?(table_name)
|
56
|
+
table_renames[table_name]
|
58
57
|
end
|
59
58
|
end
|
60
59
|
|
61
60
|
def renamed_column?(connection, table_name)
|
62
61
|
column_renames = OnlineMigrations.config.column_renames
|
63
|
-
column_renames.key?(table_name) && connection.
|
62
|
+
column_renames.key?(table_name) && connection.view_exists?(table_name)
|
64
63
|
end
|
65
64
|
|
66
65
|
def column_rename_table(table_name)
|
@@ -131,14 +130,21 @@ module OnlineMigrations
|
|
131
130
|
def renamed_table?(pool, table_name)
|
132
131
|
table_renames = OnlineMigrations.config.table_renames
|
133
132
|
if table_renames.key?(table_name)
|
134
|
-
|
135
|
-
|
133
|
+
view_exists = pool.with_connection do |connection|
|
134
|
+
connection.view_exists?(table_name)
|
135
|
+
end
|
136
|
+
|
137
|
+
table_renames[table_name] if view_exists
|
136
138
|
end
|
137
139
|
end
|
138
140
|
|
139
141
|
def renamed_column?(pool, table_name)
|
140
142
|
column_renames = OnlineMigrations.config.column_renames
|
141
|
-
column_renames.key?(table_name)
|
143
|
+
return false if !column_renames.key?(table_name)
|
144
|
+
|
145
|
+
pool.with_connection do |connection|
|
146
|
+
connection.view_exists?(table_name)
|
147
|
+
end
|
142
148
|
end
|
143
149
|
|
144
150
|
def column_rename_table(table_name)
|
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.
|
4
|
+
version: 0.28.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fatkodima
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|