pact_broker 1.18.0 → 2.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -9
  3. data/DEVELOPER_DOCUMENTATION.md +53 -0
  4. data/README.md +13 -13
  5. data/db/migrations/23_create_pact_contents_table.rb +19 -0
  6. data/db/migrations/24_populate_pact_contents.rb +9 -0
  7. data/db/migrations/25_populate_pact_contents_pacticipants.rb +7 -0
  8. data/db/migrations/26_make_pc_pacticipants_mandatory.rb +8 -0
  9. data/db/migrations/27_create_pact_publications.rb +18 -0
  10. data/db/migrations/28_populate_pact_publications.rb +13 -0
  11. data/db/migrations/29_recreate_all_pacts.rb +16 -0
  12. data/db/migrations/30_drop_pacts.rb +8 -0
  13. data/db/migrations/31_drop_pact_version_contents.rb +5 -0
  14. data/db/migrations/32_rename_pact_contents.rb +5 -0
  15. data/db/migrations/33_recreate_all_pacts.rb +52 -0
  16. data/db/migrations/34_recreate_latest_tagged_pacts.rb +23 -0
  17. data/db/migrations/35_create_verifications.rb +15 -0
  18. data/db/migrations/36_create_latest_verifications.rb +14 -0
  19. data/db/pact_broker_database.sqlite3 +0 -0
  20. data/lib/pact_broker/api.rb +25 -10
  21. data/lib/pact_broker/api/contracts/verification_contract.rb +41 -0
  22. data/lib/pact_broker/api/decorators/pact_decorator.rb +7 -0
  23. data/lib/pact_broker/api/decorators/pact_version_decorator.rb +0 -1
  24. data/lib/pact_broker/api/decorators/representable_pact.rb +4 -3
  25. data/lib/pact_broker/api/decorators/timestamps.rb +1 -1
  26. data/lib/pact_broker/api/decorators/verification_decorator.rb +30 -0
  27. data/lib/pact_broker/api/decorators/verifications_decorator.rb +21 -0
  28. data/lib/pact_broker/api/decorators/version_decorator.rb +14 -0
  29. data/lib/pact_broker/api/decorators/versions_decorator.rb +1 -1
  30. data/lib/pact_broker/api/pact_broker_urls.rb +41 -2
  31. data/lib/pact_broker/api/renderers/html_pact_renderer.rb +1 -1
  32. data/lib/pact_broker/api/resources/base_resource.rb +11 -2
  33. data/lib/pact_broker/api/resources/latest_verifications_for_consumer_version.rb +39 -0
  34. data/lib/pact_broker/api/resources/pacticipants.rb +1 -1
  35. data/lib/pact_broker/api/resources/previous_distinct_pact_version.rb +1 -1
  36. data/lib/pact_broker/api/resources/verifications.rb +67 -0
  37. data/lib/pact_broker/api/resources/versions.rb +1 -1
  38. data/lib/pact_broker/api/resources/webhooks.rb +1 -1
  39. data/lib/pact_broker/app.rb +0 -2
  40. data/lib/pact_broker/configuration.rb +1 -4
  41. data/lib/pact_broker/doc/views/latest-verifications.markdown +7 -0
  42. data/lib/pact_broker/doc/views/publish-verification.markdown +14 -0
  43. data/lib/pact_broker/domain.rb +1 -1
  44. data/lib/pact_broker/domain/order_versions.rb +5 -15
  45. data/lib/pact_broker/domain/pact.rb +10 -2
  46. data/lib/pact_broker/domain/relationship.rb +31 -4
  47. data/lib/pact_broker/domain/verification.rb +77 -0
  48. data/lib/pact_broker/domain/version.rb +6 -1
  49. data/lib/pact_broker/domain/webhook.rb +1 -0
  50. data/lib/pact_broker/domain/webhook_request.rb +4 -6
  51. data/lib/pact_broker/locale/en.yml +2 -1
  52. data/lib/pact_broker/logging.rb +0 -4
  53. data/lib/pact_broker/pacticipants/repository.rb +1 -2
  54. data/lib/pact_broker/pacticipants/service.rb +11 -5
  55. data/lib/pact_broker/pacts/all_pact_publications.rb +96 -0
  56. data/lib/pact_broker/pacts/all_pacts.rb +4 -89
  57. data/lib/pact_broker/pacts/diff.rb +2 -2
  58. data/lib/pact_broker/pacts/latest_pact_publications.rb +11 -0
  59. data/lib/pact_broker/pacts/latest_pact_publications_by_consumer_version.rb +11 -0
  60. data/lib/pact_broker/pacts/latest_pacts.rb +1 -0
  61. data/lib/pact_broker/pacts/latest_tagged_pact_publications.rb +11 -0
  62. data/lib/pact_broker/pacts/pact_params.rb +11 -1
  63. data/lib/pact_broker/pacts/pact_publication.rb +50 -0
  64. data/lib/pact_broker/pacts/pact_version.rb +39 -0
  65. data/lib/pact_broker/pacts/repository.rb +46 -36
  66. data/lib/pact_broker/pacts/service.rb +2 -2
  67. data/lib/pact_broker/repositories.rb +5 -0
  68. data/lib/pact_broker/services.rb +5 -0
  69. data/lib/pact_broker/ui/view_models/relationship.rb +38 -0
  70. data/lib/pact_broker/ui/views/relationships/show.haml +9 -0
  71. data/lib/pact_broker/verifications/repository.rb +45 -0
  72. data/lib/pact_broker/verifications/service.rb +40 -0
  73. data/lib/pact_broker/version.rb +1 -1
  74. data/lib/pact_broker/versions/parse_semantic_version.rb +9 -6
  75. data/lib/pact_broker/webhooks/service.rb +8 -9
  76. data/lib/pact_broker/webhooks/webhook.rb +1 -1
  77. data/pact_broker.gemspec +3 -4
  78. data/pact_broker_client-pact_broker.json +4 -4
  79. data/script/publish.sh +2 -2
  80. data/script/record_verification.sh +3 -0
  81. data/spec/features/delete_pact_spec.rb +1 -1
  82. data/spec/features/get_verifications_for_consumer_version_spec.rb +33 -0
  83. data/spec/features/publish_verification_spec.rb +28 -0
  84. data/spec/fixtures/a_consumer-a_provider-2.json +1 -1
  85. data/spec/fixtures/a_consumer-a_provider-3.json +1 -1
  86. data/spec/fixtures/a_consumer-a_provider-conflict.json +1 -1
  87. data/spec/fixtures/a_consumer-a_provider-merged.json +2 -2
  88. data/spec/fixtures/a_consumer-a_provider.json +1 -1
  89. data/spec/fixtures/consumer-provider.json +1 -1
  90. data/spec/fixtures/renderer_pact.json +1 -1
  91. data/spec/fixtures/verification.json +4 -0
  92. data/spec/lib/pact_broker/api/contracts/verification_contract_spec.rb +91 -0
  93. data/spec/lib/pact_broker/api/decorators/latest_pact_decorator_spec.rb +0 -18
  94. data/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb +6 -2
  95. data/spec/lib/pact_broker/api/decorators/pact_version_decorator_spec.rb +0 -3
  96. data/spec/lib/pact_broker/api/decorators/verification_decorator_spec.rb +61 -0
  97. data/spec/lib/pact_broker/api/decorators/verifications_decorator_spec.rb +42 -0
  98. data/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb +4 -0
  99. data/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb +1 -1
  100. data/spec/lib/pact_broker/api/resources/latest_verifications_for_consumer_version_spec.rb +68 -0
  101. data/spec/lib/pact_broker/api/resources/pact_spec.rb +1 -1
  102. data/spec/lib/pact_broker/api/resources/pacticipants_spec.rb +1 -1
  103. data/spec/lib/pact_broker/api/resources/verifications_spec.rb +92 -0
  104. data/spec/lib/pact_broker/api/resources/webhooks_spec.rb +1 -1
  105. data/spec/lib/pact_broker/domain/order_versions_spec.rb +10 -30
  106. data/spec/lib/pact_broker/domain/verification_spec.rb +41 -0
  107. data/spec/lib/pact_broker/domain/version_spec.rb +26 -0
  108. data/spec/lib/pact_broker/domain/webhook_request_spec.rb +1 -3
  109. data/spec/lib/pact_broker/pacticipants/repository_spec.rb +0 -16
  110. data/spec/lib/pact_broker/pacticipants/service_spec.rb +4 -3
  111. data/spec/lib/pact_broker/pacts/pact_params_spec.rb +14 -1
  112. data/spec/lib/pact_broker/pacts/pact_version_spec.rb +50 -0
  113. data/spec/lib/pact_broker/pacts/repository_spec.rb +85 -36
  114. data/spec/lib/pact_broker/ui/view_models/relationship_spec.rb +48 -2
  115. data/spec/lib/pact_broker/verifications/repository_spec.rb +92 -0
  116. data/spec/lib/pact_broker/verifications/service_spec.rb +61 -0
  117. data/spec/lib/pact_broker/versions/parse_semantic_version_spec.rb +39 -0
  118. data/spec/lib/pact_broker/webhooks/service_spec.rb +3 -40
  119. data/spec/migrations/23_pact_versions_spec.rb +95 -0
  120. data/spec/migrations/24_populate_pact_contents_spec.rb +48 -0
  121. data/spec/migrations/34_latest_tagged_pacts_spec.rb +108 -0
  122. data/spec/migrations/34_pact_revisions_spec.rb +106 -0
  123. data/spec/support/database_cleaner.rb +8 -4
  124. data/spec/support/provider_state_builder.rb +22 -8
  125. metadata +81 -36
  126. data/lib/pact_broker/pacts/database_model.rb +0 -35
  127. data/lib/pact_broker/pacts/latest_tagged_pacts.rb +0 -11
  128. data/lib/pact_broker/pacts/pact_version_content.rb +0 -11
  129. data/lib/pact_broker/webhooks/job.rb +0 -46
  130. data/script/foo-bar.json +0 -22
  131. data/script/publish-new.sh +0 -7
  132. data/script/recreate-pg-db.sh +0 -7
  133. data/spec/lib/pact_broker/webhooks/job_spec.rb +0 -67
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ef22c7934452713d713906de14fade4ecc2a2c8
4
- data.tar.gz: e20f94e91cd30b71fde2c80393861342e989a33f
3
+ metadata.gz: f1868b3d1f43fe2ebee71e30e38088b70faa46c4
4
+ data.tar.gz: 6e0947382d1b455892c94b23b41b400ca2c8c7a6
5
5
  SHA512:
