From 78d31c49998806e157e0b4c43acb3f2f1bc6abf6 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Mon, 30 Jul 2018 19:39:30 +1000 Subject: [PATCH] feat: move migrations on feature branch to run last --- ... => 20180720_create_latest_pact_publication_ids.rb} | 0 ...=> 20180721_migrate_latest_pact_publication_ids.rb} | 0 ...19_recreate_views.rb => 20180722_recreate_views.rb} | 0 ...s.rb => 20180723_create_latest_verification_ids.rb} | 2 +- ....rb => 20180724_migrate_latest_verification_ids.rb} | 0 ..._latest_verifications_for_consumer_version_tags.rb} | 0 ...23_recreate_views.rb => 20180726_recreate_views.rb} | 5 +++-- ..._latest_verifications_for_consumer_and_provider.rb} | 0 lib/pact_broker/pacts/repository.rb | 9 ++------- lib/pact_broker/verifications/repository.rb | 10 ++-------- 10 files changed, 8 insertions(+), 18 deletions(-) rename db/migrations/{20180517_create_latest_pact_publication_ids.rb => 20180720_create_latest_pact_publication_ids.rb} (100%) rename db/migrations/{20180518_migrate_latest_pact_publication_ids.rb => 20180721_migrate_latest_pact_publication_ids.rb} (100%) rename db/migrations/{20180519_recreate_views.rb => 20180722_recreate_views.rb} (100%) rename db/migrations/{20180521_create_latest_verification_ids.rb => 20180723_create_latest_verification_ids.rb} (94%) rename db/migrations/{20180522_migrate_latest_verification_ids.rb => 20180724_migrate_latest_verification_ids.rb} (100%) rename db/migrations/{20180523_create_latest_verifications_for_consumer_version_tags.rb => 20180725_create_latest_verifications_for_consumer_version_tags.rb} (100%) rename db/migrations/{20180523_recreate_views.rb => 20180726_recreate_views.rb} (94%) rename db/migrations/{20180524_create_latest_verifications_for_consumer_and_provider.rb => 20180727_create_latest_verifications_for_consumer_and_provider.rb} (100%) diff --git a/db/migrations/20180517_create_latest_pact_publication_ids.rb b/db/migrations/20180720_create_latest_pact_publication_ids.rb similarity index 100% rename from db/migrations/20180517_create_latest_pact_publication_ids.rb rename to db/migrations/20180720_create_latest_pact_publication_ids.rb diff --git a/db/migrations/20180518_migrate_latest_pact_publication_ids.rb b/db/migrations/20180721_migrate_latest_pact_publication_ids.rb similarity index 100% rename from db/migrations/20180518_migrate_latest_pact_publication_ids.rb rename to db/migrations/20180721_migrate_latest_pact_publication_ids.rb diff --git a/db/migrations/20180519_recreate_views.rb b/db/migrations/20180722_recreate_views.rb similarity index 100% rename from db/migrations/20180519_recreate_views.rb rename to db/migrations/20180722_recreate_views.rb diff --git a/db/migrations/20180521_create_latest_verification_ids.rb b/db/migrations/20180723_create_latest_verification_ids.rb similarity index 94% rename from db/migrations/20180521_create_latest_verification_ids.rb rename to db/migrations/20180723_create_latest_verification_ids.rb index d4f89e41f..969e3c83d 100644 --- a/db/migrations/20180521_create_latest_verification_ids.rb +++ b/db/migrations/20180723_create_latest_verification_ids.rb @@ -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 diff --git a/db/migrations/20180522_migrate_latest_verification_ids.rb b/db/migrations/20180724_migrate_latest_verification_ids.rb similarity index 100% rename from db/migrations/20180522_migrate_latest_verification_ids.rb rename to db/migrations/20180724_migrate_latest_verification_ids.rb diff --git a/db/migrations/20180523_create_latest_verifications_for_consumer_version_tags.rb b/db/migrations/20180725_create_latest_verifications_for_consumer_version_tags.rb similarity index 100% rename from db/migrations/20180523_create_latest_verifications_for_consumer_version_tags.rb rename to db/migrations/20180725_create_latest_verifications_for_consumer_version_tags.rb diff --git a/db/migrations/20180523_recreate_views.rb b/db/migrations/20180726_recreate_views.rb similarity index 94% rename from db/migrations/20180523_recreate_views.rb rename to db/migrations/20180726_recreate_views.rb index e14fcc928..32266bf56 100644 --- a/db/migrations/20180523_recreate_views.rb +++ b/db/migrations/20180726_recreate_views.rb @@ -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 diff --git a/db/migrations/20180524_create_latest_verifications_for_consumer_and_provider.rb b/db/migrations/20180727_create_latest_verifications_for_consumer_and_provider.rb similarity index 100% rename from db/migrations/20180524_create_latest_verifications_for_consumer_and_provider.rb rename to db/migrations/20180727_create_latest_verifications_for_consumer_and_provider.rb diff --git a/lib/pact_broker/pacts/repository.rb b/lib/pact_broker/pacts/repository.rb index 0466b3081..b4f7cf48d 100644 --- a/lib/pact_broker/pacts/repository.rb +++ b/lib/pact_broker/pacts/repository.rb @@ -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 diff --git a/lib/pact_broker/verifications/repository.rb b/lib/pact_broker/verifications/repository.rb index c47d02ca1..d81371bc3 100644 --- a/lib/pact_broker/verifications/repository.rb +++ b/lib/pact_broker/verifications/repository.rb @@ -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