pact_broker 2.76.2 → 2.77.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +12 -0
  3. data/.github/workflows/test-ruby-3.yml +19 -0
  4. data/.github/workflows/test.yml +16 -7
  5. data/.gitignore +3 -1
  6. data/CHANGELOG.md +15 -0
  7. data/DEVELOPER_SETUP.md +62 -3
  8. data/Dockerfile +1 -0
  9. data/ISSUES.md +7 -7
  10. data/config.ru +1 -0
  11. data/db/ddl_statements/head_pact_tags.rb +24 -1
  12. data/db/ddl_statements/latest_tagged_pact_consumer_version_orders.rb +11 -0
  13. data/db/ddl_statements/latest_tagged_pact_publications.rb +6 -0
  14. data/db/ddl_statements/latest_verification_ids_for_consumer_version_tags.rb +13 -0
  15. data/db/migrations/20210117_add_branch_to_version.rb +9 -0
  16. data/db/migrations/20210202_add_created_at_to_head_pact_tags.rb +14 -0
  17. data/db/migrations/20210205_add_pacticipant_id_to_tag.rb +17 -0
  18. data/db/migrations/20210206_add_index_to_tags_and_versions.rb +27 -0
  19. data/db/migrations/20210207_optimise_latest_verification_ids_for_consumer_version_tags.rb +13 -0
  20. data/db/migrations/20210208_optimise_latest_tagged_pact_cv_orders.rb +13 -0
  21. data/lib/pact_broker/api.rb +2 -2
  22. data/lib/pact_broker/api/decorators/dashboard_decorator.rb +5 -1
  23. data/lib/pact_broker/api/decorators/matrix_decorator.rb +3 -1
  24. data/lib/pact_broker/api/decorators/verifiable_pacts_query_decorator.rb +2 -0
  25. data/lib/pact_broker/api/decorators/version_decorator.rb +4 -2
  26. data/lib/pact_broker/api/resources/default_base_resource.rb +4 -0
  27. data/lib/pact_broker/api/resources/index.rb +6 -0
  28. data/lib/pact_broker/api/resources/latest_version.rb +27 -0
  29. data/lib/pact_broker/api/resources/provider_pacts_for_verification.rb +1 -0
  30. data/lib/pact_broker/api/resources/version.rb +15 -9
  31. data/lib/pact_broker/certificates/certificate.rb +1 -1
  32. data/lib/pact_broker/config/setting.rb +1 -1
  33. data/lib/pact_broker/config/space_delimited_integer_list.rb +25 -0
  34. data/lib/pact_broker/configuration.rb +17 -1
  35. data/lib/pact_broker/db/data_migrations/helpers.rb +4 -0
  36. data/lib/pact_broker/db/data_migrations/set_extra_columns_for_tags.rb +29 -0
  37. data/lib/pact_broker/db/migrate_data.rb +1 -0
  38. data/lib/pact_broker/db/seed_example_data.rb +13 -13
  39. data/lib/pact_broker/doc/views/index/pacticipant-version.markdown +13 -0
  40. data/lib/pact_broker/domain/index_item.rb +18 -4
  41. data/lib/pact_broker/domain/pacticipant.rb +9 -5
  42. data/lib/pact_broker/domain/tag.rb +131 -71
  43. data/lib/pact_broker/domain/verification.rb +3 -2
  44. data/lib/pact_broker/domain/version.rb +58 -23
  45. data/lib/pact_broker/domain/webhook.rb +6 -3
  46. data/lib/pact_broker/index/service.rb +55 -49
  47. data/lib/pact_broker/matrix/quick_row.rb +8 -0
  48. data/lib/pact_broker/metrics/service.rb +1 -1
  49. data/lib/pact_broker/pacts/eager_loaders.rb +52 -0
  50. data/lib/pact_broker/pacts/latest_pact_publication_id_for_consumer_version.rb +18 -13
  51. data/lib/pact_broker/pacts/lazy_loaders.rb +14 -0
  52. data/lib/pact_broker/pacts/pact_publication.rb +38 -84
  53. data/lib/pact_broker/pacts/pact_publication_dataset_module.rb +297 -0
  54. data/lib/pact_broker/pacts/pact_version.rb +1 -2
  55. data/lib/pact_broker/pacts/pacts_for_verification_repository.rb +286 -0
  56. data/lib/pact_broker/pacts/repository.rb +5 -240
  57. data/lib/pact_broker/pacts/selected_pact.rb +4 -0
  58. data/lib/pact_broker/pacts/selector.rb +56 -1
  59. data/lib/pact_broker/pacts/selectors.rb +16 -0
  60. data/lib/pact_broker/pacts/service.rb +2 -6
  61. data/lib/pact_broker/pacts/squash_pacts_for_verification.rb +1 -4
  62. data/lib/pact_broker/pacts/verifiable_pact.rb +23 -2
  63. data/lib/pact_broker/pacts/verifiable_pact_messages.rb +56 -16
  64. data/lib/pact_broker/repositories/helpers.rb +4 -0
  65. data/lib/pact_broker/tags/eager_loaders.rb +47 -0
  66. data/lib/pact_broker/tags/repository.rb +3 -1
  67. data/lib/pact_broker/tags/service.rb +0 -3
  68. data/lib/pact_broker/tags/tag_with_latest_flag.rb +1 -0
  69. data/lib/pact_broker/test/http_test_data_builder.rb +23 -7
  70. data/lib/pact_broker/test/test_data_builder.rb +36 -3
  71. data/lib/pact_broker/ui/view_models/index_item.rb +9 -0
  72. data/lib/pact_broker/ui/view_models/matrix_line.rb +36 -0
  73. data/lib/pact_broker/ui/views/index/show-with-tags.haml +8 -0
  74. data/lib/pact_broker/ui/views/matrix/show.haml +10 -0
  75. data/lib/pact_broker/verifications/latest_verification_id_for_pact_version_and_provider_version.rb +7 -5
  76. data/lib/pact_broker/version.rb +1 -1
  77. data/lib/pact_broker/versions/eager_loaders.rb +71 -0
  78. data/lib/pact_broker/versions/lazy_loaders.rb +13 -0
  79. data/lib/pact_broker/versions/repository.rb +11 -2
  80. data/lib/pact_broker/versions/service.rb +5 -1
  81. data/lib/pact_broker/webhooks/execution.rb +3 -2
  82. data/lib/pact_broker/webhooks/latest_triggered_webhook.rb +2 -0
  83. data/lib/pact_broker/webhooks/triggered_webhook.rb +11 -4
  84. data/lib/pact_broker/webhooks/webhook.rb +1 -1
  85. data/lib/pact_broker/webhooks/webhook_event.rb +1 -1
  86. data/lib/pact_broker/webhooks/webhook_request_logger.rb +5 -1
  87. data/lib/sequel/plugins/upsert.rb +18 -4
  88. data/public/stylesheets/index.css +22 -1
  89. data/public/stylesheets/matrix.css +0 -21
  90. data/regression/can_i_deploy_spec.rb +5 -4
  91. data/regression/index_spec.rb +26 -0
  92. data/regression/regression_helper.rb +29 -3
  93. data/regression/script/clear.sh +3 -0
  94. data/regression/script/run.sh +3 -0
  95. data/script/demonstrate-version-branches.rb +33 -0
  96. data/script/pry.rb +2 -2
  97. data/spec/features/create_version_spec.rb +44 -0
  98. data/spec/fixtures/dashboard.json +4 -2
  99. data/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb +4 -2
  100. data/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb +11 -6
  101. data/spec/lib/pact_broker/api/decorators/verifiable_pacts_query_decorator_spec.rb +6 -0
  102. data/spec/lib/pact_broker/api/resources/provider_pacts_for_verification_spec.rb +4 -0
  103. data/spec/lib/pact_broker/config/space_delimited_integer_list_spec.rb +47 -0
  104. data/spec/lib/pact_broker/configuration_spec.rb +12 -0
  105. data/spec/lib/pact_broker/domain/tag_spec.rb +101 -27
  106. data/spec/lib/pact_broker/domain/version_spec.rb +103 -15
  107. data/spec/lib/pact_broker/domain/webhook_spec.rb +1 -1
  108. data/spec/lib/pact_broker/index/service_spec.rb +89 -15
  109. data/spec/lib/pact_broker/pacts/pact_publication_dataset_module_spec.rb +400 -0
  110. data/spec/lib/pact_broker/pacts/pact_publication_spec.rb +434 -14
  111. data/spec/lib/pact_broker/pacts/repository_find_for_verification_fallback_spec.rb +1 -1
  112. data/spec/lib/pact_broker/pacts/repository_find_for_verification_spec.rb +1 -1
  113. data/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_branch_spec.rb +224 -0
  114. data/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_spec.rb +20 -7
  115. data/spec/lib/pact_broker/pacts/selector_spec.rb +3 -2
  116. data/spec/lib/pact_broker/pacts/service_find_for_verification_spec.rb +2 -3
  117. data/spec/lib/pact_broker/pacts/service_spec.rb +2 -2
  118. data/spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb +57 -10
  119. data/spec/lib/pact_broker/tags/repository_spec.rb +2 -0
  120. data/spec/lib/pact_broker/versions/repository_spec.rb +44 -0
  121. data/spec/lib/pact_broker/webhooks/webhook_request_logger_spec.rb +8 -0
  122. data/spec/lib/sequel/plugins/upsert_spec.rb +31 -3
  123. data/spec/spec_helper.rb +17 -5
  124. data/spec/support/approvals.rb +24 -0
  125. data/tasks/db.rake +1 -0
  126. data/tasks/rspec.rake +1 -1
  127. metadata +36 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cdc8ed42038e4b622005f53471a000d870efd99a6dbd6b773aa9e8a3f9a993cb
