pact_broker 2.15.0 → 2.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +7 -3
  3. data/CHANGELOG.md +53 -0
  4. data/DEVELOPER_DOCUMENTATION.md +28 -1
  5. data/DEVELOPER_SETUP.md +1 -1
  6. data/README.md +8 -5
  7. data/db/migrations/000004_create_tags_table.rb +1 -1
  8. data/db/migrations/000050_create_latest_matrix.rb +1 -0
  9. data/db/migrations/20180122_create_head_pact_publications.rb +21 -0
  10. data/db/migrations/20180123_create_tags_with_latest_flag.rb +28 -0
  11. data/db/migrations/20180129_create_latest_matrix_for_cv_and_pv.rb +91 -0
  12. data/db/migrations/20180130_create_materialized_matrix.rb +35 -0
  13. data/db/migrations/20180131_create_materialized_latest_matrix.rb +35 -0
  14. data/db/migrations/20180201_create_head_matrix.rb +33 -0
  15. data/db/migrations/20180202_create_materialized_head_matrix.rb +34 -0
  16. data/db/migrations/20180203_fix_head_matrix.rb +36 -0
  17. data/db/migrations/20180204_fix_latest_matrix_for_cv_and_pv.rb +57 -0
  18. data/db/migrations/20180205_drop_materialized_latest_matrix.rb +36 -0
  19. data/db/migrations/20180206_recreate_head_matrix_rename_consumer_tag_name.rb +68 -0
  20. data/db/migrations/20180207_recreate_head_matrix_union_all.rb +60 -0
  21. data/db/migrations/20180208_add_cv_tag_name_index_to_mat_head_matrix.rb +7 -0
  22. data/db/migrations/20180209_recreate_latest_matrix_for_cv_and_pv_union_all.rb +54 -0
  23. data/db/migrations/20180210_fix_latest_matrix_for_cv_and_pv_again.rb +53 -0
  24. data/db/migrations/migration_helper.rb +8 -0
  25. data/db/test/backwards_compatibility/Rakefile +1 -1
  26. data/example/pact_broker_database.sqlite3 +0 -0
  27. data/lib/pact_broker/api.rb +1 -0
  28. data/lib/pact_broker/api/decorators/dashboard_decorator.rb +163 -0
  29. data/lib/pact_broker/api/decorators/dashboard_text_decorator.rb +50 -0
  30. data/lib/pact_broker/api/decorators/matrix_decorator.rb +21 -16
  31. data/lib/pact_broker/api/decorators/pacticipant_decorator.rb +1 -0
  32. data/lib/pact_broker/api/pact_broker_urls.rb +29 -0
  33. data/lib/pact_broker/api/resources/base_resource.rb +3 -0
  34. data/lib/pact_broker/api/resources/dashboard.rb +38 -0
  35. data/lib/pact_broker/api/resources/label.rb +0 -1
  36. data/lib/pact_broker/api/resources/tag.rb +0 -1
  37. data/lib/pact_broker/dashboard/service.rb +0 -0
  38. data/lib/pact_broker/domain/index_item.rb +16 -5
  39. data/lib/pact_broker/index/service.rb +69 -4
  40. data/lib/pact_broker/matrix/head_row.rb +11 -0
  41. data/lib/pact_broker/matrix/latest_row.rb +2 -16
  42. data/lib/pact_broker/matrix/repository.rb +56 -11
  43. data/lib/pact_broker/matrix/row.rb +166 -6
  44. data/lib/pact_broker/matrix/service.rb +5 -0
  45. data/lib/pact_broker/tags/tag_with_latest_flag.rb +18 -0
  46. data/lib/pact_broker/ui/controllers/index.rb +5 -2
  47. data/lib/pact_broker/ui/controllers/matrix.rb +3 -3
  48. data/lib/pact_broker/ui/view_models/index_item.rb +13 -5
  49. data/lib/pact_broker/ui/view_models/matrix_line.rb +77 -8
  50. data/lib/pact_broker/ui/view_models/matrix_lines.rb +17 -0
  51. data/lib/pact_broker/ui/view_models/matrix_tag.rb +42 -0
  52. data/lib/pact_broker/ui/views/index/show-with-tags.haml +26 -14
  53. data/lib/pact_broker/ui/views/index/show.haml +9 -8
  54. data/lib/pact_broker/ui/views/matrix/show.haml +46 -15
  55. data/lib/pact_broker/verifications/latest_verifications_by_consumer_version.rb +1 -0
  56. data/lib/pact_broker/verifications/repository.rb +4 -4
  57. data/lib/pact_broker/version.rb +1 -1
  58. data/lib/pact_broker/versions/abbreviate_number.rb +14 -0
  59. data/pact_broker.gemspec +3 -2
  60. data/public/images/logo@2x.png +0 -0
  61. data/public/javascripts/matrix.js +5 -0
  62. data/public/stylesheets/index.css +33 -1
  63. data/public/stylesheets/matrix.css +9 -0
  64. data/script/db-spec.sh +1 -1
  65. data/spec/features/get_dashboard_spec.rb +29 -0
  66. data/spec/fixtures/dashboard.json +83 -0
  67. data/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb +89 -0
  68. data/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb +30 -26
  69. data/spec/lib/pact_broker/api/resources/dashboard_spec.rb +16 -0
  70. data/spec/lib/pact_broker/api/resources/group_spec.rb +1 -0
  71. data/spec/lib/pact_broker/index/service_spec.rb +146 -32
  72. data/spec/lib/pact_broker/matrix/repository_spec.rb +48 -1
  73. data/spec/lib/pact_broker/matrix/row_spec.rb +59 -0
  74. data/spec/lib/pact_broker/ui/view_models/index_item_spec.rb +17 -12
  75. data/spec/lib/pact_broker/versions/abbreviate_number_spec.rb +22 -0
  76. data/spec/migrations/20180201_create_head_matrix_spec.rb +132 -0
  77. data/spec/migrations/23_pact_versions_spec.rb +2 -2
  78. data/spec/migrations/50_create_latest_matrix_spec.rb +84 -16
  79. data/spec/migrations/change_migration_strategy_spec.rb +1 -1
  80. data/spec/service_consumers/pact_helper.rb +4 -1
  81. data/spec/spec_helper.rb +1 -0
  82. data/spec/support/migration_helpers.rb +1 -1
  83. data/spec/support/rspec_match_hash.rb +6 -2
  84. data/spec/support/shared_examples_for_responses.rb +1 -1
  85. data/spec/support/test_data_builder.rb +61 -11
  86. metadata +57 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 404111dc7e6ebc927394295e7d75df78fdd1a1e3
