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]
def up
queue_background_migration_jobs_by_range_at_intervals(
define_batchable_model('integrations'),
define_batchable_model('integrations').all,
MIGRATION,
INTERVAL,
track_jobs: true,
......
......@@ -64,6 +64,8 @@ module Gitlab
"(#{record.id}, #{bytea(encrypted_properties)}, #{bytea(encrypted_properties_iv)})"
end
return if values.empty?
Integration.connection.execute(<<~SQL.squish)
WITH cte(cte_id, cte_encrypted_properties, cte_encrypted_properties_iv)
AS #{::Gitlab::Database::AsWithMaterialized.materialized_if_supported} (
......
......@@ -18,18 +18,18 @@ RSpec.describe EncryptIntegrationProperties, :migration, schema: 20220204193000
record1 = integrations.create!(properties: some_props)
record2 = integrations.create!(properties: some_props)
record3 = integrations.create!(properties: some_props)
# no update required
integrations.create!(properties: nil)
record4 = integrations.create!(properties: nil)
record5 = integrations.create!(properties: nil)
Sidekiq::Testing.fake! do
freeze_time do
migrate!
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
......
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