4
- data.tar.gz: d2f42cd3e13007471cdd33fabbe515afa9c9ff4896566868accd9961f66f557f
3
+ metadata.gz: caab9fa9fc2bef074e4523e89122015a55d85572df00564956dc25553273f095
4
+ data.tar.gz: aa1638d95186e934c08cac4d5842c8e10c762b95e9db1f5f9e3ca3c4533dbde4
5
5
  SHA512:
6
- metadata.gz: a250f5f452356d3a9eb87659933cc47d0e947b7ce10a8c984d7cd296a28bc9be7dcfe82bd37fba29919f570a949b9b4a46b1622d6d242b92698268e54018aadf
7
- data.tar.gz: c136cbe836ed813de2819480cf3347de86248f00258e0f8e89ec33375cf0c929186a65c51ef620995c11d2c596d496bec858c430894f80bacd6f647877f4af3e
6
+ metadata.gz: 82a534408c7557f0dd8b5a605d3c68da1d79d8dabaefb721608ff99a4fcb16e6e04815d5b2286fc50d87dce99c8170eebcef653e46d4b423f4048ffeccce0075
7
+ data.tar.gz: fdb5a29c0ccdb0dce1d60ea7853925154a1d82384fd2c720a46a612b2a20f173ce65f08f67349d6095e6f2ca8f14721d660c2b4a35ca77a3ce3e7e8c9fb12269
data/.codeclimate.yml CHANGED
@@ -1,4 +1,13 @@
1
1
  ---
