Skip to content

Commit

Permalink
feat: move migrations on feature branch to run last
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jul 30, 2018
1 parent 262af75 commit 78d31c4
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 18 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
create_table(:latest_verification_id_for_pact_version_and_provider_version, charset: 'utf8') do
foreign_key :pact_version_id, :pact_versions, nil: false, on_delete: :cascade
foreign_key :provider_version_id, :versions, nil: false, on_delete: :cascade
foreign_key :provider_id, :pacticipants, nil: false, on_delete: :cascade
foreign_key :provider_id, :pacticipants, nil: false, on_delete: :cascade # not required, but useful to avoid extra joins
foreign_key :verification_id, :verifications, nil: false, on_delete: :cascade, unique: true
index [:pact_version_id, :provider_version_id], unique: true, name: "unq_latest_verifid_pvid_provid"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
on lv.pact_version_id = pp.pact_version_id"
)

#TODO
# TODO
#drop_view(:latest_matrix)
#drop_view(:latest_verification_id_for_consumer_version_and_provider)
#drop_view(:latest_matrix_for_consumer_version_and_provider_version)

#drop_table(:materialized_matrix)
#drop_table(:materialized_head_matrix)
end

down do
Expand Down
9 changes: 2 additions & 7 deletions lib/pact_broker/pacts/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,8 @@ def update id, params
end

def update_latest_pact_publication_ids(pact_publication)
table = AllPactPublications.db[:latest_pact_publication_ids_by_consumer_versions]
count = table.where(consumer_version_id: pact_publication.consumer_version_id, provider_id: pact_publication.provider_id).count
if count == 0
table.insert(consumer_version_id: pact_publication.consumer_version_id, provider_id: pact_publication.provider_id, pact_publication_id: pact_publication.id)
else
table.where(consumer_version_id: pact_publication.consumer_version_id, provider_id: pact_publication.provider_id).update(pact_publication_id: pact_publication.id)
end
latest_pact_publication_params = { consumer_version_id: pact_publication.consumer_version_id, provider_id: pact_publication.provider_id, pact_publication_id: pact_publication.id }
AllPactPublications.db[:latest_pact_publication_ids_by_consumer_versions].insert_ignore.insert(latest_pact_publication_params)
end

def delete params
Expand Down
10 changes: 2 additions & 8 deletions lib/pact_broker/verifications/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,8 @@ def create verification, provider_version_number, pact
end

def update_latest_verification_id verification
if PactBroker::Domain::Verification.db.table_exists?(:latest_verification_id_for_pact_version_and_provider_version)
table = PactBroker::Domain::Verification.db[:latest_verification_id_for_pact_version_and_provider_version]
if table.where(pact_version_id: verification.pact_version_id, provider_version_id: verification.provider_version_id).count == 0
table.insert(pact_version_id: verification.pact_version_id, provider_version_id: verification.provider_version_id, provider_id: verification.provider_version.pacticipant_id, verification_id: verification.id)
else
table.where(pact_version_id: verification.pact_version_id, provider_version_id: verification.provider_version_id).update(verification_id: verification.id)
end
end
latest_verification_params = { pact_version_id: verification.pact_version_id, provider_version_id: verification.provider_version_id, provider_id: verification.provider_version.pacticipant_id, verification_id: verification.id }
PactBroker::Domain::Verification.db[:latest_verification_id_for_pact_version_and_provider_version].insert_ignore.insert(latest_verification_params)
end

def find consumer_name, provider_name, pact_version_sha, verification_number
Expand Down

0 comments on commit 78d31c4

Please sign in to comment.