-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: keep track of latest pact revision in table rather than calcula…
…ting it
- Loading branch information
Showing
4 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
db/migrations/20180517_create_latest_pact_publication_ids.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Sequel.migration do | ||
up do | ||
# Latest pact_publication (revision) for each provider/consumer version. | ||
# Keeping track of this in a table rather than having to calculate the | ||
# latest revision speeds things up. | ||
# We don't have to worry about updating it if a revision is deleted, because | ||
# you can't delete a single 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 | ||
foreign_key :consumer_version_id, :versions, nil: false, on_delete: :cascade | ||
foreign_key :provider_id, :pacticipants, nil: false, on_delete: :cascade | ||
foreign_key :pact_publication_id, :pact_publications, nil: false, on_delete: :cascade | ||
index [:provider_id, :consumer_version_id], unique: true, name: "unq_latest_ppid_prov_conver" | ||
end | ||
end | ||
|
||
down do | ||
drop_table(:latest_pact_publication_ids_by_consumer_versions) | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
db/migrations/20180518_migrate_latest_pact_publication_ids.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Sequel.migration do | ||
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_version_id, :provider_id, :id) | ||
from(:latest_pact_publication_ids_by_consumer_versions).insert(rows) | ||
end | ||
|
||
down do | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Sequel.migration do | ||
up do | ||
# 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 | ||
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 | ||
latest_pact_consumer_version_orders = from(lpp).select_group( | ||
Sequel[lpp][:provider_id], | ||
Sequel[:cv][:pacticipant_id].as(:consumer_id)) | ||
.select_append{ max(order).as(latest_consumer_version_order) } | ||
.join(:versions, { Sequel[lpp][:consumer_version_id] => Sequel[:cv][:id] }, { table_alias: :cv }) | ||
|
||
create_or_replace_view(:latest_pact_consumer_version_orders, latest_pact_consumer_version_orders) | ||
end | ||
|
||
down do | ||
# Latest pact_publication details for each provider/consumer version | ||
create_or_replace_view(:latest_pact_publications_by_consumer_versions, | ||
"select app.* | ||
from all_pact_publications app | ||
inner join latest_pact_publication_revision_numbers lr | ||
on app.consumer_id = lr.consumer_id | ||
and app.provider_id = lr.provider_id | ||
and app.consumer_version_order = lr.consumer_version_order | ||
and app.revision_number = lr.latest_revision_number" | ||
) | ||
|
||
create_or_replace_view(:latest_pact_consumer_version_orders, | ||
"select provider_id, consumer_id, max(consumer_version_order) as latest_consumer_version_order | ||
from all_pact_publications | ||
group by provider_id, consumer_id" | ||
) | ||
end | ||
end |