Skip to content

Commit

Permalink
feat: add more logging to data migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Phanindra Srungavarapu authored and Phanindra Srungavarapu committed Sep 16, 2024
1 parent 7eb80ee commit 5dc023b
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 16 deletions.
39 changes: 23 additions & 16 deletions lib/pact_broker/db/migrate_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,30 @@
module PactBroker
module DB
class MigrateData
include PactBroker::Logging

def self.call database_connection, _options = {}
DataMigrations::SetPacticipantIdsForVerifications.call(database_connection)
DataMigrations::SetConsumerIdsForPactPublications.call(database_connection)
DataMigrations::SetLatestVersionSequenceValue.call(database_connection)
DataMigrations::SetWebhooksEnabled.call(database_connection)
DataMigrations::DeleteDeprecatedWebhookExecutions.call(database_connection)
DataMigrations::SetCreatedAtForLatestPactPublications.call(database_connection)
DataMigrations::SetCreatedAtForLatestVerifications.call(database_connection)
DataMigrations::SetExtraColumnsForTags.call(database_connection)
DataMigrations::SetPacticipantDisplayName.call(database_connection)
DataMigrations::SetWebhookUuid.call(database_connection)
DataMigrations::SetConsumerVersionOrderForPactPublications.call(database_connection)
DataMigrations::SetExtraColumnsForTags.call(database_connection)
DataMigrations::CreateBranches.call(database_connection)
DataMigrations::MigrateIntegrations.call(database_connection)
DataMigrations::MigratePactVersionProviderTagSuccessfulVerifications.call(database_connection)
DataMigrations::SetContractDataUpdatedAtForIntegrations.call(database_connection)
[
DataMigrations::SetPacticipantIdsForVerifications,
DataMigrations::SetConsumerIdsForPactPublications,
DataMigrations::SetLatestVersionSequenceValue,
DataMigrations::SetWebhooksEnabled,
DataMigrations::DeleteDeprecatedWebhookExecutions,
DataMigrations::SetCreatedAtForLatestPactPublications,
DataMigrations::SetCreatedAtForLatestVerifications,
DataMigrations::SetExtraColumnsForTags,
DataMigrations::SetPacticipantDisplayName,
DataMigrations::SetWebhookUuid,
DataMigrations::SetConsumerVersionOrderForPactPublications,
DataMigrations::SetInteractionsCounts,
DataMigrations::CreateBranches,
DataMigrations::MigrateIntegrations,
DataMigrations::MigratePactVersionProviderTagSuccessfulVerifications,
DataMigrations::SetContractDataUpdatedAtForIntegrations
].each do | migration |
logger.debug "Running data migration #{migration.class}"
migration.call(database_connection)
end
end
end
end
Expand Down
59 changes: 59 additions & 0 deletions spec/lib/pact_broker/db/migrate_data_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require 'pact_broker/db/migrate_data'

RSpec.describe PactBroker::DB::MigrateData do
let(:database_connection) { double('Database Connection') }
let(:options) { {} }
let(:debug) { double('debug', debug: nil) }

before do
allow(PactBroker::DB::MigrateData).to receive(:logger).and_return(double('logger', debug: debug))
[
PactBroker::DB::DataMigrations::SetPacticipantIdsForVerifications,
PactBroker::DB::DataMigrations::SetConsumerIdsForPactPublications,
PactBroker::DB::DataMigrations::SetLatestVersionSequenceValue,
PactBroker::DB::DataMigrations::SetWebhooksEnabled,
PactBroker::DB::DataMigrations::DeleteDeprecatedWebhookExecutions,
PactBroker::DB::DataMigrations::SetCreatedAtForLatestPactPublications,
PactBroker::DB::DataMigrations::SetCreatedAtForLatestVerifications,
PactBroker::DB::DataMigrations::SetExtraColumnsForTags,
PactBroker::DB::DataMigrations::SetPacticipantDisplayName,
PactBroker::DB::DataMigrations::SetWebhookUuid,
PactBroker::DB::DataMigrations::SetConsumerVersionOrderForPactPublications,
PactBroker::DB::DataMigrations::SetInteractionsCounts,
PactBroker::DB::DataMigrations::CreateBranches,
PactBroker::DB::DataMigrations::MigrateIntegrations,
PactBroker::DB::DataMigrations::MigratePactVersionProviderTagSuccessfulVerifications,
PactBroker::DB::DataMigrations::SetContractDataUpdatedAtForIntegrations
].each do |migration|
allow(migration).to receive(:call)
end
end

describe '.call' do
it 'calls each data migration with the correct database connection' do
described_class.call(database_connection, options)

[
PactBroker::DB::DataMigrations::SetPacticipantIdsForVerifications,
PactBroker::DB::DataMigrations::SetConsumerIdsForPactPublications,
PactBroker::DB::DataMigrations::SetLatestVersionSequenceValue,
PactBroker::DB::DataMigrations::SetWebhooksEnabled,
PactBroker::DB::DataMigrations::DeleteDeprecatedWebhookExecutions,
PactBroker::DB::DataMigrations::SetCreatedAtForLatestPactPublications,
PactBroker::DB::DataMigrations::SetCreatedAtForLatestVerifications,
PactBroker::DB::DataMigrations::SetExtraColumnsForTags,
PactBroker::DB::DataMigrations::SetPacticipantDisplayName,
PactBroker::DB::DataMigrations::SetWebhookUuid,
PactBroker::DB::DataMigrations::SetConsumerVersionOrderForPactPublications,
PactBroker::DB::DataMigrations::SetInteractionsCounts,
PactBroker::DB::DataMigrations::CreateBranches,
PactBroker::DB::DataMigrations::MigrateIntegrations,
PactBroker::DB::DataMigrations::MigratePactVersionProviderTagSuccessfulVerifications,
PactBroker::DB::DataMigrations::SetContractDataUpdatedAtForIntegrations
].each do |migration|
expect(migration).to have_received(:call).with(database_connection)
#expect(debug).to have_received(:debug).with("Running data migration #{migration}")
end
end
end
end

0 comments on commit 5dc023b

Please sign in to comment.