Skip to content

Commit

Permalink
Merge branch 'master' into feat/simplify-schema-2
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Aug 5, 2018
2 parents e77ae23 + eb70403 commit 19a3355
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 15 deletions.
5 changes: 3 additions & 2 deletions db/migrations/20180720_create_latest_pact_publication_ids.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
# you can't delete a single pact revision through the API - all the revisions
# for a pact are deleted together when you delete the pact resource for that
# consumer version, and when that happens, this row will cascade delete.
create_table(:latest_pact_publication_ids_by_consumer_versions, charset: 'utf8') do

create_table(:latest_pact_publication_ids_for_consumer_versions, charset: 'utf8') do
foreign_key :consumer_id, :pacticipants, null: false, on_delete: :cascade # redundant, but speeds up queries by removing need for extra join
foreign_key :consumer_version_id, :versions, null: false, on_delete: :cascade
foreign_key :provider_id, :pacticipants, null: false, on_delete: :cascade
Expand All @@ -19,6 +20,6 @@
end

down do
drop_table(:latest_pact_publication_ids_by_consumer_versions)
drop_table(:latest_pact_publication_ids_for_consumer_versions)
end
end
4 changes: 2 additions & 2 deletions db/migrations/20180721_migrate_latest_pact_publication_ids.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
up do
# The danger with this migration is that a pact publication created by an old node will be lost
rows = from(:latest_pact_publications_by_consumer_versions).select(:consumer_id, :consumer_version_id, :provider_id, :id, :pact_version_id)
from(:latest_pact_publication_ids_by_consumer_versions).insert(rows)
from(:latest_pact_publication_ids_for_consumer_versions).insert(rows)
end

down do
from(:latest_pact_publication_ids_by_consumer_versions).delete
from(:latest_pact_publication_ids_for_consumer_versions).delete
end
end
6 changes: 3 additions & 3 deletions db/migrations/20180722_recreate_views.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
# Latest pact_publication details for each provider/consumer version
create_or_replace_view(:latest_pact_publications_by_consumer_versions,
"select app.*
from latest_pact_publication_ids_by_consumer_versions lpp
from latest_pact_publication_ids_for_consumer_versions lpp
inner join all_pact_publications app
on lpp.consumer_version_id = app.consumer_version_id
and lpp.pact_publication_id = app.id
and lpp.provider_id = app.provider_id"
)