6
- metadata.gz: b5be0a05dd839aef2b0da83d95f7ea58c0c9934ec6e59162a726fa21c3c9f7f795090f05071506df821ff2a930557a1649111f951ec7321a008faed5f59ea2de
7
- data.tar.gz: 1fb67c57f5491571a02d096e0243bd20c43f64faf1a5245457743c71663a002ee3c91dd59355ea863164025ef22ca6840c38d226ec324b40d69c237da5bbddae
6
+ metadata.gz: 0d592dfd992c8de6271f6bfbc30292bd48aa772d2eb914f741882efe853b5677ff8d440ffd41fa30686074dfab7116e1a082dcd87c11870a13adb162cef08161
7
+ data.tar.gz: 9dfc13a55c1ea8a00ef5efeed880a81687460030d20ea32c95e639076d70fba98d5c76d6e4b1c90da6eea2fea4ad7c90236a4ba27243f8fbba253b7d9ec6fc81
data/CHANGELOG.md CHANGED
@@ -2,17 +2,20 @@ Do this to generate your change history
2
2
 
3
3
  $ git log --pretty=format:' * %h - %s (%an, %ad)' vX.Y.Z..HEAD
4
4
 
5
- #### 1.18.0 (2017-05-09)
6
- * 397060b - Display application versions in reverse order in the Versions resource. (Beth Skurrie, Tue May 9 13:59:54 2017 +1000)
7
- * 251c878 - Allow application versions to be ordered by creation date where no consistent orderable object can be extracted from the consumer application version. (Beth Skurrie, Tue May 9 13:22:36 2017 +1000)
8
- * 68bb6d9 - Execute webhooks using sucker punch. (Beth Skurrie, Mon May 8 10:32:45 2017 +1000)
5
+ #### 2.0.0.beta.1 (2017-04-28)
9
6
 
