Commit 4f727ada authored by Alex Kalderimis's avatar Alex Kalderimis

Fix migration by handling empty result sets

parent 8acc5d32
...@@ -8,7 +8,7 @@ class EncryptIntegrationProperties < Gitlab::Database::Migration[1.0] ...@@ -8,7 +8,7 @@ class EncryptIntegrationProperties < Gitlab::Database::Migration[1.0]
def up def up
queue_background_migration_jobs_by_range_at_intervals( queue_background_migration_jobs_by_range_at_intervals(
define_batchable_model('integrations'), define_batchable_model('integrations').all,
MIGRATION, MIGRATION,
INTERVAL, INTERVAL,
track_jobs: true, track_jobs: true,
......
...@@ -64,6 +64,8 @@ module Gitlab ...@@ -64,6 +64,8 @@ module Gitlab
"(#{record.id}, #{bytea(encrypted_properties)}, #{bytea(encrypted_properties_iv)})" "(#{record.id}, #{bytea(encrypted_properties)}, #{bytea(encrypted_properties_iv)})"
end end
return if values.empty?
Integration.connection.execute(<<~SQL.squish) Integration.connection.execute(<<~SQL.squish)
WITH cte(cte_id, cte_encrypted_properties, cte_encrypted_properties_iv) WITH cte(cte_id, cte_encrypted_properties, cte_encrypted_properties_iv)
AS #{::Gitlab::Database::AsWithMaterialized.materialized_if_supported} ( AS #{::Gitlab::Database::AsWithMaterialized.materialized_if_supported} (
......
...@@ -18,18 +18,18 @@ RSpec.describe EncryptIntegrationProperties, :migration, schema: 20220204193000 ...@@ -18,18 +18,18 @@ RSpec.describe EncryptIntegrationProperties, :migration, schema: 20220204193000
record1 = integrations.create!(properties: some_props) record1 = integrations.create!(properties: some_props)
record2 = integrations.create!(properties: some_props) record2 = integrations.create!(properties: some_props)
record3 = integrations.create!(properties: some_props) record3 = integrations.create!(properties: some_props)
record4 = integrations.create!(properties: nil)
# no update required record5 = integrations.create!(properties: nil)
integrations.create!(properties: nil)
Sidekiq::Testing.fake! do Sidekiq::Testing.fake! do
freeze_time do freeze_time do
migrate! migrate!
expect(described_class::MIGRATION).to be_scheduled_migration(record1.id, record2.id) expect(described_class::MIGRATION).to be_scheduled_migration(record1.id, record2.id)
expect(described_class::MIGRATION).to be_scheduled_migration(record3.id, record3.id) expect(described_class::MIGRATION).to be_scheduled_migration(record3.id, record4.id)
expect(described_class::MIGRATION).to be_scheduled_migration(record5.id, record5.id)
expect(BackgroundMigrationWorker.jobs.size).to eq(2) expect(BackgroundMigrationWorker.jobs.size).to eq(3)
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment