diff --git a/lib/pact_broker/db/data_migrations/set_consumer_ids_for_pact_publications.rb b/lib/pact_broker/db/data_migrations/set_consumer_ids_for_pact_publications.rb index a15c493d6..e0af2f760 100644 --- a/lib/pact_broker/db/data_migrations/set_consumer_ids_for_pact_publications.rb +++ b/lib/pact_broker/db/data_migrations/set_consumer_ids_for_pact_publications.rb @@ -4,14 +4,12 @@ module DataMigrations class SetConsumerIdsForPactPublications def self.call connection if columns_exist?(connection) - ids = connection.from(:pact_publications) - .select(Sequel[:pact_publications][:id], Sequel[:versions][:pacticipant_id].as(:consumer_id)) - .join(:versions, {id: :consumer_version_id}) - .where(Sequel[:pact_publications][:consumer_id] => nil) - - ids.each do | id | - connection.from(:pact_publications).where(id: id[:id]).update(consumer_id: id[:consumer_id]) - end + query = "UPDATE pact_publications + SET consumer_id = (SELECT consumer_id + FROM versions + WHERE id = pact_publications.consumer_version_id) + WHERE consumer_id is null" + connection.run(query) end end diff --git a/lib/pact_broker/db/data_migrations/set_pacticipant_ids_for_verifications.rb b/lib/pact_broker/db/data_migrations/set_pacticipant_ids_for_verifications.rb index 64066e5e5..dd52ca397 100644 --- a/lib/pact_broker/db/data_migrations/set_pacticipant_ids_for_verifications.rb +++ b/lib/pact_broker/db/data_migrations/set_pacticipant_ids_for_verifications.rb @@ -4,15 +4,16 @@ module DataMigrations class SetPacticipantIdsForVerifications def self.call connection if columns_exist?(connection) - ids = connection.from(:verifications) - .select(Sequel[:verifications][:id], Sequel[:pact_versions][:consumer_id], Sequel[:pact_versions][:provider_id]) - .join(:pact_versions, {id: :provider_version_id}) - .where(Sequel[:verifications][:consumer_id] => nil) - .or(Sequel[:verifications][:provider_id] => nil) - - ids.each do | id | - connection.from(:verifications).where(id: id[:id]).update(consumer_id: id[:consumer_id], provider_id: id[:provider_id]) - end + query = "UPDATE verifications + SET consumer_id = (SELECT consumer_id + FROM pact_versions + WHERE id = verifications.pact_version_id), + provider_id = (SELECT provider_id + FROM pact_versions + WHERE id = verifications.pact_version_id) + WHERE consumer_id is null + OR provider_id is null" + connection.run(query) end end