10
- #### 1.17.2 (2017-05-04)
11
- * b8f45e1 - fix issue with pact document link not displaying #94 (Matt Fellows, Wed May 3 11:23:09 2017 +1000)
12
-
13
- #### 1.17.1 (2017-05-02)
14
- * 7576bc2 - Fix 500 error in webhooks endpoint. (Beth Skurrie, Tue May 2 14:35:06 2017 +1000)
7
+ * 049bc5c - Added tooltip to verification date to show provider version. (Beth Skurrie, Fri Apr 28 10:05:13 2017 +1000)
8
+ * 4287c99 - Add tooltip text to last verified date when pact has changed since last verification. (Beth Skurrie, Fri Apr 28 09:02:59 2017 +1000)
15
9
  * 7351ec8 - Add restrictions for all gem versions in gemspec. Fix formatting in haml file. (Beth Skurrie, Thu Apr 27 19:55:04 2017 +1000)
10
+ * a836b56 - Add last verified date for each pact to landing page of application UI. (Beth Skurrie, Tue Apr 25 17:03:06 2017 +1000)
11
+ * c7589c9 - Use latest ruby-2.3.4 for development. (Tan Le, Mon Apr 24 23:05:27 2017 +1000)
12
+ * 46b87f9 - Use latest ruby patches for CI. (Tan Le, Mon Apr 24 23:00:12 2017 +1000)
13
+ * 7c17c62 - Required at least ruby-2.2.0 as we move along ruby release schedule. (Tan Le, Mon Apr 24 22:54:52 2017 +1000)
14
+ * 66a2f3b - Added pb:publish-verification HAL link to pact resource. (Beth Skurrie, Fri Apr 21 16:09:55 2017 +1000)
15
+ * f2110ac - Replacing versionomy with semver2 for parsing version numbers according to semver 2.0.0 (http://semver.org) (Danilo Sato, Thu Apr 20 11:48:49 2017 -0400)
16
+ * 1f6045a - Added DEVELOPER_DOCUMENTATION.md with information about the tables and views. (Beth Skurrie, Tue Apr 18 11:35:39 2017 +1000)
17
+ * 77eaf7b - Added pb:latest-verifications link to version resource. (Beth Skurrie, Tue Apr 11 16:25:45 2017 +1000)
18
+ * aaf44d9 - Added endpoint to view the latest verifications for a given consumer version. (Beth Skurrie, Tue Apr 11 11:16:03 2017 +1000)
16
19
 
17
20
  #### 1.17.0 (2017-04-26)
18
21
  * 5cbb9da - Added pb:publish-pact to HAL index (Beth Skurrie, Wed Apr 26 08:39:15 2017 +1000)
@@ -0,0 +1,53 @@
1
+ # Developer Documentation
2
+
3
+ ## Domain and database design
4
+
5
+ ### Tables
6
+ * `pact_version_contents` - the JSON content of each UNIQUE pact document is stored in this table. The same content is likely to be published over and over again by the CI builds, so deduplicating the content saves us a lot of disk space. Once created, a row is never modified.
7
+
8
+ * `pact_revisions` - this table holds references to the:
9
+
10
+ * `provider` (in the pacticipants table)
11
+ * `consumer version` (in the versions table),
12
+ * `pact content` (in the pact_version_contents table)
13
+ * and a `revision number`
14
+
15
+ A row exists for every `PUT` or `PATCH` request made to create or update a given pact resource. Once created, a row is never modified. When a pact resource (defined by the `provider`, `consumer` and `consumer version number`) is modified via HTTP, a new `pact_revision` row is created with an incremented `revision_number`. The `revision_number` begins at 1 for each new `consumer_version`.
16
+
17
+ * `versions` - this table consists of:
18
+
19
+ * a reference to the `pacticipant` that owns the version (the `consumer`)
20
+ * the version `number` (eg. 1.0.2)
21
+ * the version `order` - an integer calculated by the code when the row is created that allows us to sort versions in the database without it needing to understand how to order semantic version strings. The versions are ordered within the context of their owning `pacticipant`.
22
+
23
+ Currently only consumer versions are stored, as these are created when a pact resource is created. There is potential to create provider versions when we implement verifications.
24
+
25
+ * `pacticipants` - this table consists of:
26
+
27
+ * a `name`
28
+
29
+ * `tags` - this table consists of:
30
+
31
+ * a `name`
32
+ * a reference to the `pacticipant version`
33
+
34
+ Note that a `consumer version` is tagged, rather than a `pact_version`. This means that when a given version is marked as the "prod" one, all the pacts for that version are considered the "prod" pacts, rather than having to tag them individually.
35
+
36
+ ### Views
37
+
38
+ * `all_pact_revisions` - A denormalised view the one-to-one attributes of a `pact_revision`, including:
39
+
40
+ * `provider name` and `provider id`
41
+ * `consumer name` and `consumer id`
42
+ * `consumer version number` and `consumer version order`
43
+ * `revision_number`
44
+
45
+ * `all_pacts` - This view has the same columns as `all_pact_revisions`, but it only contains the latest (current) revision of the pact for each provider/consumer/version. It maps to what a user would consider the "pact" resource ie. `/pacts/provider/Provider/consumer/Consumer/version/1.2.3`
46
+
47
+ The AllPacts Sequel model in the code is what is used when querying data for displaying in a response, rather than the normalised separate PactRevision and PactVersionContent models.
48
+
49
+ * `latest_pacts` - This view has the same columns as `all_pact_revisions`, but it only contains the latest revision of the pact for the latest consumer version for each consumer/provider pair. It is what a user would consider the "latest pact", and maps to the resource at `/pacts/provider/Provider/consumer/Consumer/latest`
50
+
51
+ * `latest_tagged_pacts` - This view has the same columns as `all_pact_revisions`, plus a `tag_name` column. It is used to return the pact for the latest tagged version of a consumer.
52
+
53
+ * `latest_verifications` - The most recent verification for each pact version.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Pact Broker
2
2
 
3
- [![Build Status](https://travis-ci.org/pact-foundation/pact_broker.svg?branch=master)](https://travis-ci.org/pact-foundation/pact_broker) [![Join the chat at https://gitter.im/pact-foundation/pact_broker](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/pact-foundation/pact_broker?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
3
+ [![Build Status](https://travis-ci.org/bethesque/pact_broker.svg?branch=master)](https://travis-ci.org/bethesque/pact_broker) [![Join the chat at https://gitter.im/bethesque/pact_broker](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/bethesque/pact_broker?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
4
 
5
5
  The Pact Broker provides a repository for consumer driven contracts created using the pact gem.
6
6
 
@@ -23,7 +23,7 @@ Features:
23
23
  * Tracks changes between Pact versions so you can tell when a consumer has changed its expectations.
24
24
  * [Docker Pact Broker][docker]
25
25
 
26
- Travis CI Status: [![Build Status](https://travis-ci.org/pact-foundation/pact_broker.svg?branch=master)](https://travis-ci.org/pact-foundation/pact_broker)
26
+ Travis CI Status: [![Build Status](https://travis-ci.org/bethesque/pact_broker.svg?branch=master)](https://travis-ci.org/bethesque/pact_broker)
27
27
 
28
28
  ### How would I use the Pact Broker?
29
29
 
@@ -41,47 +41,47 @@ If you don't have a [Pact Broker CI Nerf Gun][nerf], you'll probably want to rea
41
41
 
42
42
  ## Documentation
43
43
 
44
- See the [Pact Broker Client](https://github.com/pact-foundation/pact_broker-client) for documentation on how to publish a pact to the Pact Broker, and configure the URLs in the provider project.
44
+ See the [Pact Broker Client](https://github.com/bethesque/pact_broker-client) for documentation on how to publish a pact to the Pact Broker, and configure the URLs in the provider project.
45
45
 
46
- See the [wiki](https://github.com/pact-foundation/pact_broker/wiki) for documentation related to the Pact Broker itself.
46
+ See the [wiki](https://github.com/bethesque/pact_broker/wiki) for documentation related to the Pact Broker itself.
47
47
 
48
48
  ### Screenshots
49
49
 
50
50
  #### Index
51
51
 
52
52
  * * *
53
- <img src="https://raw.githubusercontent.com/wiki/pact-foundation/pact_broker/images/index.png"/>
53
+ <img src="https://raw.githubusercontent.com/wiki/bethesque/pact_broker/images/index.png"/>
54
54
 
55
55
  #### Autogenerated documentation
56
56
 
57
57
  Paste the pact URL into a browser to view a HTML version of the pact.
58
58
  * * *
59
- <img src="https://raw.githubusercontent.com/wiki/pact-foundation/pact_broker/images/autogenerated_documentation.png"/>
59
+ <img src="https://raw.githubusercontent.com/wiki/bethesque/pact_broker/images/autogenerated_documentation.png"/>
60
60
 
61
61
 
62
62
  #### Network diagram
63
63
 
64
64
  * * *
65
- <img src="https://raw.githubusercontent.com/wiki/pact-foundation/pact_broker/images/network_diagram.png"/>
65
+ <img src="https://raw.githubusercontent.com/wiki/bethesque/pact_broker/images/network_diagram.png"/>
66
66
 
67
67
  #### HAL browser
68
68
 
69
69
  Use the embedded HAL browser to navigate the API.
70
70
  * * *
71
- <img src="https://raw.githubusercontent.com/wiki/pact-foundation/pact_broker/images/hal_browser.png"/>
71
+ <img src="https://raw.githubusercontent.com/wiki/bethesque/pact_broker/images/hal_browser.png"/>
72
72
 
73
73
  #### HAL documentation
74
74
 
75
75
  Use the HAL browser to view documentation as you browse.
76
76
  * * *
77
- <img src="https://raw.githubusercontent.com/wiki/pact-foundation/pact_broker/images/hal_documentation.png"/>
77
+ <img src="https://raw.githubusercontent.com/wiki/bethesque/pact_broker/images/hal_documentation.png"/>
78
78
 
79
79
  ## Usage
80
80
 
81
81
  ### To have a play around on your local machine
82
82
 
83
83
  * Install ruby 2.2.0 or later and bundler >= 1.12.0
84
- * Run `git clone git@github.com:pact-foundation/pact_broker.git && cd pact_broker/example`
84
+ * Run `git clone git@github.com:bethesque/pact_broker.git && cd pact_broker/example`
85
85
  * Run `bundle`
86
86
  * Run `bundle exec rackup -p 8080`
87
87
  * Open [http://localhost:8080](http://localhost:8080) and you should see a list containing the pact between the Zoo App and the Animal Service.
@@ -100,7 +100,7 @@ the [Hosted Pact Broker](https://pact.dius.com.au/?utm_source=github&utm_campaig
100
100
  You can use the [Pact Broker Docker container][docker] or [Terraform on AWS][terraform] or to roll your own...
101
101
 
102
102
  * Create a database using a product that is supported by the Sequel gem (listed on this page http://sequel.jeremyevans.net/rdoc/files/README_rdoc.html). The migrations have been tested on MySQL and PostgreSQL - your mileage will vary on other databases.
103
- * __Note:__ It is recommended to use __PostgreSQL__ as it will support JSON search features that are planned in a future release, however MySQL the other [semi supported](https://github.com/pact-foundation/pact_broker/issues/33) database.
103
+ * __Note:__ It is recommended to use __PostgreSQL__ as it will support JSON search features that are planned in a future release, however MySQL the other [semi supported](https://github.com/bethesque/pact_broker/issues/33) database.
104
104
  * Install ruby 2.2.0 or later and bundler >= 1.12.0
105
105
  * Copy the [example](/example) directory to the location you want to install the application.
106
106
  * Modify the config.ru and Gemfile as desired (eg. choose database driver gem, set your database credentials. Use the "pg" gem if using Postgres.)
@@ -110,7 +110,7 @@ You can use the [Pact Broker Docker container][docker] or [Terraform on AWS][ter
110
110
 
111
111
  [decouple]: http://techblog.realestate.com.au/enter-the-pact-matrix-or-how-to-decouple-the-release-cycles-of-your-microservices/
112
112
  [pact]: https://github.com/realestate-com-au/pact
113
- [nerf]: https://github.com/pact-foundation/pact_broker/wiki/pact-broker-ci-nerf-gun
113
+ [nerf]: https://github.com/bethesque/pact_broker/wiki/pact-broker-ci-nerf-gun
114
114
  [different-teams]: https://github.com/realestate-com-au/pact/wiki/Using-pact-where-the-consumer-team-is-different-from-the-provider-team
115
- [docker]: https://hub.docker.com/r/dius/pact-broker
115
+ [docker]: https://registry.hub.docker.com/u/dius/pact_broker/
116
116
  [terraform]: https://github.com/nadnerb/terraform-pact-broker
@@ -0,0 +1,19 @@
1
+ require_relative 'migration_helper'
2
+
3
+ Sequel.migration do
4
+ up do
5
+ create_table(:pact_contents, charset: 'utf8') do
6
+ primary_key :id
7
+ foreign_key :consumer_id, :pacticipants
8
+ foreign_key :provider_id, :pacticipants
9
+ String :sha, null: false
10
+ String :content, type: PactBroker::MigrationHelper.large_text_type
11
+ index [:consumer_id, :provider_id, :sha], unique: true, name: 'unq_pvc_con_prov_sha'
12
+ DateTime :created_at, null: false
13
+ end
14
+ end
15
+
16
+ down do
17
+ drop_table(:pact_contents)
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ Sequel.migration do
2
+ up do
3
+ run("insert into pact_contents (sha, content, created_at) select sha, content, created_at from pact_version_contents")
4
+ end
5
+
6
+ down do
7
+ run("delete from pact_contents")
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ Sequel.migration do
2
+ up do
3
+ run("update pact_contents set consumer_id = (select consumer_id from all_pacts where pact_version_content_sha = pact_contents.sha limit 1)")
4
+ run("update pact_contents set provider_id = (select provider_id from all_pacts where pact_version_content_sha = pact_contents.sha limit 1)")
5
+ run("delete from pact_contents where consumer_id is null")
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ Sequel.migration do
2
+ up do
3
+ alter_table(:pact_contents) do
4
+ set_column_not_null(:consumer_id)
5
+ set_column_not_null(:provider_id)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,18 @@
1
+ Sequel.migration do
2
+ up do
3
+ create_table(:pact_publications, charset: 'utf8') do
4
+ primary_key :id
5
+ foreign_key :consumer_version_id, :versions, null: false
6
+ foreign_key :provider_id, :pacticipants, null: false
7
+ Integer :revision_number, null: false
8
+ foreign_key :pact_version_id, :pact_contents, null: false
9
+ DateTime :created_at, null: false
10
+ index [:consumer_version_id, :provider_id, :revision_number], unique: true, name: 'cv_prov_revision_unq'
11
+ index [:consumer_version_id, :provider_id, :id], name: 'cv_prov_id_ndx'
12
+ end
13
+ end
14
+
15
+ down do
16
+ drop_table(:pact_publications)
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ Sequel.migration do
2
+ up do
3
+ run("insert into pact_publications
4
+ (id, consumer_version_id, provider_id, revision_number, pact_version_id, created_at)
5
+ select ap.id, ap.consumer_version_id, ap.provider_id, 1, pc.id, ap.updated_at
6
+ from all_pacts ap inner join pact_contents pc
7
+ on pc.sha = ap.pact_version_content_sha")
8
+ end
9
+
10
+ down do
11
+ run("delete from pact_publications")
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ Sequel.migration do
2
+ up do
3
+ create_or_replace_view(:all_pacts,
4
+ Sequel::Model.db[:pact_publications].select(:pact_publications__id,
5
+ :c__id___consumer_id, :c__name___consumer_name,
6
+ :cv__id___consumer_version_id, :cv__number___consumer_version_number, :cv__order___consumer_version_order,
7
+ :p__id___provider_id, :p__name___provider_name,
8
+ :pact_publications__revision_number, :pc__sha___pact_version_sha, :pact_publications__created_at).
9
+ join(:versions, {:id => :consumer_version_id}, {:table_alias => :cv, implicit_qualifier: :pact_publications}).
10
+ join(:pacticipants, {:id => :pacticipant_id}, {:table_alias => :c, implicit_qualifier: :cv}).
11
+ join(:pacticipants, {:id => :provider_id}, {:table_alias => :p, implicit_qualifier: :pact_publications}).
12
+ join(:pact_contents, {:id => :pact_version_id}, {:table_alias => :pc, implicit_qualifier: :pact_publications})
13
+ )
14
+ end
15
+ end
16
+
@@ -0,0 +1,8 @@
1
+ require 'digest/sha1'
2
+ require_relative 'migration_helper'
3
+
4
+ Sequel.migration do
5
+ up do
6
+ drop_table(:pacts)
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ Sequel.migration do
2
+ up do
3
+ drop_table(:pact_version_contents)
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ Sequel.migration do
2
+ up do
3
+ rename_table(:pact_contents, :pact_versions)
4
+ end
5
+ end
@@ -0,0 +1,52 @@
1
+ Sequel.migration do
2
+ up do
3
+ # The denormalised pact publication details for each publication
4
+ create_or_replace_view(:all_pact_publications,
5
+ Sequel::Model.db[:pact_publications].select(:pact_publications__id,
6
+ :c__id___consumer_id, :c__name___consumer_name,
7
+ :cv__id___consumer_version_id, :cv__number___consumer_version_number, :cv__order___consumer_version_order,
8
+ :p__id___provider_id, :p__name___provider_name,
9
+ :pact_publications__revision_number, :pv__id___pact_version_id, :pv__sha___pact_version_sha, :pact_publications__created_at).
10
+ join(:versions, {:id => :consumer_version_id}, {:table_alias => :cv, implicit_qualifier: :pact_publications}).
11
+ join(:pacticipants, {:id => :pacticipant_id}, {:table_alias => :c, implicit_qualifier: :cv}).
12
+ join(:pacticipants, {:id => :provider_id}, {:table_alias => :p, implicit_qualifier: :pact_publications}).
13
+ join(:pact_versions, {:id => :pact_version_id}, {:table_alias => :pv, implicit_qualifier: :pact_publications})
14
+ )
15
+
16
+ # Latest revision number for each consumer version order
17
+ create_or_replace_view(:latest_pact_publication_revision_numbers,
18
+ "select provider_id, consumer_id, consumer_version_order, max(revision_number) as latest_revision_number
19
+ from all_pact_publications
20
+ group by provider_id, consumer_id, consumer_version_order"
21
+ )
22
+
23
+ # Latest pact_publication details for each consumer version
24
+ create_or_replace_view(:latest_pact_publications_by_consumer_versions,
25
+ "select app.*
26
+ from all_pact_publications app
27
+ inner join latest_pact_publication_revision_numbers lr
28
+ on app.consumer_id = lr.consumer_id
29
+ and app.provider_id = lr.provider_id
30
+ and app.consumer_version_order = lr.consumer_version_order
31
+ and app.revision_number = lr.latest_revision_number"
32
+ )
33
+
34
+
35
+ create_or_replace_view(:latest_pact_consumer_version_orders,
36
+ "select provider_id, consumer_id, max(consumer_version_order) as latest_consumer_version_order
37
+ from all_pact_publications
38
+ group by provider_id, consumer_id"
39
+ )
40
+
41
+ # Latest pact publications by consumer/provider
42
+ create_or_replace_view(:latest_pact_publications,
43
+ "select lpcv.*
44
+ from latest_pact_publications_by_consumer_versions lpcv
45
+ inner join latest_pact_consumer_version_orders lp
46
+ on lpcv.consumer_id = lp.consumer_id
47
+ and lpcv.provider_id = lp.provider_id
48
+ and lpcv.consumer_version_order = latest_consumer_version_order"
49
+ )
50
+
51
+ end
52
+ end
@@ -0,0 +1,23 @@
1
+ Sequel.migration do
2
+ up do
3
+ create_or_replace_view(:latest_tagged_pact_consumer_version_orders,
4
+ "select provider_id, consumer_id, t.name as tag_name, max(consumer_version_order) as latest_consumer_version_order
5
+ from latest_pact_publications_by_consumer_versions ap
6
+ inner join tags t
7
+ on t.version_id = ap.consumer_version_id
8
+ group by provider_id, consumer_id, t.name"
9
+ )
10
+
11
+ create_or_replace_view(:latest_tagged_pact_publications,
12
+ "select lp.*, o.tag_name
13
+ from latest_pact_publications_by_consumer_versions lp
14
+ inner join latest_tagged_pact_consumer_version_orders o
15
+ on lp.consumer_id = o.consumer_id
16
+ and lp.provider_id = o.provider_id
17
+ and lp.consumer_version_order = latest_consumer_version_order"
18
+ )
19
+
20
+ drop_view(:all_pacts)
21
+ drop_view(:latest_pacts)
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ Sequel.migration do
2
+ up do
3
+ create_table(:verifications, charset: 'utf8') do
4
+ primary_key :id
5
+ Integer :number
6
+ Boolean :success, null: false
7
+ String :provider_version, null: false
8
+ String :build_url
9
+ foreign_key :pact_version_id, :pact_versions, null: false
10
+ DateTime :execution_date, null: false
11
+ DateTime :created_at, null: false
12
+ index [:pact_version_id, :number], unique: true
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ Sequel.migration do
2
+ up do
3
+ # The most recent verification for each pact version
4
+ create_or_replace_view(:latest_verifications,
5
+ "SELECT v.id, v.number, v.success, v.provider_version, v.build_url, v.pact_version_id, v.execution_date, v.created_at
6
+ FROM verifications v
7
+ INNER JOIN (
8
+ SELECT pact_version_id, MAX(number) latest_number
9
+ FROM verifications
10
+ GROUP BY pact_version_id
11
+ ) lv ON v.pact_version_id = lv.pact_version_id AND v.number = lv.latest_number"
12
+ )
13
+ end
14
+ end
Binary file
@@ -23,6 +23,8 @@ require 'pact_broker/api/resources/versions'
23
23
  require 'pact_broker/api/resources/pact_content_diff'
24
24
  require 'pact_broker/api/resources/previous_distinct_pact_version'
25
25
  require 'pact_broker/api/resources/latest_provider_pacts'
26
+ require 'pact_broker/api/resources/verifications'
27
+ require 'pact_broker/api/resources/latest_verifications_for_consumer_version'
26
28
 
27
29
  require 'webmachine/adapters/rack_mapped'
28
30
 
@@ -32,33 +34,46 @@ module PactBroker
32
34
  pact_api = Webmachine::Application.new do |app|
33
35
  app.routes do
34
36
  add(['trace', :*], Webmachine::Trace::TraceResource) unless ENV['RACK_ENV'] == 'production'
35
- # Support both /pact and /pacts
36
- # /pact will be deprecated
37
- # Todo, rename /version/ to /versions
38
- add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'latest'], Api::Resources::LatestPact
39
- add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'latest', :tag], Api::Resources::LatestPact
40
- add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'version', :consumer_version_number], Api::Resources::Pact
41
- add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'versions', :consumer_version_number], Api::Resources::Pact # Not the standard URL, but keep for backwards compatibility
37
+
42
38
  add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'versions'], Api::Resources::PactVersions
39
+ add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'versions', :consumer_version_number], Api::Resources::Pact # Not the standard URL, but keep for backwards compatibility
40
+
41
+ # Pacts
42
+ add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'version', :consumer_version_number], Api::Resources::Pact
43
43
  add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'version', :consumer_version_number, 'previous-distinct'], Api::Resources::PreviousDistinctPactVersion
44
44
  add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'version', :consumer_version_number, 'diff', 'previous-distinct'], Api::Resources::PactContentDiff
45
+
46
+ # Verifications
47
+ add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'pact-version', :pact_version_sha, 'verifications'], Api::Resources::Verifications
48
+ add ['pacts', 'consumer', :consumer_name, 'versions', :consumer_version_number, 'verifications', 'latest'], Api::Resources::LatestVerificationsForConsumerVersion
49
+
50
+ # Latest pacts
51
+ add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'latest'], Api::Resources::LatestPact
52
+ add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'latest', :tag], Api::Resources::LatestPact
45
53
  add ['pacts', 'provider', :provider_name, 'latest'], Api::Resources::LatestProviderPacts
46
54
  add ['pacts', 'provider', :provider_name, 'latest', :tag], Api::Resources::LatestProviderPacts
55
+ add ['pacts', 'latest'], Api::Resources::LatestPacts
47
56
 
57
+ # Deprecated pact
48
58
  add ['pact', 'provider', :provider_name, 'consumer', :consumer_name, 'version', :consumer_version_number], Api::Resources::Pact # Deprecate, singular /pact
49
59
  add ['pact', 'provider', :provider_name, 'consumer', :consumer_name, 'latest'], Api::Resources::LatestPact
50
- add ['pacts', 'latest'], Api::Resources::LatestPacts
60
+
61
+ # Pacticipants
51
62
  add ['pacticipants'], Api::Resources::Pacticipants
52
63
  add ['pacticipants', :name], Api::Resources::Pacticipant
53
64
  add ['pacticipants', :pacticipant_name, 'versions'], Api::Resources::Versions
54
65
  add ['pacticipants', :pacticipant_name, 'versions', :pacticipant_version_number], Api::Resources::Version
55
66
  add ['pacticipants', :pacticipant_name, 'versions', :pacticipant_version_number, 'tags', :tag_name], Api::Resources::Tag
56
- add ['relationships'], Api::Resources::Relationships
57
- add ['groups', :pacticipant_name], Api::Resources::Group
67
+
68
+ # Webhooks
58
69
  add ['webhooks', 'provider', :provider_name, 'consumer', :consumer_name ], Api::Resources::PactWebhooks
59
70
  add ['webhooks', :uuid ], Api::Resources::Webhook
60
71
  add ['webhooks', :uuid, 'execute' ], Api::Resources::WebhookExecution
61
72
  add ['webhooks'], Api::Resources::Webhooks
73
+
74
+ add ['relationships'], Api::Resources::Relationships
75
+ add ['groups', :pacticipant_name], Api::Resources::Group
76
+
62
77
  add [], Api::Resources::Index
63
78
  end
64
79
  end