Skip to content

Commit

Permalink
feat: replace latest_verifications view with latest_verifications_for…
Browse files Browse the repository at this point in the history
…_provider_versions
  • Loading branch information
bethesque committed Aug 5, 2018
1 parent 38e3019 commit ee4fef9
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 41 deletions.
3 changes: 3 additions & 0 deletions db/ddl_statements.rb
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
31 changes: 31 additions & 0 deletions db/ddl_statements/head_matrix_v001.rb
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
"
31 changes: 31 additions & 0 deletions db/ddl_statements/head_matrix_v002.rb
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_provider_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_provider_versions lv
on p.pact_version_id = lv.pact_version_id
"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
LATEST_VERIFICATION_IDS_FOR_PROVIDER_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"
35 changes: 2 additions & 33 deletions db/migrations/20180311_optimise_head_matrix.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require_relative 'migration_helper'
require_relative '../ddl_statements'

Sequel.migration do
up do
Expand Down Expand Up @@ -46,38 +47,6 @@
)


create_or_replace_view(:head_matrix,
"
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
"
)
create_or_replace_view(:head_matrix, HEAD_MATRIX_V1)
end
end
3 changes: 2 additions & 1 deletion db/migrations/20180723_create_latest_verification_ids.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
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: "unq_latest_verifid_pvid_provid"
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

Expand Down
7 changes: 0 additions & 7 deletions db/migrations/20180726_recreate_views.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
left outer join latest_verification_id_for_pact_version_and_provider_version lv
on lv.pact_version_id = pp.pact_version_id"
)

# 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
20 changes: 20 additions & 0 deletions db/migrations/20180728_truncate_materialized_matrix_tables.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Sequel.migration do
up do
from(:materialized_matrix).delete
from(:materialized_head_matrix).delete

# 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
from(:materialized_matrix).delete
from(:materialized_matrix).insert(from(:matrix).select_all)
from(:materialized_head_matrix).delete
from(:materialized_head_matrix).insert(from(:head_matrix).select_all)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require_relative '../ddl_statements'

Sequel.migration do
change do
create_view(:latest_verification_ids_for_provider_versions,
LATEST_VERIFICATION_IDS_FOR_PROVIDER_VERSIONS_V1)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Sequel.migration do
change do
# The most recent verification for each pact_version
v = :verifications
create_view(:latest_verifications_for_provider_versions,
from(v)
.select(
Sequel[v][:id],
Sequel[v][:number],
Sequel[v][:success],
Sequel[v][:build_url],
Sequel[v][:pact_version_id],
Sequel[v][:execution_date],
Sequel[v][:created_at],
Sequel[v][:provider_version_id],
Sequel[:s][:number].as(:provider_version_number),
Sequel[:s][:order].as(:provider_version_order))
.join(:latest_verification_ids_for_provider_versions,
{
Sequel[v][:pact_version_id] => Sequel[:lv][:pact_version_id],
Sequel[v][:id] => Sequel[:lv][:latest_verification_id]
}, { table_alias: :lv })
.join(:versions,
{
Sequel[v][:provider_version_id] => Sequel[:s][:id]
}, { table_alias: :s })
)
end
end
11 changes: 11 additions & 0 deletions db/migrations/20180731_update_head_matrix.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Sequel.migration do
up do
create_or_replace_view(:head_matrix, HEAD_MATRIX_V2)
#TODO
#drop_view(:latest_verifications)
end

down do
create_or_replace_view(:head_matrix, HEAD_MATRIX_V1)
end
end
Binary file modified db/pact_broker_database.sqlite3
Binary file not shown.

0 comments on commit ee4fef9

Please sign in to comment.