4
- data.tar.gz: 52f7cbf51020f206ae07a5a876c4d04d4adecec8
3
+ metadata.gz: '08afc57ea5d32509b4533f1667506bf2225d1d68'
4
+ data.tar.gz: e1a451ae25b6e50d1f5839aa4ff25990f3d9e112
5
5
  SHA512:
6
- metadata.gz: b0e7b2db30b4e2f4045cfb391c23b88df8384676d314e867bdc7ef72597eadce0f0abf6c13bd6186269bb01573e71b912cfa34a307ddef2cf8076a2977d72020
7
- data.tar.gz: afd391d5952f47ac4278c676e2846521b94b6d58fdc7c6658697dfbbcb0d8f9b2e4e77b160c605a6abf8353854bdfc4fa958669ba72ef4d75bf48c1835bdcd9d
6
+ metadata.gz: 02b6ebf75e3840706d78a435a241da778d4155fe469431c9f670c55780ca7c338c0ec7c937c353d65359aa477ebeb589690d300cb3f1c235055584c80b7abe05
7
+ data.tar.gz: 7810448e6235d088de9c4646b74b895de50f23d8b87ad8841e7e22e098d4745d006ed01d85c6e574ccaa0d496e6ea2fa6bb83c7f38643285c3e419524d512c09
data/.codeclimate.yml CHANGED
@@ -4,12 +4,12 @@ engines:
4
4
  enabled: true
5
5
  duplication:
6
6
  enabled: true
7
+ exclude_patterns:
8
+ - spec/
7
9
  config:
8
10
  languages:
9
11
  - ruby
10
12
  - javascript
