-
-
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.
Merge branch 'feat/simplify-schema-2'
- Loading branch information
Showing
51 changed files
with
570 additions
and
391 deletions.
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
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
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,3 @@ | ||
Dir.glob(File.expand_path(File.join(__FILE__, "..", "ddl_statements", "*.rb"))).sort.each do | path | | ||
require path | ||
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,31 @@ | ||
HEAD_MATRIX_V1 = " | ||
select | ||
p.consumer_id, p.consumer_name, p.consumer_version_id, p.consumer_version_number, p.consumer_version_order, | ||
p.id as pact_publication_id, p.pact_version_id, p.pact_version_sha, p.revision_number as pact_revision_number, | ||
p.created_at as pact_created_at, | ||
p.provider_id, p.provider_name, lv.provider_version_id, lv.provider_version_number, lv.provider_version_order, | ||
lv.id as verification_id, lv.success, lv.number as verification_number, lv.execution_date as verification_executed_at, | ||
lv.build_url as verification_build_url, | ||
null as consumer_version_tag_name | ||
from latest_pact_publications p | ||
left outer join latest_verifications lv | ||
on p.pact_version_id = lv.pact_version_id | ||
union all | ||
select | ||
p.consumer_id, p.consumer_name, p.consumer_version_id, p.consumer_version_number, p.consumer_version_order, | ||
p.id as pact_publication_id, p.pact_version_id, p.pact_version_sha, p.revision_number as pact_revision_number, | ||
p.created_at as pact_created_at, | ||
p.provider_id, p.provider_name, lv.provider_version_id, lv.provider_version_number, lv.provider_version_order, | ||
lv.id as verification_id, lv.success, lv.number as verification_number, lv.execution_date as verification_executed_at, | ||
lv.build_url as verification_build_url, | ||
lt.tag_name as consumer_version_tag_name | ||
from latest_tagged_pact_consumer_version_orders lt | ||
inner join latest_pact_publications_by_consumer_versions p | ||
on lt.consumer_id = p.consumer_id | ||
and lt.provider_id = p.provider_id | ||
and lt.latest_consumer_version_order = p.consumer_version_order | ||
left outer join latest_verifications lv | ||
on p.pact_version_id = lv.pact_version_id | ||
" |
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,31 @@ | ||
HEAD_MATRIX_V2 = " | ||
select | ||
p.consumer_id, p.consumer_name, p.consumer_version_id, p.consumer_version_number, p.consumer_version_order, | ||
p.id as pact_publication_id, p.pact_version_id, p.pact_version_sha, p.revision_number as pact_revision_number, | ||
p.created_at as pact_created_at, | ||
p.provider_id, p.provider_name, lv.provider_version_id, lv.provider_version_number, lv.provider_version_order, | ||
lv.id as verification_id, lv.success, lv.number as verification_number, lv.execution_date as verification_executed_at, | ||
lv.build_url as verification_build_url, | ||
null as consumer_version_tag_name | ||
from latest_pact_publications p | ||
left outer join latest_verifications_for_pact_versions lv | ||
on p.pact_version_id = lv.pact_version_id | ||
union all | ||
select | ||
p.consumer_id, p.consumer_name, p.consumer_version_id, p.consumer_version_number, p.consumer_version_order, | ||
p.id as pact_publication_id, p.pact_version_id, p.pact_version_sha, p.revision_number as pact_revision_number, | ||
p.created_at as pact_created_at, | ||
p.provider_id, p.provider_name, lv.provider_version_id, lv.provider_version_number, lv.provider_version_order, | ||
lv.id as verification_id, lv.success, lv.number as verification_number, lv.execution_date as verification_executed_at, | ||
lv.build_url as verification_build_url, | ||
lt.tag_name as consumer_version_tag_name | ||
from latest_tagged_pact_consumer_version_orders lt | ||
inner join latest_pact_publications_by_consumer_versions p | ||
on lt.consumer_id = p.consumer_id | ||
and lt.provider_id = p.provider_id | ||
and lt.latest_consumer_version_order = p.consumer_version_order | ||
left outer join latest_verifications_for_pact_versions lv | ||
on p.pact_version_id = lv.pact_version_id | ||
" |
4 changes: 4 additions & 0 deletions
4
db/ddl_statements/latest_verification_ids_for_pact_versions_v001.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,4 @@ | ||
LATEST_VERIFICATION_IDS_FOR_PACT_VERSIONS_V1 = | ||
"select pact_version_id, MAX(verification_id) latest_verification_id | ||
FROM latest_verification_id_for_pact_version_and_provider_version | ||
GROUP BY pact_version_id" |
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
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
2 changes: 2 additions & 0 deletions
2
db/migrations/20180523_create_latest_verifications_for_consumer_version_tags.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
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
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
11 changes: 11 additions & 0 deletions
11
db/migrations/20180721_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_id, :consumer_version_id, :provider_id, :id, :pact_version_id) | ||
from(:latest_pact_publication_ids_for_consumer_versions).insert(rows) | ||
end | ||
|
||
down do | ||
from(:latest_pact_publication_ids_for_consumer_versions).delete | ||
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_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_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)) | ||
.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 |
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,23 @@ | ||
Sequel.migration do | ||
up do | ||
# Latest verification_id for each pact version/provider version. | ||
# Keeping track of this in a table rather than having to calculate the | ||
# latest revision speeds queries up. | ||
# There is no way to delete an individual verification result yet, but when there | ||
# is, we'll need to re-calculate the latest. | ||
create_table(:latest_verification_id_for_pact_version_and_provider_version, charset: 'utf8') do | ||
foreign_key :consumer_id, :pacticipants, null: false, on_delete: :cascade, foreign_key_constraint_name: 'latest_v_id_for_pv_and_pv_consumer_id_fk' # not required, but useful to avoid extra joins | ||
foreign_key :pact_version_id, :pact_versions, null: false, on_delete: :cascade, foreign_key_constraint_name: 'latest_v_id_for_pv_and_pv_pact_version_id_fk' | ||
foreign_key :provider_id, :pacticipants, null: false, on_delete: :cascade, foreign_key_constraint_name: 'latest_v_id_for_pv_and_pv_provider_id_fk' # not required, but useful to avoid extra joins | ||
foreign_key :provider_version_id, :versions, null: false, on_delete: :cascade, foreign_key_constraint_name: 'latest_v_id_for_pv_and_pv_provider_version_id_fk' | ||
foreign_key :verification_id, :verifications, null: false, on_delete: :cascade, foreign_key_constraint_name: 'latest_v_id_for_pv_and_pv_verification_id_fk' | ||
index [:verification_id], unique: true, name: "latest_v_id_for_pv_and_pv_v_id_unq" | ||
index [:pact_version_id, :provider_version_id], unique: true, name: "latest_v_id_for_pv_and_pv_pv_id_pv_id_unq" | ||
index [:pact_version_id, :verification_id], name: "latest_v_id_for_pv_and_pv_pv_id_v_id" | ||
end | ||
end | ||
|
||
down do | ||
drop_table(:latest_verification_id_for_pact_version_and_provider_version) | ||
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,18 @@ | ||
Sequel.migration do | ||
up do | ||
# consumer_id and provider_id are redundant by avoid making extra joins when creating views | ||
rows = from(:verifications).select_group( | ||
Sequel[:verifications][:consumer_id], | ||
Sequel[:verifications][:pact_version_id], | ||
Sequel[:verifications][:provider_id], | ||
Sequel[:verifications][:provider_version_id]) | ||
.select_append{ max(verifications[id]).as(verification_id) } | ||
|
||
# The danger with this migration is that a verification created by an old node will be lost | ||
from(:latest_verification_id_for_pact_version_and_provider_version).insert(rows) | ||
end | ||
|
||
down do | ||
from(:latest_verification_id_for_pact_version_and_provider_version).delete | ||
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,29 @@ | ||
Sequel.migration do | ||
up do | ||
# joining with latest_pact_publication_revision_numbers gets rid of the overwritten | ||
# pact revisions, and the max(verification_id) gets rid of the overwritten | ||
# 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_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 | ||
on lv.pact_version_id = pp.pact_version_id" | ||
) | ||
end | ||
|
||
down do | ||
create_or_replace_view(:latest_verification_id_for_consumer_version_and_provider_version, | ||
"select consumer_version_id, provider_version_id, max(verification_id) as latest_verification_id | ||
from matrix | ||
inner join latest_pact_publication_revision_numbers lr | ||
on matrix.consumer_id = lr.consumer_id | ||
and matrix.provider_id = lr.provider_id | ||
and matrix.consumer_version_order = lr.consumer_version_order | ||
and matrix.pact_revision_number = lr.latest_revision_number | ||
group by consumer_version_id, provider_version_id" | ||
) | ||
|
||
end | ||
end |
Oops, something went wrong.