2
+ checks:
3
+ argument-count:
4
+ config:
5
+ threshold: 6
6
+ method-count:
7
+ config:
8
+ threshold: 40
9
+ similar-code:
10
+ enabled: false
2
11
  engines:
3
12
  csslint:
4
13
  enabled: true
@@ -35,3 +44,6 @@ exclude_patterns:
35
44
  - public/javascripts/highlight.pack.js
36
45
  - public/javascripts/jquery*.js
37
46
  - public/js/bootstrap*.js
47
+ - public/javascripts/pagination.js
48
+ - public/javascripts/material-menu.js
49
+
@@ -0,0 +1,19 @@
1
+ name: Tests for Ruby 3.0 - these are hardcoded to succeed so every commit doesn't look like it's failing
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ sqlite:
7
+ if: "!contains(github.event.head_commit.message, '[ci-skip]')"
8
+ runs-on: "ubuntu-latest"
9
+ strategy:
10
+ fail-fast: false
11
+ matrix:
12
+ ruby_version: ["3.0"]
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby_version }}
18
+ - run: "bundle install"
19
+ - run: "bundle exec rake || true"
@@ -1,29 +1,36 @@
1
1
  name: Test
2
2
 
3
- on: push
3
+ on: [push, pull_request]
4
4
 
5
5
  jobs:
6
6
  sqlite:
7
+ if: "!contains(github.event.head_commit.message, '[ci-skip]')"
7
8
  runs-on: "ubuntu-latest"
8
- continue-on-error: ${{ matrix.experimental }}
9
9
  strategy:
10
10
  fail-fast: false
11
11
  matrix:
12
12
  ruby_version: ["2.7"]
13
- experimental: [false]
14
- include:
15
- - ruby_version: "3.0"
16
- experimental: true
17
13
  steps:
18
14
  - uses: actions/checkout@v2
19
15
  - uses: ruby/setup-ruby@v1
20
16
  with:
21
17
  ruby-version: ${{ matrix.ruby_version }}
22
18
  - run: "bundle install"
23
- - run: "bundle exec rake"
19
+ - name: "Install CodeClimate Test Reporter"
20
+ run: |
21
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
22
+ chmod +x ./cc-test-reporter
23
+ - name: Tests
24
+ run: bundle exec rake
25
+ - name: Report test coverage
26
+ run: ./cc-test-reporter after-build --exit-code 0 || true
27
+ env:
28
+ CC_TEST_REPORTER_ID: dc2c30b67c9e2a5309e1aef699c30fdab55ba4f0e4f1beac029ba93e293835db
24
29
  postgres:
30
+ if: "!contains(github.event.head_commit.message, '[ci-skip]')"
25
31
  runs-on: "ubuntu-latest"
26
32
  strategy:
33
+ fail-fast: false
27
34
  matrix:
28
35
  ruby_version: ["2.5", "2.7"]
29
36
  services:
@@ -51,8 +58,10 @@ jobs:
51
58
  DATABASE_ADAPTER: github_actions_postgres
52
59
  INSTALL_PG: "true"
53
60
  mysql:
61
+ if: "!contains(github.event.head_commit.message, '[ci-skip]')"
54
62
  runs-on: "ubuntu-latest"
55
63
  strategy:
64
+ fail-fast: false
56
65
  matrix:
57
66
  ruby_version: ["2.7"]
58
67
  steps:
data/.gitignore CHANGED
@@ -39,4 +39,6 @@ db/test/change_migration_strategy/pact_broker_database.sqlite3
39
39
  coverage
40
40
  db/test/backwards_compatibility/pids
41
41
  db/test/backwards_compatibility/pact_broker_database.sqlite3