11
- exclude_paths:
12
- - spec/
13
13
  eslint:
14
14
  enabled: true
15
15
  fixme:
@@ -26,8 +26,12 @@ ratings:
26
26
  - "**.php"
27
27
  - "**.py"
28
28
  - "**.rb"
29
- exclude_paths:
29
+ exclude_patterns:
30
30
  - script/
31
31
  - vendor/
32
32
  - public/Network Graph_files/
33
33
  - public/js/bootstrap*
34
+ - public/javascripts/d3.v3.js.pagespeed.ce.dFNRrGTALe.js
35
+ - public/javascripts/highlight.pack.js
36
+ - public/javascripts/jquery*.js
37
+ - public/js/bootstrap*.js
data/CHANGELOG.md CHANGED
@@ -1,3 +1,56 @@
1
+ <a name="v2.16.0"></a>
2
+ ### v2.16.0 (2018-03-05)
3
+
4
+
5
+ #### Features
6
+
7
+ * upgrade haml to 5.0 ([4415686](/../../commit/4415686))
8
+ * upgrade sequel to 5.6 ([a37c59a](/../../commit/a37c59a))
9
+ * abbreviate git shas in index and matrix UIs ([9a21e10](/../../commit/9a21e10))
10
+ * add latest provider version tag names to dashboard UI ([de179d7](/../../commit/de179d7))
11
+ * created dashboard API ([044bab7](/../../commit/044bab7))
12
+ * allow database to have missing migration files so that we can deploy branches with different migrations to the same database ([c9fe988](/../../commit/c9fe988))
13
+ * add dius logo to new index view with tags ([8a4e727](/../../commit/8a4e727))
14
+
15
+ * **matrix**
16
+ * make index refresh happen synchronously to prevent data corruption ([acd64e6](/../../commit/acd64e6))
17
+ * speed up query to refresh index ([011d7c9](/../../commit/011d7c9))
18
+ * refresh head matrix asynchronously to speed up pact publishing and tagging ([989e6e3](/../../commit/989e6e3))
19
+ * speed up matrix query for latestby=cvpv and latestby=cvp ([6ae039d](/../../commit/6ae039d))
20
+
21
+ * **index**
22
+ * sort verifications by execution date ([2523982](/../../commit/2523982))
23
+ * show tag names as slugs ([117c89b](/../../commit/117c89b))
24
+
25
+ * **matrix ui**
26
+ * rename "rows" to "results" ([2023265](/../../commit/2023265))
27
+ * show row count ([b50bd9a](/../../commit/b50bd9a))
28
+ * remove logic for hiding links until I can get it right ([107fca2](/../../commit/107fca2))
29
+ * correct logic for hiding pact links ([825af6d](/../../commit/825af6d))
30
+ * don't show potentially confusing links for overwritten pact revisions ([ed7498a](/../../commit/ed7498a))
31
+ * add links to all resources referenced in matrix ([2958ae8](/../../commit/2958ae8))
32
+ * add tags ([869d49d](/../../commit/869d49d))
33
+
34
+ * **dashboard api**
35
+ * correct latest verification results ([d02ea24](/../../commit/d02ea24))
36
+ * fix query for displaying dashboard with tags ([924aaae](/../../commit/924aaae))
37
+ * optimise dashboard query by creating manual materialized views for the matrix ([494f553](/../../commit/494f553))
38
+ * add plain text content type for easy debugging ([317a64d](/../../commit/317a64d))
39
+ * speed up loading of verification tags ([a3aea48](/../../commit/a3aea48))
40
+ * include verification tags ([e8d0fae](/../../commit/e8d0fae))
41
+ * add pact tags ([0c79440](/../../commit/0c79440))
42
+
43
+
44
+ #### Bug Fixes
45
+
46
+ * **matrix**
47
+ * correct logic for selecting matrix rows on MySQL ([06f6dd4](/../../commit/06f6dd4))
48
+ * ensure matrix for latest consumer version/provider version shows correct results when a pact is published, published again for the same version with different content, then published again for the same version with the original content. ([679eec1](/../../commit/679eec1))
49
+
50
+ * **matrix ui**
51
+ * fix provider version sorting ([611ab7e](/../../commit/611ab7e))
52
+
53
+
1
54
  <a name="v2.15.0"></a>