# Latest consumer version order for consumer/provider
# Recreate latest_pact_publication_ids_by_consumer_versions view
lpp = :latest_pact_publication_ids_by_consumer_versions
# Recreate latest_pact_publication_ids_for_consumer_versions view
lpp = :latest_pact_publication_ids_for_consumer_versions
latest_pact_consumer_version_orders = from(lpp).select_group(
Sequel[lpp][:provider_id],
Sequel[:cv][:pacticipant_id].as(:consumer_id))
Expand Down
2 changes: 1 addition & 1 deletion db/migrations/20180726_recreate_views.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# verifications
create_or_replace_view(:latest_verification_id_for_consumer_version_and_provider_version,
"select pp.consumer_version_id, lv.provider_version_id, lv.verification_id as latest_verification_id
from latest_pact_publication_ids_by_consumer_versions lpp
from latest_pact_publication_ids_for_consumer_versions lpp
inner join pact_publications pp
on pp.id = lpp.pact_publication_id
left outer join latest_verification_id_for_pact_version_and_provider_version lv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
t.name as consumer_version_tag_name,
max(v.verification_id) as latest_verification_id
from latest_verification_id_for_pact_version_and_provider_version v
join latest_pact_publication_ids_by_consumer_versions lpp
join latest_pact_publication_ids_for_consumer_versions lpp
on v.pact_version_id = lpp.pact_version_id
join tags t
on lpp.consumer_version_id = t.version_id
Expand Down
4 changes: 2 additions & 2 deletions lib/pact_broker/domain/pacticipant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def validate
# webhook_executions | webhook_executions_provider_id_fkey | (provider_id) REFERENCES pacticipants(id)
# webhooks | fk_webhooks_consumer | (consumer_id) REFERENCES pacticipants(id)
# webhooks | fk_webhooks_provider | (provider_id) REFERENCES pacticipants(id)
# latest_pact_publication_ids_by_consumer_versions | latest_pact_publication_ids_by_consumer_versio_consumer_id_fkey | (consumer_id) REFERENCES pacticipants(id) ON DELETE CASCADE
# latest_pact_publication_ids_by_consumer_versions | latest_pact_publication_ids_by_consumer_versio_provider_id_fkey | (provider_id) REFERENCES pacticipants(id) ON DELETE CASCADE
# latest_pact_publication_ids_for_consumer_versions | latest_pact_publication_ids_by_consumer_versio_consumer_id_fkey | (consumer_id) REFERENCES pacticipants(id) ON DELETE CASCADE
# latest_pact_publication_ids_for_consumer_versions | latest_pact_publication_ids_by_consumer_versio_provider_id_fkey | (provider_id) REFERENCES pacticipants(id) ON DELETE CASCADE
# latest_verification_id_for_pact_version_and_provider_version | latest_v_id_for_pv_and_pv_consumer_id_fk | (consumer_id) REFERENCES pacticipants(id) ON DELETE CASCADE
# latest_verification_id_for_pact_version_and_provider_version | latest_v_id_for_pv_and_pv_provider_id_fk | (provider_id) REFERENCES pacticipants(id) ON DELETE CASCADE
2 changes: 1 addition & 1 deletion lib/pact_broker/domain/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ def latest_pact_publication
# pact_publications | pact_publications_consumer_version_id_fkey | (consumer_version_id) REFERENCES versions(id)
# verifications | fk_verifications_versions | (provider_version_id) REFERENCES versions(id)
# tags | tags_version_id_fkey | (version_id) REFERENCES versions(id)
# latest_pact_publication_ids_by_consumer_versions | latest_pact_publication_ids_by_consume_consumer_version_id_fkey | (consumer_version_id) REFERENCES versions(id) ON DELETE CASCADE
# latest_pact_publication_ids_for_consumer_versions | latest_pact_publication_ids_by_consume_consumer_version_id_fkey | (consumer_version_id) REFERENCES versions(id) ON DELETE CASCADE
# latest_verification_id_for_pact_version_and_provider_version | latest_v_id_for_pv_and_pv_provider_version_id_fk | (provider_version_id) REFERENCES versions(id) ON DELETE CASCADE
2 changes: 1 addition & 1 deletion lib/pact_broker/pacts/pact_publication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ def cached_domain_for_delegation
# Referenced By:
# triggered_webhooks | triggered_webhooks_pact_publication_id_fkey | (pact_publication_id) REFERENCES pact_publications(id)
# webhook_executions | webhook_executions_pact_publication_id_fkey | (pact_publication_id) REFERENCES pact_publications(id)
# latest_pact_publication_ids_by_consumer_versions | latest_pact_publication_ids_by_consume_pact_publication_id_fkey | (pact_publication_id) REFERENCES pact_publications(id) ON DELETE CASCADE
# latest_pact_publication_ids_for_consumer_versions | latest_pact_publication_ids_by_consume_pact_publication_id_fkey | (pact_publication_id) REFERENCES pact_publications(id) ON DELETE CASCADE
2 changes: 1 addition & 1 deletion lib/pact_broker/pacts/pact_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ def latest_consumer_version_number
# Referenced By:
# pact_publications | pact_publications_pact_version_id_fkey | (pact_version_id) REFERENCES pact_versions(id)
# verifications | verifications_pact_version_id_fkey | (pact_version_id) REFERENCES pact_versions(id)
# latest_pact_publication_ids_by_consumer_versions | latest_pact_publication_ids_by_consumer_ve_pact_version_id_fkey | (pact_version_id) REFERENCES pact_versions(id) ON DELETE CASCADE
# latest_pact_publication_ids_for_consumer_versions | latest_pact_publication_ids_by_consumer_ve_pact_version_id_fkey | (pact_version_id) REFERENCES pact_versions(id) ON DELETE CASCADE
# latest_verification_id_for_pact_version_and_provider_version | latest_v_id_for_pv_and_pv_pact_version_id_fk | (pact_version_id) REFERENCES pact_versions(id) ON DELETE CASCADE
2 changes: 1 addition & 1 deletion lib/pact_broker/pacts/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def update_latest_pact_publication_ids(pact_publication)

row = key.merge(other)

table = AllPactPublications.db[:latest_pact_publication_ids_by_consumer_versions]
table = AllPactPublications.db[:latest_pact_publication_ids_for_consumer_versions]
PactBroker::Repositories::Helpers.upsert(table, key, other)
end

Expand Down

0 comments on commit 19a3355

Please sign in to comment.