42
- spec/examples.txt
42
+ spec/examples.txt
43
+ .approvals
44
+ regression/fixtures/approvals
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ <a name="v2.77.0"></a>
2
+ ### v2.77.0 (2021-02-11)
3
+
4
+ #### Features
5
+
6
+ * **webhooks**
7
+ * allow the http codes to be considered as "successful" to be configured. ([a84989b1](/../../commit/a84989b1))
8
+
9
+ * add duplicate columns to tags table to reduce joins ([5ca9de62](/../../commit/5ca9de62))
10
+ * set the branch in the seed data ([9a00ce6d](/../../commit/9a00ce6d))
11
+ * display version branch on index and matrix pages ([2057df7d](/../../commit/2057df7d))
12
+ * support creating version with branch (#371) ([5884a047](/../../commit/5884a047))
13
+ * sort tags on index and matrix pages and APIs by creation date ([91590718](/../../commit/91590718))
14
+ * sort consumer version tags by date in dashboard response ([f82ba1bc](/../../commit/f82ba1bc))
15
+
1
16
  <a name="v2.76.2"></a>
2
17
  ### v2.76.2 (2021-01-29)
3
18
 
data/DEVELOPER_SETUP.md CHANGED
@@ -36,7 +36,7 @@ Remember to rebuild the image if you change any of the gems or gem versions.
36
36
 
37
37
  ### With native install
38
38
 
39
- * You will need to install Ruby 2.5, and preferably a ruby version manager. I recommend using [chruby][chruby] and [ruby-install][ruby-install].
39
+ * You will need to install Ruby 2.7, and preferably a ruby version manager. I recommend using [chruby][chruby] and [ruby-install][ruby-install].
40
40
  * Install bundler (the Ruby gem dependency manager) `gem install bundler`
41
41
  * Check out the pact_broker repository and cd into it.
42
42
  * Run `bundle install`. If you have any gem conflict issues, run `bundle update`.
@@ -75,17 +75,27 @@ Running a mysql client in the mysql-tests container:
75
75
  mysql -hmysql -upact_broker -ppact_broker
76
76
  ```
77
77
 
78
+ Running a postgresql client in the postgres-tests container:
79
+
80
+ ```
81
+ psql postgres://postgres:postgres@postgres/postgres
82
+ ```
83
+
78
84
  ## Running the tests
79
85
 
80
86
  * To run everything (specs, pact verifications, vulnerability scan...):
81
87
  ```sh
82
88
  bundle exec rake
83
89
  ```
90
+ * To set up the database (this is done automatically when running the default rake task, but if you want to run a different task without running the default task first, this must be run once beforehand):
91
+ ```sh
92
+ bundle exec rake db:prepare:test
93
+ ```
84
94
  * To run a smaller subset of the tests:
85
95
  ```sh
86
96
  bundle exec rake spec
87
97
  ```
88
- * To run the "quick tests" (skip the lengthy migration specs)
98
+ * To run the "quick tests" (skip the lengthy migration specs and db setup)
89
99
  ```sh
90
100
  bundle exec rake spec:quick
91
101
  ```
@@ -94,7 +104,56 @@ mysql -hmysql -upact_broker -ppact_broker
94
104
  bundle exec rspec path_to_your_spec.rb
95
105
  ```
96
106
 
97
- NOTE: the spec tasks requires the `db:prepare:test` task to be executed at least once prior to running.
107
+ ## Running the regression tests
108
+
109
+ The regression tests record a series of API requests/responses using a real exported database (not included in the git repository because of the size) and store the expectations in files using the Approvals gem. They allow you to make sure that the changes you have made have not made any (unexpected) changes to the interface.
110
+
111
+ The tests and files are stored in the [regression](regression) directory.
112
+
113
+ To run:
114
+
115
+ 1. Set up your local development environment as described above, making sure you have `INSTALL_PG=true` exported in your shell.
116
+
117
+ 1. Make sure you have the master branch checked out.
118
+
119
+ 1. Load an exported real database into a postgres docker image. The exported file must be in the pg dump format to use this script, and it must be located in the project root directory for it to be found via the mounted directory.
120
+
121
+ ```
122
+ script/docker/reload.sh <export>
123
+
124
+ ```
125
+ 1. Clear any previously generated approvals.
126
+
127
+ ```
128
+ regression/script/clear.sh
129
+ ```
130
+
131
+ 1. Run the tests. They will fail because there are no approval files yet.
132
+
133
+ ```
134
+ regression/script/run.sh
135
+ ```
136
+
137
+ 1. Approval all the things.
138
+
139
+ ```
140
+ regression/script/approval-all.sh
141
+ ```
142
+
143
+ 1. Run the tests again to make sure that the same results can be expected each time.
144
+
145
+ ```
146
+ regression/script/run.sh
147
+ ```
148
+
149
+ 1. Check out the feature branch (or enable the feature toggle)
150
+
151
+ 1. Run the tests again.
152
+ ```
153
+ regression/script/run.sh
154
+ ```
155
+
156
+ 1. If there is a diff, you can set `SHOW_REGRESSION_DIFF=true`, but the output is quite noisy, and you're probably better off using diff or diffmerge to view the differences.
98
157
 
99
158
  [chruby]: https://github.com/postmodern/chruby
100
159
  [ruby-install]: https://github.com/postmodern/ruby-install
data/Dockerfile CHANGED
@@ -16,6 +16,7 @@ RUN apk update \
16
16
  "tzdata>=2019" \
17
17
  "mariadb-dev>=10.3" \
18
18
  "mysql-client>=10.3.25" \
19
+ "postgresql-client>=11.10" \
19
20
  && rm -rf /var/cache/apk/*
20
21
 
21
22
  RUN apk add --no-cache openssl less
data/ISSUES.md CHANGED
@@ -2,29 +2,29 @@
2
2
 
3
3
  ## Reproducing an issue
4
4
 
5
- In [script/reproduce-issue.rb](script/reproduce-issue.rb) you will find a fluent API that allows you to simulate client libraries interacting with the Pact Broker.
5
+ In [script/reproduce-issue.rb](script/reproduce-issue.rb) you will find an example fluent API script that allows you to simulate client libraries interacting with the Pact Broker.
6
6
 
7
- You can use it to easily reproduce issues.
7
+ You can use it to easily reproduce issues. You will need Docker and Docker Compose installed (but not Ruby).
8
8
 
9
9
  To use it:
10
10
 
11
11
  * Run the Pact Broker using a specific Pact Broker Docker image by setting the required tag for the pact-broker service in the docker-compose-issue-repro-with-pact-broker-docker-image.yml file.
12
12
 
13
13
  ```
14
- # might need to try twice if it doesn't connect to postgres
14
+ git clone git@github.com:pact-foundation/pact_broker.git
15
+ cd pact_broker
16
+
15
17
  docker-compose -f docker-compose-issue-repro-with-pact-broker-docker-image.yml up pact-broker
16
18
 
17
- # if needing webhooks - new window
19
+ # if needing webhooks - run this in a new window so the logs are clearer
18
20
  docker-compose -f docker-compose-issue-repro-with-pact-broker-docker-image.yml up webhook-server
19
21
 
20
- # new window
21
- docker-compose -f docker-compose-issue-repro-with-pact-broker-docker-image.yml run repro-issue
22
-
23
22
  ```
24
23
 
25
24
  * Run the reproduction script.
26
25
 
27
26
  ```
27
+ # in a new shell
28
28
  docker-compose -f docker-compose-issue-repro-with-pact-broker-docker-image.yml run repro-issue
29
29
  ```
30
30
 
data/config.ru CHANGED
@@ -26,6 +26,7 @@ app = PactBroker::App.new do | config |
26
26
  config.webhook_host_whitelist = [/.*/, "10.0.0.0/8"]
