|
| 1 | +Sequel.migration do |
| 2 | + up do |
| 3 | + # The latest verification id for each consumer version tag |
| 4 | + create_view(:latest_verification_ids_for_consumer_and_provider, |
| 5 | + "select |
| 6 | + pv.pacticipant_id as provider_id, |
| 7 | + lpp.consumer_id, |
| 8 | + max(v.id) as latest_verification_id |
| 9 | + from verifications v |
| 10 | + join latest_pact_publications_by_consumer_versions lpp |
| 11 | + on v.pact_version_id = lpp.pact_version_id |
| 12 | + join versions pv |
| 13 | + on v.provider_version_id = pv.id |
| 14 | + group by pv.pacticipant_id, lpp.consumer_id") |
| 15 | + |
| 16 | + # The most recent verification for each consumer/consumer version tag/provider |
| 17 | + latest_verifications = from(:verifications) |
| 18 | + .select( |
| 19 | + Sequel[:lv][:consumer_id], |
| 20 | + Sequel[:lv][:provider_id], |
| 21 | + Sequel[:pv][:sha].as(:pact_version_sha), |
| 22 | + Sequel[:prv][:number].as(:provider_version_number), |
| 23 | + Sequel[:prv][:order].as(:provider_version_order), |
| 24 | + ) |
| 25 | + .select_append{ verifications.* } |
| 26 | + .join(:latest_verification_ids_for_consumer_and_provider, |
| 27 | + { |
| 28 | + Sequel[:verifications][:id] => Sequel[:lv][:latest_verification_id], |
| 29 | + }, { table_alias: :lv }) |
| 30 | + .join(:versions, |
| 31 | + { |
| 32 | + Sequel[:verifications][:provider_version_id] => Sequel[:prv][:id] |
| 33 | + }, { table_alias: :prv }) |
| 34 | + .join(:pact_versions, |
| 35 | + { |
| 36 | + Sequel[:verifications][:pact_version_id] => Sequel[:pv][:id] |
| 37 | + }, { table_alias: :pv }) |
| 38 | + |
| 39 | + create_or_replace_view(:latest_verifications_for_consumer_and_provider, latest_verifications) |
| 40 | + end |
| 41 | + |
| 42 | + down do |
| 43 | + drop_view(:latest_verifications_for_consumer_and_provider) |
| 44 | + drop_view(:latest_verification_ids_for_consumer_and_provider) |
| 45 | + end |
| 46 | +end |
0 commit comments