2
55
  ### v2.15.0 (2018-02-26)
3
56
 
@@ -58,4 +58,31 @@ Domain classes are found in `lib/pact_broker/domain`. Many of these classes are
58
58
 
59
59
  * `matrix` - The matrix of every pact publication and verification. Includes every pact revision (eg. publishing to the same consumer version twice, or using PATCH) and every verification (including 'overwritten' ones. eg. when the same provider build runs twice.)
60
60
 
61
- * `latest_matrix` - This view is a subset of, and has the same columns as, the `matrix`. It removes 'overwritten' pacts and verifications from the matrix (ie. only show latest pact revision for each consumer version and latest verification for each provider version)
61
+ * `latest_matrix_for_consumer_version_and_provider_version` - This view is a subset of, and has the same columns as, the `matrix`. It removes 'overwritten' pacts and verifications from the matrix (ie. only show latest pact revision for each consumer version and latest verification for each provider version)
62
+
63
+ ### Materialized Views
64
+
65
+ We can't use proper materialized views because we have to support MySQL :|
66
+
67
+ So as a hacky solution, there are two tables which act as materialized views to speed up the performance of the matrix and index queries. These tables are updated after any resource is published with a `consumer_name`, `provider_name` or `pacticipant_name` in the URL (see lib/pact_broker/api/resources/base_resource.rb#finish_request).
68
+
69
+ * `materialized_matrix` table - is populated from the `matrix` view.
70
+
71
+ * `materialized_head_matrix` table - is populated from `head_matrix` view, and is based on `materialized_matrix`.
72
+
73
+ ### Dependencies
74
+
75
+ materialized_head_matrix table (is populated from...)
76
+ = head_matrix view
77
+ -> latest_matrix_for_consumer_version_and_provider_version view
78
+ -> materialized_matrix table (is populated from...)
79
+ = matrix view
80
+ -> verifications table
81
+ -> versions table
82
+ -> all_pact_publications view
83
+ -> pact_versions table
84
+ -> pact_publications table
85
+ -> pacticipants table
86
+ -> versions table
87
+ -> latest_verification_id_for_consumer_version_and_provider_version view
88
+ -> latest_pact_publication_revision_numbers view
data/DEVELOPER_SETUP.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Developer setup
2
2
 
3
- * You will need to install Ruby 2.4, and preferably a ruby version manager. I recommend using [chruby](chruby) and [ruby-install](ruby-install).
3
+ * You will need to install Ruby 2.4, and preferably a ruby version manager. I recommend using [chruby][chruby] and [ruby-install][ruby-install].
4
4
  * Install bundler (the Ruby gem dependency manager) `gem install bundler`
5
5
  * Check out the pact_broker repository.
6
6
  * Run `bundle exec pact_broker:dev:setup`. This will create an example application that you can run locally, that uses the local source code.
data/README.md CHANGED
@@ -6,8 +6,11 @@
6
6
  [![Issue Count](https://codeclimate.com/github/pact-foundation/pact_broker/badges/issue_count.svg)](https://codeclimate.com/github/pact-foundation/pact_broker)
7
7
  [![Dependency Status](https://gemnasium.com/badges/github.com/pact-foundation/pact_broker.svg)](https://gemnasium.com/github.com/pact-foundation/pact_broker)
8
8
 
9
- The Pact Broker is an application for sharing for consumer driven contracts. It is optimised for use with "pacts" (contracts created by the [Pact][pact-docs] framework), but can be used for any type of contract that can be serialized to JSON.
9
+ The Pact Broker is an application for sharing for consumer driven contracts and verification results. It is optimised for use with "pacts" (contracts created by the [Pact][pact-docs] framework), but can be used for any type of contract that can be serialized to JSON.
10
10
 
11
+ **Why do I need one?**
12
+
13
+ Contract testing is an alternative approach to traditional integration testing that gives you tests that are quicker to execute, and that are more maintainable at scale. One down side of the approach is that the important information that would be available all in one place at the end of an integration test suite execution (that is, the version numbers of all the applications that were tested together, and whether the tests passed or failed) is now spread out across many different builds. The Pact Broker is a tool that brings all this information back together again, and allows you to deploy with safety.
11
14
 
12
15
  It:
13
16
 
@@ -29,7 +32,7 @@ Features:
29
32
  * Displays provider verificaton results so you know if you can deploy safely.
30
33
  * Provides a "matrix" of compatible consumer and provider versions, so you know which versions can be safely deployed together.
31
34
  * Provides badges to display pact verification statuses in your READMEs.
32
- * Enables an application version to be tagged (ie. "prod", "feat/customer-preferences") to allow repository-like workflows.
35
+ * Enables an application version to be tagged (ie. "prod", "feat/customer-preferences") to allow repository-like workflows.
33
36
  * Provides webhooks to trigger actions when pacts change eg. run provider build, notify a Slack channel.
34
37
  * View diffs between Pact versions so you can tell what expectations have changed.
35
38
  * [Docker Pact Broker][docker]
@@ -40,7 +43,7 @@ Features:
40
43
  #### Step 1. Consumer CI build
41
44
  1. The consumer project runs its tests using the [Pact][pact] library to provide a mock service.
42
45
  2. While the tests run, the mock service writes the requests and the expected responses to a JSON "pact" file - this is the consumer contract.
43
- 3. The generated pact is then published to the Pact Broker. Most Pact libries will make a task available for you to do this easily, however, at its simplest, it is a `PUT` to a resource that specifies the consumer name and application version, and the provider name. eg `http://my-pact-broker/pacts/provider/Animal%20Service/consumer/Zoo%20App/version/1.0.0`
46
+ 3. The generated pact is then published to the Pact Broker. Most Pact libries will make a task available for you to do this easily, however, at its simplest, it is a `PUT` to a resource that specifies the consumer name and application version, and the provider name. eg `http://my-pact-broker/pacts/provider/Animal%20Service/consumer/Zoo%20App/version/1.0.0`
44
47
  (Note that you are specifying the _consumer application version_ in the URL, not the pact version. The broker will take care of versioning the pact behind the scenes when its content changes. It is expected that the consumer application version will increment with every CI build.)
45
48
  4. When a pact is published, a webhook in the Pact Broker kicks off a build of the provider project if the pact content has changed since the previous version.
46
49
 
@@ -63,7 +66,7 @@ Read more about how to use the Pact Broker in the [overview][overview] on the wi
63
66
 
64
67
  ## Documentation
65
68
 
66
- See the [wiki][wiki] for documentation on the Pact Broker.
69
+ See the [wiki][wiki] for documentation on the Pact Broker. Please read the [overview][overview] page first to get an understanding of the HTTP resources in the broker, and how they relate to each other.
67
70
 
68
71
  ## Support
69
72
 
@@ -139,7 +142,7 @@ You can use the [Pact Broker Docker image][docker] or [Terraform on AWS][terrafo
139
142
  * Check the [travis.yml][travisyml] file to make sure you're using the version of the database that we're currently running our tests against.
140
143
  * If you're using PostgreSQL (did we mention this was _recommended!_) you'll find the database creation script in the [example/config.ru](https://github.com/pact-foundation/pact_broker/blob/master/example/config.ru).
141
144
  * Install ruby 2.2.0 or later and bundler >= 1.12.0 (if you've come this far, I'm assuming you know how to do both of these. Did I mention there was a [Docker][docker] image?)
142
- * Copy the [pact\_broker](https://github.com/DiUS/pact_broker-docker/tree/master/pact_broker) directory from the Pact Broker Docker project. This will have the recommended settings for database connections, logging, basic auth etc. Note that the Docker image uses Phusion Passenger as the web application server in front of the Pact Broker Ruby application, which is the recommended set up.
145
+ * Copy the [pact\_broker](https://github.com/DiUS/pact_broker-docker/tree/master/pact_broker) directory from the Pact Broker Docker project. This will have the recommended settings for database connections, logging, basic auth etc. Note that the Docker image uses Phusion Passenger as the web application server in front of the Pact Broker Ruby application, which is the recommended set up.
143
146
  * Modify the config.ru and Gemfile as desired (eg. choose database driver gem, set your database credentials. Use the "pg" gem if using Postgres and the "mysql2" gem if using MySQL)
144
147
  * Please ensure you use `encoding: 'utf8'` in your Sequel options to avoid encoding issues.
145
148
  * For production usage, use a web application server like [Phusion Passenger](https://www.phusionpassenger.com) or [Nginx](http://nginx.org/) to serve the Pact Broker application. You'll need to read up on the documentation for these yourself as it is beyond the scope of this documentation. See the [wiki][reverse-proxy-docs] for instructions on using a reverse proxy with SSL.
@@ -3,7 +3,7 @@ Sequel.migration do
3
3
  create_table(:tags, charset: 'utf8') do
4
4
  String :name
5
5
  foreign_key :version_id, :versions
6
- primary_key [:version_id, :name], :name=>:tags_pk
6
+ primary_key [:version_id, :name], name: :tags_pk
7
7
  end
8
8
  end
9
9
  end
@@ -5,6 +5,7 @@ Sequel.migration do
5
5
  # latest verification for each provider version)
6
6
  # Must include lines where verification_id is null so that we don't
7
7
  # lose the unverified pacts.
8
+ # In this view there will be one row for each consumer version/provider version
8
9
  create_view(:latest_matrix,
9
10
  "SELECT matrix.* FROM matrix
10
11
  INNER JOIN latest_verification_id_for_consumer_version_and_provider_version AS lv
@@ -0,0 +1,21 @@
1
+ Sequel.migration do
2
+ change do
3
+
4
+ # This view includes all the latest pacts, as well as the latest pacts
5
+ # for each tag.
6
+ # If a pact publication is the latest AND the latest tagged version
7
+ # there will be two rows in this view for it - one for the top
8
+ # query,and one for the bottom.
9
+ create_view(:head_pact_publications,
10
+ "select lp.*, null as tag_name, 1 as latest
11
+ from latest_pact_publications lp
12
+
13
+ UNION
14
+
15
+ select ltp.*, null as latest
16
+ from latest_tagged_pact_publications ltp
17
+ "
18
+ )
19
+
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'migration_helper'
2
+
3
+ Sequel.migration do
4
+ change do
5
+ create_view(:latest_tagged_version_orders,
6
+ PactBroker::MigrationHelper.sqlite_safe("
7
+ select v.pacticipant_id, t.name as tag_name, max(v.order) as latest_version_order, 1 as latest
8
+ from tags t
9
+ inner join versions v
10
+ on v.id = t.version_id
11
+ group by v.pacticipant_id, t.name
12
+ ")
13
+ )
14
+
15
+ create_view(:tags_with_latest_flag,
16
+ PactBroker::MigrationHelper.sqlite_safe("
17
+ select t.*, ltvo.latest
18
+ from tags t
19
+ inner join versions v
20
+ on v.id = t.version_id
21
+ left outer join latest_tagged_version_orders ltvo
22
+ on t.name = ltvo.tag_name
23
+ and v.pacticipant_id = ltvo.pacticipant_id
24
+ and v.order = ltvo.latest_version_order
25
+ ")
26
+ )
27
+ end
28
+ end
@@ -0,0 +1,91 @@
1
+ Sequel.migration do
2
+ up do
3
+ # Removes 'overwritten' pacts and verifications from the matrix
4
+ # (ie. only show latest pact revision for each consumer version and
5
+ # latest verification for each provider version)
6
+ # Must include lines where verification_id is null so that we don't
7
+ # lose the unverified pacts.
8
+ # In this view there will be one row for each consumer version/provider version
9
+ # This view used to be (stupidly) called latest_matrix
10
+ create_view(:latest_matrix_for_consumer_version_and_provider_version,
11
+ "SELECT matrix.* FROM matrix
12
+ INNER JOIN latest_verification_id_for_consumer_version_and_provider_version AS lv
13
+ ON ((matrix.consumer_version_id = lv.consumer_version_id)
14
+ AND (matrix.provider_version_id = lv.provider_version_id)
15
+ AND ((matrix.verification_id = lv.latest_verification_id)))
16
+
17
+ UNION
18
+
19
+ select matrix.* from matrix
20
+ inner join latest_pact_publication_revision_numbers lr
21
+ on matrix.consumer_id = lr.consumer_id
22
+ and matrix.provider_id = lr.provider_id
23
+ and matrix.consumer_version_order = lr.consumer_version_order
24
+ and matrix.pact_revision_number = lr.latest_revision_number
25
+ where verification_id is null
26
+ "
27
+ )
28
+
29
+ # it's a bit dodgey to be using the max(id) of the verification to determine the latest,
30
+ # but otherwise we'd need to add an extra step and find the latest_provider_version_order
31
+ # and then find the latest verification within that provider_version_order, which we'd
32
+ # probably do by using the ID anyway. And I'm feeling lazy.
33
+ create_view(:latest_verification_id_for_consumer_version_and_provider,
34
+ "select matrix.consumer_version_id, matrix.provider_id, max(verification_id) as latest_verification_id
35
+ from latest_matrix_for_consumer_version_and_provider_version matrix
36
+ where matrix.verification_id is not null
37
+ group by matrix.consumer_version_id, matrix.provider_id
38
+ "
39
+ )
40
+
41
+ # update the definition of latest_matrix to actually be the latest_matrix
42
+ # in the same way that latest_pact_publications is.
43
+ # It contains the latest verification results for the latest pacts.
44
+ create_or_replace_view(:latest_matrix,
45
+ "SELECT matrix.* FROM latest_matrix_for_consumer_version_and_provider_version matrix
46
+ INNER JOIN latest_pact_consumer_version_orders lpcvo
47
+ ON matrix.consumer_id = lpcvo.consumer_id
48
+ AND matrix.provider_id = lpcvo.provider_id
49
+ AND matrix.consumer_version_order = lpcvo.latest_consumer_version_order
50
+ INNER JOIN latest_verification_id_for_consumer_version_and_provider AS lv
51
+ ON ((matrix.consumer_version_id = lv.consumer_version_id)
52
+ AND (matrix.provider_id = lv.provider_id)
53
+ AND ((matrix.verification_id = lv.latest_verification_id)))
54
+
55
+ UNION
56
+
57
+ SELECT matrix.* FROM latest_matrix_for_consumer_version_and_provider_version matrix
58
+ INNER JOIN latest_pact_consumer_version_orders lpcvo
59
+ ON matrix.consumer_id = lpcvo.consumer_id
60
+ AND matrix.provider_id = lpcvo.provider_id
61
+ AND matrix.consumer_version_order = lpcvo.latest_consumer_version_order
62
+ where verification_id is null
63
+ "
64
+ )
65
+ end
66
+
67
+ down do
68
+ # revert to previous crappy definition
69
+ create_or_replace_view(:latest_matrix,
70
+ "SELECT matrix.* FROM matrix
71
+ INNER JOIN latest_verification_id_for_consumer_version_and_provider_version AS lv
72
+ ON ((matrix.consumer_version_id = lv.consumer_version_id)
73
+ AND (matrix.provider_version_id = lv.provider_version_id)
74
+ AND ((matrix.verification_id = lv.latest_verification_id)))
75
+
76
+ UNION
77
+
78
+ select matrix.* from matrix
79
+ inner join latest_pact_publication_revision_numbers lr
80
+ on matrix.consumer_id = lr.consumer_id
81
+ and matrix.provider_id = lr.provider_id
82
+ and matrix.consumer_version_order = lr.consumer_version_order
83
+ and matrix.pact_revision_number = lr.latest_revision_number
84
+ where verification_id is null
85
+ "
86
+ )
87
+
88
+ drop_view(:latest_verification_id_for_consumer_version_and_provider)
89
+ drop_view(:latest_matrix_for_consumer_version_and_provider_version)
90
+ end
91
+ end
@@ -0,0 +1,35 @@
1
+ Sequel.migration do
2
+ up do
3
+ create_table(:materialized_matrix, charset: 'utf8') do
4
+ Integer :consumer_id, null: false
5
+ String :consumer_name, null: false
6
+ Integer :consumer_version_id, null: false
7
+ String :consumer_version_number, null: false
8
+ Integer :consumer_version_order, null: false
9
+ Integer :pact_publication_id, null: false
10
+ Integer :pact_version_id, null: false
11
+ String :pact_version_sha, null: false
12
+ Integer :pact_revision_number, null: false
13
+ DateTime :pact_created_at, null: false
14
+ Integer :provider_id, null: false
15
+ String :provider_name, null: false
16
+ Integer :provider_version_id
17
+ String :provider_version_number
18
+ Integer :provider_version_order
19
+ Integer :verification_id
20
+ Boolean :success
21
+ Integer :verification_number
22
+ DateTime :verification_executed_at
23
+ String :verification_build_url
24
+ index [:consumer_id], name: 'ndx_mm_consumer_id'
25
+ index [:provider_id], name: 'ndx_mm_provider_id'
26
+ index [:consumer_version_order], name: 'ndx_mm_cv_ord'
27
+ end
28
+
29
+ from(:materialized_matrix).insert(from(:matrix).select_all)
30
+ end
31
+
32
+ down do
33
+ drop_table(:materialized_matrix)
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ Sequel.migration do
2
+ up do
3
+ create_table(:materialized_latest_matrix, charset: 'utf8') do
4
+ Integer :consumer_id, null: false
5
+ String :consumer_name, null: false
6
+ Integer :consumer_version_id, null: false
7
+ String :consumer_version_number, null: false
8
+ Integer :consumer_version_order, null: false
9
+ Integer :pact_publication_id, null: false
10
+ Integer :pact_version_id, null: false
11
+ String :pact_version_sha, null: false
12
+ Integer :pact_revision_number, null: false
13
+ DateTime :pact_created_at, null: false
14
+ Integer :provider_id, null: false
15
+ String :provider_name, null: false
16
+ Integer :provider_version_id
17
+ String :provider_version_number
18
+ Integer :provider_version_order
19
+ Integer :verification_id
20
+ Boolean :success
21
+ Integer :verification_number
22
+ DateTime :verification_executed_at
23
+ String :verification_build_url
24
+ index [:consumer_id], name: 'ndx_mlm_consumer_id'
25
+ index [:provider_id], name: 'ndx_mlm_provider_id'
26
+ index [:consumer_version_order], name: 'ndx_mlm_cv_ord'
27
+ end
28
+
29
+ from(:materialized_latest_matrix).insert(from(:latest_matrix).select_all)
30
+ end
31
+
32
+ down do
33
+ drop_table(:materialized_latest_matrix)
34
+ end
35
+ end
@@ -0,0 +1,33 @@
1
+ Sequel.migration do
2
+ up do
3
+ # a row for each of the latest pact publications,
4
+ # and a row for each of the latest tagged pact publications
5
+ create_view(:head_matrix,
6
+ "SELECT matrix.*, hpp.tag_name as consumer_tag_name
7
+ FROM latest_matrix_for_consumer_version_and_provider_version matrix
8
+ INNER JOIN head_pact_publications hpp
9
+ ON matrix.consumer_id = hpp.consumer_id
10
+ AND matrix.provider_id = hpp.provider_id
11
+ AND matrix.consumer_version_order = hpp.consumer_version_order
12
+ INNER JOIN latest_verification_id_for_consumer_version_and_provider AS lv
13
+ ON matrix.consumer_version_id = lv.consumer_version_id
14
+ AND matrix.provider_id = lv.provider_id
15
+ AND matrix.verification_id = lv.latest_verification_id
16
+
17
+ UNION
18
+
19
+ SELECT matrix.*, hpp.tag_name as consumer_tag_name
20
+ FROM latest_matrix_for_consumer_version_and_provider_version matrix
21
+ INNER JOIN head_pact_publications hpp
22
+ ON matrix.consumer_id = hpp.consumer_id
23
+ AND matrix.provider_id = hpp.provider_id
24
+ AND matrix.consumer_version_order = hpp.consumer_version_order
25
+ where verification_id is null
26
+ "
27
+ )
28
+ end
29
+
30
+ down do
31
+ drop_view(:head_matrix)
32
+ end
33
+ end