27
27
  config.webhook_scheme_whitelist = ['http', 'https']
28
28
  config.webhook_http_method_whitelist = ['GET', 'POST']
29
+ config.webhook_http_code_success = [200, 201, 202, 203, 204, 205, 206]
29
30
  #config.base_url = ENV['PACT_BROKER_BASE_URL']
30
31
 
31
32
  database_logger = PactBroker::DB::LogQuietener.new(config.logger)
@@ -5,6 +5,29 @@ def head_pact_tags_v1(connection)
5
5
  Sequel[:lp][:consumer_id] => Sequel[:o][:consumer_id],
6
6
  Sequel[:lp][:provider_id] => Sequel[:o][:provider_id],
7
7
  Sequel[:cv][:order] => Sequel[:o][:latest_consumer_version_order]
8
- }, { table_alias: :o})
8
+ }, { table_alias: :o })
9
9
  .select(Sequel[:o][:tag_name].as(:name), Sequel[:lp][:pact_publication_id])
10
10
  end
11
+
12
+ def head_pact_tags_v2_rollback(connection, postgres)
13
+ if(postgres)
14
+ head_pact_tags_v1(connection).select_append(Sequel.lit("TIMESTAMP 'epoch'").as(:created_at))
15
+ else
16
+ head_pact_tags_v1(connection)
17
+ end
18
+ end
19
+
20
+ def head_pact_tags_v2(connection)
21
+ connection.from(Sequel.as(:latest_pact_publication_ids_for_consumer_versions, :lp))
22
+ .join(:versions,{ Sequel[:lp][:consumer_version_id] => Sequel[:cv][:id]}, { table_alias: :cv })
23
+ .join(:latest_tagged_pact_consumer_version_orders, {
24
+ Sequel[:lp][:consumer_id] => Sequel[:o][:consumer_id],
25
+ Sequel[:lp][:provider_id] => Sequel[:o][:provider_id],
26
+ Sequel[:cv][:order] => Sequel[:o][:latest_consumer_version_order]
27
+ }, { table_alias: :o } )
28
+ .join(:tags, {
29
+ Sequel[:tags][:version_id] => Sequel[:cv][:id],
30
+ Sequel[:tags][:name] => Sequel[:o][:tag_name]
31
+ })
32
+ .select(Sequel[:o][:tag_name].as(:name), Sequel[:lp][:pact_publication_id], Sequel[:tags][:created_at])
33
+ end
@@ -21,3 +21,14 @@ def latest_tagged_pact_consumer_version_orders_v3(connection)
21
21
  .join(:versions, { Sequel[:lp][:consumer_version_id] => Sequel[:cv][:id] }, { table_alias: :cv} )
