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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a3658cc979ead6b8dea71140f3ba95b0f7a4a4c26a27891f49a5b6925c94e59
4
- data.tar.gz: 7d3ab5e09422e28078543ac67fa0ecae1a7afe9d8e29f67e55d6b772fb708e50
3
+ metadata.gz: bcbf178b59ac7d856b8b3b44640aa30bd5bb0bc61c334d90925562da1ca23782
4
+ data.tar.gz: 3034174c45f26e4e70a338faa8074bcb4c926160202f6dd85dc43d6ffc5b7101
5
5
  SHA512:
6
- metadata.gz: 43ae3f3ebffa5491d4ac9b99b987b048702b9142e9a4ae49182b705b9c81a562acbea6dc1580ef76e49a9124adf2d662723451b6d03003f10f05c1d39ff4a33e
7
- data.tar.gz: 5793df9ffd71454f2edb251d079439c5dfb0cfe212a30360654cbb5622c23fcd47a63e2a8cdd6b8d4df2bd7d3b39ec4d29eede4a99519264075e65956bdd1b55
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: migration_name).to_a
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
- views = connection.views
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.views.include?(table_name)
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
- views = pool.with_connection(&:views)
135
- table_renames[table_name] if views.include?(table_name)
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) && pool.with_connection(&:views).include?(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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OnlineMigrations
4
- VERSION = "0.27.1"
4
+ VERSION = "0.28.0"
5
5
  end
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.27.1
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-05-08 00:00:00.000000000 Z
11
+ date: 2025-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord