From 9bc1eab1207b30c484423c78a4fb601fe95ecd64 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Mon, 9 Sep 2019 12:33:25 +1000 Subject: [PATCH] fix: add test results to all verifications views --- ...9_add_test_results_to_all_verifications.rb | 36 +++++++++++ ...dd_test_results_to_latest_verifications.rb | 61 +++++++++++++++++++ ..._latest_verifications_for_pact_versions.rb | 58 ++++++++++++++++++ .../verifications/all_verifications.rb | 1 + .../latest_verification_for_pact_version.rb | 1 + 5 files changed, 157 insertions(+) create mode 100644 db/migrations/20190909_add_test_results_to_all_verifications.rb create mode 100644 db/migrations/20190910_add_test_results_to_latest_verifications.rb create mode 100644 db/migrations/20190911_add_test_results_to_latest_verifications_for_pact_versions.rb diff --git a/db/migrations/20190909_add_test_results_to_all_verifications.rb b/db/migrations/20190909_add_test_results_to_all_verifications.rb new file mode 100644 index 000000000..92a5b4415 --- /dev/null +++ b/db/migrations/20190909_add_test_results_to_all_verifications.rb @@ -0,0 +1,36 @@ +Sequel.migration do + up do + create_or_replace_view(:all_verifications, + from(:verifications).select( + Sequel[:verifications][:id], + Sequel[:verifications][:number], + :success, + :provider_version_id, + Sequel[:v][:number].as(:provider_version_number), + Sequel[:v][:order].as(:provider_version_order), + :build_url, + :pact_version_id, + :execution_date, + Sequel[:verifications][:created_at], + :test_results + ).join(:versions, {id: :provider_version_id}, {:table_alias => :v}) + ) + end + + down do + create_or_replace_view(:all_verifications, + from(:verifications).select( + Sequel[:verifications][:id], + Sequel[:verifications][:number], + :success, + :provider_version_id, + Sequel[:v][:number].as(:provider_version_number), + Sequel[:v][:order].as(:provider_version_order), + :build_url, + :pact_version_id, + :execution_date, + Sequel[:verifications][:created_at] + ).join(:versions, {id: :provider_version_id}, {:table_alias => :v}) + ) + end +end diff --git a/db/migrations/20190910_add_test_results_to_latest_verifications.rb b/db/migrations/20190910_add_test_results_to_latest_verifications.rb new file mode 100644 index 000000000..6ad780fe8 --- /dev/null +++ b/db/migrations/20190910_add_test_results_to_latest_verifications.rb @@ -0,0 +1,61 @@ +Sequel.migration do + up do + # The most recent verification for each pact_version + # provider_version column is DEPRECATED, use provider_version_number + # Think this can be replaced by latest_verification_id_for_pact_version_and_provider_version? + v = :verifications + create_or_replace_view(:latest_verifications, + from(v) + .select( + Sequel[v][:id], + Sequel[v][:number], + Sequel[v][:success], + Sequel[:s][:number].as(:provider_version), + 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), + Sequel[v][:test_results]) + .join(:latest_verification_numbers, + { + Sequel[v][:pact_version_id] => Sequel[:lv][:pact_version_id], + Sequel[v][:number] => Sequel[:lv][:latest_number] + }, { table_alias: :lv }) + .join(:versions, + { + Sequel[v][:provider_version_id] => Sequel[:s][:id] + }, { table_alias: :s }) + ) + end + + down do + v = :verifications + create_or_replace_view(:latest_verifications, + from(v) + .select( + Sequel[v][:id], + Sequel[v][:number], + Sequel[v][:success], + Sequel[:s][:number].as(:provider_version), + 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_numbers, + { + Sequel[v][:pact_version_id] => Sequel[:lv][:pact_version_id], + Sequel[v][:number] => Sequel[:lv][:latest_number] + }, { table_alias: :lv }) + .join(:versions, + { + Sequel[v][:provider_version_id] => Sequel[:s][:id] + }, { table_alias: :s }) + ) + end +end diff --git a/db/migrations/20190911_add_test_results_to_latest_verifications_for_pact_versions.rb b/db/migrations/20190911_add_test_results_to_latest_verifications_for_pact_versions.rb new file mode 100644 index 000000000..4f49034a8 --- /dev/null +++ b/db/migrations/20190911_add_test_results_to_latest_verifications_for_pact_versions.rb @@ -0,0 +1,58 @@ +Sequel.migration do + up do + # The most recent verification for each pact_version + v = :verifications + create_or_replace_view(:latest_verifications_for_pact_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), + Sequel[v][:test_results]) + .join(:latest_verification_ids_for_pact_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 + + down do + # The most recent verification for each pact_version + v = :verifications + create_view(:latest_verifications_for_pact_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_pact_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 diff --git a/lib/pact_broker/verifications/all_verifications.rb b/lib/pact_broker/verifications/all_verifications.rb index 65cf537a4..818de0db1 100644 --- a/lib/pact_broker/verifications/all_verifications.rb +++ b/lib/pact_broker/verifications/all_verifications.rb @@ -38,3 +38,4 @@ def provider # pact_version_id | integer | # execution_date | timestamp without time zone | # created_at | timestamp without time zone | +# test_results | text | diff --git a/lib/pact_broker/verifications/latest_verification_for_pact_version.rb b/lib/pact_broker/verifications/latest_verification_for_pact_version.rb index 243b4ef0a..ba0cf0bed 100644 --- a/lib/pact_broker/verifications/latest_verification_for_pact_version.rb +++ b/lib/pact_broker/verifications/latest_verification_for_pact_version.rb @@ -36,3 +36,4 @@ def provider # provider_version_id | integer | # provider_version_number | text | # provider_version_order | integer | +# test_results | text |