22
22
  .join(:tags, { Sequel[:t][:version_id] => Sequel[:lp][:consumer_version_id] }, { table_alias: :t })
23
23
  end
24
+
25
+ def latest_tagged_pact_consumer_version_orders_v4(connection)
26
+ view = Sequel.as(:latest_pact_publication_ids_for_consumer_versions, :lp)
27
+ connection.from(view)
28
+ .select_group(
29
+ Sequel[:lp][:provider_id],
30
+ Sequel[:lp][:consumer_id],
31
+ Sequel[:t][:name].as(:tag_name))
32
+ .select_append{ max(version_order).as(latest_consumer_version_order) }
33
+ .join(:tags, { Sequel[:t][:version_id] => Sequel[:lp][:consumer_version_id] }, { table_alias: :t })
34
+ end
@@ -0,0 +1,6 @@
1
+ LATEST_TAGGED_PACT_PUBLICATIONS = "select lp.*, o.tag_name
2
+ from latest_pact_publications_by_consumer_versions lp
3
+ inner join latest_tagged_pact_consumer_version_orders o
4
+ on lp.consumer_id = o.consumer_id
5
+ and lp.provider_id = o.provider_id
6
+ and lp.consumer_version_order = latest_consumer_version_order"
@@ -51,3 +51,16 @@ LATEST_VERIFICATION_IDS_FOR_CONSUMER_VERSION_TAGS_V3 = "select
51
51
  on v.provider_version_id = pv.id
52
52
  where v.id in (select latest_verification_id from latest_verification_ids_for_pact_versions)
53
53
  group by pv.pacticipant_id, lpp.consumer_id, t.name"
54
+
55
+ LATEST_VERIFICATION_IDS_FOR_CONSUMER_VERSION_TAGS_V4 = "select
56
+ lpp.provider_id,
57
+ lpp.consumer_id,
58
+ t.name as consumer_version_tag_name,
59
+ max(lv.latest_verification_id) as latest_verification_id
60
+ from latest_verification_ids_for_pact_versions lv
61
+ join latest_pact_publication_ids_for_consumer_versions lpp
62
+ on lv.pact_version_id = lpp.pact_version_id
63
+ join tags t
64
+ on lpp.consumer_version_id = t.version_id
65
+ group by lpp.provider_id, lpp.consumer_id, t.name
66
+ "
@@ -0,0 +1,9 @@
1
+ Sequel.migration do
2
+ change do
3
+ alter_table(:versions) do
4
+ add_column(:branch, String)
5
+ add_column(:build_url, String)
6
+ add_index([:pacticipant_id, :branch, :order], name: "versions_pacticipant_id_branch_order_index")
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ require_relative '../ddl_statements'
2
+ require_relative 'migration_helper'
3
+
4
+ include PactBroker::MigrationHelper
5
+
6
+ Sequel.migration do
7
+ up do
8
+ create_or_replace_view(:head_pact_tags, head_pact_tags_v2(self))
9
+ end
10
+
11
+ down do
12
+ create_or_replace_view(:head_pact_tags, head_pact_tags_v2_rollback(self, postgres?))
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ require_relative 'migration_helper'
2
+
3
+ include PactBroker::MigrationHelper
4
+
5
+ Sequel.migration do
6
+ change do
7
+ alter_table(:tags) do
8
+ # TODO set_column_not_null(:pacticipant_id)
9
+ # TODO set_column_not_null(:version_order)
10
+ add_column(:pacticipant_id, Integer)
11
+ add_column(:version_order, Integer)
12
+ add_index(:version_order, name: "tags_version_order_index")
13
+ add_index(:version_id, name: "tags_version_id_index")
14
+ add_index(:pacticipant_id, name: "tags_pacticipant_id_index")
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,27 @@
1
+ require_relative 'migration_helper'
2
+
3
+ include PactBroker::MigrationHelper
4
+
5
+ Sequel.migration do
6
+ up do
7
+ if postgres?
8
+ run("CREATE INDEX tags_pacticipant_id_name_version_order_desc_index ON tags (pacticipant_id, name, version_order DESC);")
9
+ run("CREATE INDEX versions_pacticipant_id_order_desc_index ON versions (pacticipant_id, \"order\" DESC);")
10
+ else
11
+ alter_table(:tags) do
12
+ add_index([:pacticipant_id, :name, :version_order], name: "tags_pacticipant_id_name_version_order_index")
13
+ end
14
+ end
15
+ end
16
+
17
+ down do
18
+ if postgres?
19
+ run("DROP INDEX tags_pacticipant_id_name_version_order_desc_index")
20
+ run("DROP INDEX versions_pacticipant_id_order_desc_index")
21
+ else
22
+ alter_table(:tags) do
23
+ drop_index([:pacticipant_id, :name, :version_order], name: "tags_pacticipant_id_name_version_order_index")
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ require_relative '../ddl_statements'
2
+
3
+ Sequel.migration do
4
+ up do
5
+ create_or_replace_view(:latest_verification_ids_for_consumer_version_tags,
6
+ LATEST_VERIFICATION_IDS_FOR_CONSUMER_VERSION_TAGS_V4)
7
+ end
8
+
9
+ down do
10
+ create_or_replace_view(:latest_verification_ids_for_consumer_version_tags,
11
+ LATEST_VERIFICATION_IDS_FOR_CONSUMER_VERSION_TAGS_V3)
12
+ end
13
+ end