pact_broker 2.24.0 → 2.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -0
  3. data/CONTRIBUTING.md +2 -2
  4. data/DEVELOPER_DOCUMENTATION.md +31 -27
  5. data/DEVELOPER_SETUP.md +3 -2
  6. data/config/database.yml +10 -0
  7. data/db/ddl_statements.rb +3 -0
  8. data/db/ddl_statements/head_matrix_v001.rb +31 -0
  9. data/db/ddl_statements/head_matrix_v002.rb +31 -0
  10. data/db/ddl_statements/latest_verification_ids_for_pact_versions_v001.rb +4 -0
  11. data/db/migrations/000028_create_all_pact_publications.rb +4 -1
  12. data/db/migrations/20180311_optimise_head_matrix.rb +5 -34
  13. data/db/migrations/20180523_create_latest_verifications_for_consumer_version_tags.rb +2 -0
  14. data/db/migrations/20180612_add_pacticipant_ids_to_verifications.rb +17 -0
  15. data/db/migrations/20180613_migrate_pacticipant_ids_for_verifications.rb +7 -0
  16. data/db/migrations/20180614_update_latest_verification_ids_for_consumer_and_provider.rb +27 -0
  17. data/db/migrations/20180615_add_consumer_id_to_pact_publications.rb +13 -0
  18. data/db/migrations/20180616_migrate_consumer_ids_for_pact_publications.rb +11 -0
  19. data/db/migrations/20180720_create_latest_pact_publication_ids.rb +25 -0
  20. data/db/migrations/20180721_migrate_latest_pact_publication_ids.rb +11 -0
  21. data/db/migrations/20180722_recreate_views.rb +43 -0
  22. data/db/migrations/20180723_create_latest_verification_ids.rb +23 -0
  23. data/db/migrations/20180724_migrate_latest_verification_ids.rb +18 -0
  24. data/db/migrations/20180726_recreate_views.rb +29 -0
  25. data/db/migrations/20180727_recreate_latest_verification_ids_for_consumer_version_tags.rb +34 -0
  26. data/db/migrations/20180728_truncate_materialized_matrix_tables.rb +20 -0
  27. data/db/migrations/20180729_create_latest_verification_ids_for_provider_versions.rb +8 -0
  28. data/db/migrations/20180730_create_latest_verifications_for_provider_versions.rb +33 -0
  29. data/db/migrations/20180731_update_head_matrix.rb +11 -0
  30. data/db/pact_broker_database.sqlite3 +0 -0
  31. data/lib/pact_broker/api.rb +3 -3
  32. data/lib/pact_broker/api/decorators/dashboard_text_decorator.rb +2 -2
  33. data/lib/pact_broker/api/pact_broker_urls.rb +1 -1
  34. data/lib/pact_broker/api/resources/base_resource.rb +0 -7
  35. data/lib/pact_broker/api/resources/index.rb +11 -9
  36. data/lib/pact_broker/api/resources/pact.rb +1 -3
  37. data/lib/pact_broker/api/resources/pacticipant.rb +1 -3
  38. data/lib/pact_broker/api/resources/tag.rb +1 -4
  39. data/lib/pact_broker/api/resources/verification.rb +2 -0
  40. data/lib/pact_broker/api/resources/version.rb +1 -3
  41. data/lib/pact_broker/app.rb +8 -0
  42. data/lib/pact_broker/certificates/certificate.rb +12 -0
  43. data/lib/pact_broker/config/setting.rb +12 -0
  44. data/lib/pact_broker/configuration.rb +2 -1
  45. data/lib/pact_broker/db.rb +6 -0
  46. data/lib/pact_broker/db/clean.rb +2 -7
  47. data/lib/pact_broker/db/data_migrations/set_consumer_ids_for_pact_publications.rb +29 -0
  48. data/lib/pact_broker/db/data_migrations/set_pacticipant_ids_for_verifications.rb +35 -0
  49. data/lib/pact_broker/db/migrate_data.rb +14 -0
  50. data/lib/pact_broker/doc/views/wip-provider-pacts.markdown +3 -0
  51. data/lib/pact_broker/domain/label.rb +12 -0
  52. data/lib/pact_broker/domain/pacticipant.rb +32 -1
  53. data/lib/pact_broker/domain/tag.rb +14 -1
  54. data/lib/pact_broker/domain/verification.rb +29 -0
  55. data/lib/pact_broker/domain/version.rb +25 -1
  56. data/lib/pact_broker/feature_toggle.rb +23 -0
  57. data/lib/pact_broker/index/service.rb +1 -0
  58. data/lib/pact_broker/matrix/head_row.rb +25 -20
  59. data/lib/pact_broker/matrix/repository.rb +0 -18
  60. data/lib/pact_broker/matrix/row.rb +24 -27
  61. data/lib/pact_broker/matrix/service.rb +0 -8
  62. data/lib/pact_broker/pacts/all_pact_publications.rb +15 -0
  63. data/lib/pact_broker/pacts/latest_pact_publication_id_by_consumer_version.rb +34 -0
  64. data/lib/pact_broker/pacts/latest_pact_publications.rb +15 -0
  65. data/lib/pact_broker/pacts/latest_pact_publications_by_consumer_version.rb +15 -0
  66. data/lib/pact_broker/pacts/latest_tagged_pact_publications.rb +16 -0
  67. data/lib/pact_broker/pacts/pact_publication.rb +24 -0
  68. data/lib/pact_broker/pacts/pact_version.rb +20 -0
  69. data/lib/pact_broker/pacts/repository.rb +37 -11
  70. data/lib/pact_broker/pacts/service.rb +9 -2
  71. data/lib/pact_broker/repositories/helpers.rb +20 -0
  72. data/lib/pact_broker/tags/tag_with_latest_flag.rb +8 -0
  73. data/lib/pact_broker/ui/view_models/index_item.rb +5 -1
  74. data/lib/pact_broker/ui/views/index/show.haml +1 -1
  75. data/lib/pact_broker/verifications/all_verifications.rb +13 -0
  76. data/lib/pact_broker/verifications/latest_verification_for_consumer_and_provider.rb +18 -0
  77. data/lib/pact_broker/verifications/latest_verification_for_consumer_version_tag.rb +19 -0
  78. data/lib/pact_broker/verifications/latest_verification_for_pact_version.rb +22 -0
  79. data/lib/pact_broker/verifications/latest_verification_id_for_pact_version_and_provider_version.rb +36 -0
  80. data/lib/pact_broker/verifications/repository.rb +23 -5
  81. data/lib/pact_broker/verifications/sequence.rb +4 -0
  82. data/lib/pact_broker/version.rb +1 -1
  83. data/lib/pact_broker/webhooks/execution.rb +16 -0
  84. data/lib/pact_broker/webhooks/latest_triggered_webhook.rb +14 -0
  85. data/lib/pact_broker/webhooks/triggered_webhook.rb +27 -0
  86. data/lib/pact_broker/webhooks/webhook.rb +26 -0
  87. data/lib/pact_broker/webhooks/webhook_event.rb +13 -0
  88. data/pact_broker.gemspec +1 -0
  89. data/script/recreate-docker-pg-db.sh +20 -0
  90. data/script/recreate-mysql-db.sh +1 -0
  91. data/spec/integration/webhooks/certificate_spec.rb +1 -1
  92. data/spec/lib/pact_broker/db/clean_spec.rb +1 -1
  93. data/spec/lib/pact_broker/db/data_migrations/set_consumer_ids_for_pact_publications_spec.rb +40 -0
  94. data/spec/lib/pact_broker/feature_toggle_spec.rb +74 -0
  95. data/spec/lib/pact_broker/matrix/head_row_spec.rb +0 -44
  96. data/spec/lib/pact_broker/matrix/repository_spec.rb +0 -20
  97. data/spec/lib/pact_broker/matrix/row_spec.rb +0 -56
  98. data/spec/lib/pact_broker/pacts/repository_spec.rb +61 -9
  99. data/spec/lib/pact_broker/pacts/service_spec.rb +65 -17
  100. data/spec/lib/pact_broker/ui/view_models/index_item_spec.rb +3 -2
  101. data/spec/migrations/44_add_provider_version_to_verification_spec.rb +0 -1
  102. data/spec/service_consumers/provider_states_for_pact_ruby.rb +14 -0
  103. data/spec/support/test_data_builder.rb +0 -18
  104. data/tasks/database/annotate.rb +40 -0
  105. data/tasks/db.rake +12 -0
  106. metadata +50 -3
  107. data/lib/pact_broker/verifications/latest_verifications_by_consumer_version.rb +0 -15
@@ -6,3 +6,15 @@ module PactBroker
6
6
  Setting.plugin :timestamps, update_on_create: true
7
7
  end
8
8
  end
9
+
10
+ # Table: config
11
+ # Columns:
12
+ # id | integer | PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY
13
+ # name | text | NOT NULL
14
+ # type | text | NOT NULL
15
+ # value | text |
16
+ # created_at | timestamp without time zone | NOT NULL
17
+ # updated_at | timestamp without time zone | NOT NULL
18
+ # Indexes:
19
+ # config_pkey | PRIMARY KEY btree (id)
20
+ # unq_config_name | UNIQUE btree (name)
@@ -31,7 +31,7 @@ module PactBroker
31
31
  :base_equality_only_on_content_that_affects_verification_results
32
32
  ]
33
33
 
34
- attr_accessor :log_dir, :database_connection, :auto_migrate_db, :use_hal_browser, :html_pact_renderer
34
+ attr_accessor :log_dir, :database_connection, :auto_migrate_db, :auto_migrate_db_data, :use_hal_browser, :html_pact_renderer
35
35
  attr_accessor :validate_database_connection_config, :enable_diagnostic_endpoints, :version_parser, :sha_generator
36
36
  attr_accessor :use_case_sensitive_resource_names, :order_versions_by_date
37
37
  attr_accessor :check_for_potential_duplicate_pacticipant_names
@@ -63,6 +63,7 @@ module PactBroker
63
63
  config = Configuration.new
64
64
  config.log_dir = File.expand_path("./log")
65
65
  config.auto_migrate_db = true
66
+ config.auto_migrate_db_data = true
66
67
  config.use_hal_browser = true
67
68
  config.validate_database_connection_config = true
68
69
  config.enable_diagnostic_endpoints = true
@@ -1,5 +1,7 @@
1
1
  require 'sequel'
2
2
  require 'pact_broker/db/validate_encoding'
3
+ require 'pact_broker/db/migrate'
4
+ require 'pact_broker/db/migrate_data'
3
5
 
4
6
  Sequel.datetime_class = DateTime
5
7
 
@@ -21,6 +23,10 @@ module PactBroker
21
23
  Sequel::TimestampMigrator.new(database_connection, PactBroker::DB::MIGRATIONS_DIR).run
22
24
  end
23
25
 
26
+ def self.run_data_migrations database_connection
27
+ PactBroker::DB::MigrateData.(connection)
28
+ end
29
+
24
30
  def self.validate_connection_config
25
31
  PactBroker::DB::ValidateEncoding.(connection)
26
32
  end
@@ -14,8 +14,8 @@ module PactBroker
14
14
  end
15
15
 
16
16
  def call
17
- db[:verifications].where(id: db[:materialized_head_matrix].select(:verification_id)).invert.delete
18
- pp_ids = db[:materialized_head_matrix].select(:pact_publication_id)
17
+ db[:verifications].where(id: db[:head_matrix].select(:verification_id)).invert.delete
18
+ pp_ids = db[:head_matrix].select(:pact_publication_id)
19
19
 
20
20
  triggered_webhook_ids = db[:triggered_webhooks].where(pact_publication_id: pp_ids).invert.select(:id)
21
21
  db[:webhook_executions].where(triggered_webhook_id: triggered_webhook_ids).delete
@@ -33,11 +33,6 @@ module PactBroker
33
33
 
34
34
  db[:tags].where(version_id: referenced_version_ids).invert.delete
35
35
  db[:versions].where(id: referenced_version_ids).invert.delete
36
-
37
- db[:materialized_matrix].delete
38
- db[:materialized_matrix].insert(db[:matrix].select_all)
39
- db[:materialized_head_matrix].delete
40
- db[:materialized_head_matrix].insert(db[:head_matrix].select_all)
41
36
  end
42
37
 
43
38
  private
@@ -0,0 +1,29 @@
1
+ module PactBroker
2
+ module DB
3
+ module DataMigrations
4
+ class SetConsumerIdsForPactPublications
5
+ def self.call connection
6
+ if columns_exist?(connection)
7
+ query = "UPDATE pact_publications
8
+ SET consumer_id = (SELECT pacticipant_id
9
+ FROM versions
10
+ WHERE id = pact_publications.consumer_version_id)
11
+ WHERE consumer_id is null"
12
+ connection.run(query)
13
+ end
14
+ end
15
+
16
+ def self.columns_exist?(connection)
17
+ column_exists?(connection, :pact_publications, :consumer_id) &&
18
+ column_exists?(connection, :pact_publications, :id) &&
19
+ column_exists?(connection, :versions, :id) &&
20
+ column_exists?(connection, :versions, :pacticipant_id)
21
+ end
22
+
23
+ def self.column_exists?(connection, table, column)
24
+ connection.table_exists?(table) && connection.schema(table).find{|col| col.first == column }
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,35 @@
1
+ module PactBroker
2
+ module DB
3
+ module DataMigrations
4
+ class SetPacticipantIdsForVerifications
5
+ def self.call connection
6
+ if columns_exist?(connection)
7
+ query = "UPDATE verifications
8
+ SET consumer_id = (SELECT consumer_id
9
+ FROM pact_versions
10
+ WHERE id = verifications.pact_version_id),
11
+ provider_id = (SELECT provider_id
12
+ FROM pact_versions
13
+ WHERE id = verifications.pact_version_id)
14
+ WHERE consumer_id is null
15
+ OR provider_id is null"
16
+ connection.run(query)
17
+ end
18
+ end
19
+
20
+ def self.columns_exist?(connection)
21
+ column_exists?(connection, :verifications, :provider_id) &&
22
+ column_exists?(connection, :verifications, :consumer_id) &&
23
+ column_exists?(connection, :verifications, :provider_version_id) &&
24
+ column_exists?(connection, :pact_versions, :provider_id) &&
25
+ column_exists?(connection, :pact_versions, :consumer_id) &&
26
+ column_exists?(connection, :pact_versions, :id)
27
+ end
28
+
29
+ def self.column_exists?(connection, table, column)
30
+ connection.table_exists?(table) && connection.schema(table).find{|col| col.first == column }
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,14 @@
1
+ Dir.glob(File.expand_path(File.join(__FILE__, "..", "data_migrations", "*.rb"))).sort.each do | path |
2
+ require path
3
+ end
4
+
5
+ module PactBroker
6
+ module DB
7
+ class MigrateData
8
+ def self.call database_connection, options = {}
9
+ DataMigrations::SetPacticipantIdsForVerifications.call(database_connection)
10
+ DataMigrations::SetConsumerIdsForPactPublications.call(database_connection)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ # Work In Progress Pacts
2
+
3
+ This feature is in beta. It allows WIP pacts (pacts that have not yet been succesfully verified) to run against a provider without failing the build.
@@ -17,3 +17,15 @@ module PactBroker
17
17
  Label.plugin :timestamps, update_on_create: true
18
18
  end
19
19
  end
20
+
21
+ # Table: labels
22
+ # Primary Key: (name, pacticipant_id)
23
+ # Columns:
24
+ # name | text |
25
+ # pacticipant_id | integer |
26
+ # created_at | timestamp without time zone | NOT NULL
27
+ # updated_at | timestamp without time zone | NOT NULL
28
+ # Indexes:
29
+ # labels_pk | PRIMARY KEY btree (pacticipant_id, name)
30
+ # Foreign key constraints:
31
+ # labels_pacticipant_id_fkey | (pacticipant_id) REFERENCES pacticipants(id)
@@ -42,4 +42,35 @@ module PactBroker
42
42
 
43
43
  Pacticipant.plugin :timestamps, update_on_create: true
44
44
  end
45
- end
45
+ end
46
+
47
+ # Table: pacticipants
48
+ # Columns:
49
+ # id | integer | PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY
50
+ # name | text |
51
+ # repository_url | text |
52
+ # created_at | timestamp without time zone | NOT NULL
53
+ # updated_at | timestamp without time zone | NOT NULL
54
+ # Indexes:
55
+ # pacticipants_pkey | PRIMARY KEY btree (id)
56
+ # pacticipants_name_key | UNIQUE btree (name)
57
+ # ndx_ppt_name | btree (name)
58
+ # Referenced By:
59
+ # versions | versions_pacticipant_id_fkey | (pacticipant_id) REFERENCES pacticipants(id)
60
+ # webhooks | fk_webhooks_consumer | (consumer_id) REFERENCES pacticipants(id)
61
+ # webhooks | fk_webhooks_provider | (provider_id) REFERENCES pacticipants(id)
62
+ # pact_versions | pact_versions_consumer_id_fkey | (consumer_id) REFERENCES pacticipants(id)
63
+ # pact_versions | pact_versions_provider_id_fkey | (provider_id) REFERENCES pacticipants(id)
64
+ # pact_publications | pact_publications_consumer_id_fkey | (consumer_id) REFERENCES pacticipants(id)
65
+ # pact_publications | pact_publications_provider_id_fkey | (provider_id) REFERENCES pacticipants(id)
66
+ # verifications | verifications_consumer_id_fkey | (consumer_id) REFERENCES pacticipants(id)
67
+ # verifications | verifications_provider_id_fkey | (provider_id) REFERENCES pacticipants(id)
68
+ # webhook_executions | webhook_executions_consumer_id_fkey | (consumer_id) REFERENCES pacticipants(id)
69
+ # webhook_executions | webhook_executions_provider_id_fkey | (provider_id) REFERENCES pacticipants(id)
70
+ # labels | labels_pacticipant_id_fkey | (pacticipant_id) REFERENCES pacticipants(id)
71
+ # triggered_webhooks | triggered_webhooks_consumer_id_fkey | (consumer_id) REFERENCES pacticipants(id)
72
+ # triggered_webhooks | triggered_webhooks_provider_id_fkey | (provider_id) REFERENCES pacticipants(id)
73
+ # latest_pact_publication_ids_for_consumer_versions | latest_pact_publication_ids_for_consumer_versi_consumer_id_fkey | (consumer_id) REFERENCES pacticipants(id) ON DELETE CASCADE
74
+ # latest_pact_publication_ids_for_consumer_versions | latest_pact_publication_ids_for_consumer_versi_provider_id_fkey | (provider_id) REFERENCES pacticipants(id) ON DELETE CASCADE
75
+ # latest_verification_id_for_pact_version_and_provider_version | latest_v_id_for_pv_and_pv_consumer_id_fk | (consumer_id) REFERENCES pacticipants(id) ON DELETE CASCADE
76
+ # latest_verification_id_for_pact_version_and_provider_version | latest_v_id_for_pv_and_pv_provider_id_fk | (provider_id) REFERENCES pacticipants(id) ON DELETE CASCADE
@@ -22,4 +22,17 @@ module PactBroker
22
22
 
23
23
  Tag.plugin :timestamps, :update_on_create=>true
24
24
  end
25
- end
25
+ end
26
+
27
+ # Table: tags
28
+ # Primary Key: (name, version_id)
29
+ # Columns:
30
+ # name | text |
31
+ # version_id | integer |
32
+ # created_at | timestamp without time zone | NOT NULL
33
+ # updated_at | timestamp without time zone | NOT NULL
34
+ # Indexes:
35
+ # tags_pk | PRIMARY KEY btree (version_id, name)
36
+ # ndx_tag_name | btree (name)
37
+ # Foreign key constraints:
38
+ # tags_version_id_fkey | (version_id) REFERENCES versions(id)
@@ -98,3 +98,32 @@ module PactBroker
98
98
  Verification.plugin :timestamps
99
99
  end
100
100
  end
101
+
102
+ # Table: verifications
103
+ # Columns:
104
+ # id | integer | PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY
105
+ # number | integer |
106
+ # success | boolean | NOT NULL
107
+ # provider_version | text |
108
+ # build_url | text |
109
+ # pact_version_id | integer | NOT NULL
110
+ # execution_date | timestamp without time zone | NOT NULL
111
+ # created_at | timestamp without time zone | NOT NULL
112
+ # provider_version_id | integer |
113
+ # test_results | text |
114
+ # consumer_id | integer |
115
+ # provider_id | integer |
116
+ # Indexes:
117
+ # verifications_pkey | PRIMARY KEY btree (id)
118
+ # verifications_pact_version_id_number_index | UNIQUE btree (pact_version_id, number)
119
+ # verifications_consumer_id_index | btree (consumer_id)
120
+ # verifications_provider_id_consumer_id_index | btree (provider_id, consumer_id)
121
+ # verifications_provider_id_index | btree (provider_id)
122
+ # Foreign key constraints:
123
+ # fk_verifications_versions | (provider_version_id) REFERENCES versions(id)
124
+ # verifications_consumer_id_fkey | (consumer_id) REFERENCES pacticipants(id)
125
+ # verifications_pact_version_id_fkey | (pact_version_id) REFERENCES pact_versions(id)
126
+ # verifications_provider_id_fkey | (provider_id) REFERENCES pacticipants(id)
127
+ # Referenced By:
128
+ # triggered_webhooks | triggered_webhooks_verification_id_fkey | (verification_id) REFERENCES verifications(id)
129
+ # latest_verification_id_for_pact_version_and_provider_version | latest_v_id_for_pv_and_pv_verification_id_fk | (verification_id) REFERENCES verifications(id) ON DELETE CASCADE
@@ -37,4 +37,28 @@ module PactBroker
37
37
 
38
38
  Version.plugin :timestamps, :update_on_create=>true
39
39
  end
40
- end
40
+ end
41
+
42
+ # Table: versions
43
+ # Columns:
44
+ # id | integer | PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY
45
+ # number | text |
46
+ # repository_ref | text |
47
+ # pacticipant_id | integer | NOT NULL
48
+ # order | integer |
49
+ # created_at | timestamp without time zone | NOT NULL
50
+ # updated_at | timestamp without time zone | NOT NULL
51
+ # Indexes:
52
+ # versions_pkey | PRIMARY KEY btree (id)
53
+ # uq_ver_ppt_ord | UNIQUE btree (pacticipant_id, "order")
54
+ # versions_pacticipant_id_number_index | UNIQUE btree (pacticipant_id, number)
55
+ # ndx_ver_num | btree (number)
56
+ # ndx_ver_ord | btree ("order")
57
+ # Foreign key constraints:
58
+ # versions_pacticipant_id_fkey | (pacticipant_id) REFERENCES pacticipants(id)
59
+ # Referenced By:
60
+ # tags | tags_version_id_fkey | (version_id) REFERENCES versions(id)
61
+ # pact_publications | pact_publications_consumer_version_id_fkey | (consumer_version_id) REFERENCES versions(id)
62
+ # verifications | fk_verifications_versions | (provider_version_id) REFERENCES versions(id)
63
+ # latest_pact_publication_ids_for_consumer_versions | latest_pact_publication_ids_for_consum_consumer_version_id_fkey | (consumer_version_id) REFERENCES versions(id) ON DELETE CASCADE
64
+ # latest_verification_id_for_pact_version_and_provider_version | latest_v_id_for_pv_and_pv_provider_version_id_fk | (provider_version_id) REFERENCES versions(id) ON DELETE CASCADE
@@ -0,0 +1,23 @@
1
+ module PactBroker
2
+ class FeatureToggle
3
+ def self.enabled?(feature)
4
+ not_production? || feature_in_env_var?(feature)
5
+ end
6
+
7
+ def self.not_production?
8
+ ENV['RACK_ENV'] != 'production'
9
+ end
10
+
11
+ def self.feature_in_env_var?(feature)
12
+ (features =~ /\b#{feature}\b/i) != nil
13
+ end
14
+
15
+ def self.features
16
+ ENV['PACT_BROKER_FEATURES'] || ""
17
+ end
18
+ end
19
+
20
+ def self.feature_enabled?(feature)
21
+ FeatureToggle.enabled?(feature)
22
+ end
23
+ end
@@ -28,6 +28,7 @@ module PactBroker
28
28
  rows = rows.eager(:consumer_version_tags)
29
29
  .eager(:provider_version_tags)
30
30
  .eager(:latest_verification_for_consumer_version_tag)
31
+ .eager(:latest_verification_for_consumer_and_provider)
31
32
  end
32
33
  rows = rows.all.group_by(&:pact_publication_id).values.collect{ | rows| Matrix::AggregatedRow.new(rows) }
33
34
 
@@ -5,7 +5,7 @@ module PactBroker
5
5
  # A row for each of the overall latest pacts, and a row for each of the latest tagged pacts
6
6
  # Rows with a nil consumer_tag_name are the overall latest
7
7
  class HeadRow < Row
8
- set_dataset(:materialized_head_matrix)
8
+ set_dataset(:head_matrix)
9
9
 
10
10
  # one_to_one :latest_verification_for_consumer_version_tag,
11
11
  # :class => "PactBroker::Verifications::LatestVerificationForConsumerVersionTag",
@@ -29,25 +29,30 @@ module PactBroker
29
29
  end
30
30
  end
31
31
  end)
32
-
33
- dataset_module do
34
- include PactBroker::Repositories::Helpers
35
- include PactBroker::Logging
36
-
37
- def refresh ids
38
- return super unless ids[:tag_name]
39
-
40
- logger.debug("Refreshing #{model.table_name} for #{ids}")
41
- db = model.db
42
- table_name = model.table_name
43
- criteria = { consumer_id: ids[:pacticipant_id], consumer_version_tag_name: ids[:tag_name] }
44
- db.transaction do
45
- db[table_name].where(criteria).delete
46
- new_rows = db[source_view_name].where(criteria)
47
- db[table_name].insert(new_rows)
48
- end
49
- end
50
- end
51
32
  end
52
33
  end
53
34
  end
35
+
36
+ # Table: head_matrix
37
+ # Columns:
38
+ # consumer_id | integer |
39
+ # consumer_name | text |
40
+ # consumer_version_id | integer |
41
+ # consumer_version_number | text |
42
+ # consumer_version_order | integer |
43
+ # pact_publication_id | integer |
44
+ # pact_version_id | integer |
45
+ # pact_version_sha | text |
46
+ # pact_revision_number | integer |
47
+ # pact_created_at | timestamp without time zone |
48
+ # provider_id | integer |
49
+ # provider_name | text |
50
+ # provider_version_id | integer |
51
+ # provider_version_number | text |
52
+ # provider_version_order | integer |
53
+ # verification_id | integer |
54
+ # success | boolean |
55
+ # verification_number | integer |
56
+ # verification_executed_at | timestamp without time zone |
57
+ # verification_build_url | text |
58
+ # consumer_version_tag_name | text |
@@ -23,24 +23,6 @@ module PactBroker
23
23
  GROUP_BY_PROVIDER = [:consumer_name, :consumer_version_number, :provider_name]
24
24
  GROUP_BY_PACT = [:consumer_name, :provider_name]
25
25
 
26
- # Use a block when the refresh is caused by a resource deletion
27
- # This allows us to store the correct object ids for use afterwards
28
- def refresh params
29
- criteria = find_ids_for_pacticipant_names(params)
30
- yield if block_given?
31
- PactBroker::Matrix::Row.refresh(criteria)
32
- PactBroker::Matrix::HeadRow.refresh(criteria)
33
- end
34
-
35
- # Only need to update the HeadRow table when tags change
36
- # because it only changes which rows are the latest tagged ones -
37
- # it doesn't change the actual values in the underlying matrix.
38
- def refresh_tags params
39
- criteria = find_ids_for_pacticipant_names(params)
40
- yield if block_given?
41
- PactBroker::Matrix::HeadRow.refresh(criteria)
42
- end
43
-
44
26
  def find_ids_for_pacticipant_names params
45
27
  criteria = {}
46
28
 
@@ -8,7 +8,7 @@ require 'pact_broker/verifications/latest_verification_for_consumer_and_provider
8
8
  module PactBroker
9
9
  module Matrix
10
10
 
11
- class Row < Sequel::Model(:materialized_matrix)
11
+ class Row < Sequel::Model(:matrix)
12
12
 
13
13
  # Used when using table_print to output query results
14
14
  TP_COLS = [ :consumer_version_number, :pact_revision_number, :provider_version_number, :verification_number]
@@ -26,32 +26,6 @@ module PactBroker
26
26
  include PactBroker::Repositories::Helpers
27
27
  include PactBroker::Logging
28
28
 
29
- def refresh ids
30
- logger.debug("Refreshing #{model.table_name} for #{ids}")
31
-
32
- db = model.db
33
- table_name = model.table_name
34
-
35
- if ids[:pacticipant_id]
36
- db.transaction do
37
- db[table_name].where(consumer_id: ids[:pacticipant_id]).or(provider_id: ids[:pacticipant_id]).delete
38
- new_rows = db[source_view_name].where(consumer_id: ids[:pacticipant_id]).or(provider_id: ids[:pacticipant_id]).distinct
39
- db[table_name].insert(new_rows)
40
- end
41
- elsif ids.any?
42
- accepted_columns = [:consumer_id, :consumer_name, :provider_id, :provider_name]
43
- criteria = ids.reject{ |k, v| !accepted_columns.include?(k) }
44
- db.transaction do
45
- db[table_name].where(criteria).delete
46
- db[table_name].insert(db[source_view_name].where(criteria))
47
- end
48
- end
49
- end
50
-
51
- def source_view_name
52
- model.table_name.to_s.gsub('materialized_', '').to_sym
53
- end
54
-
55
29
  def matching_selectors selectors
56
30
  if selectors.size == 1
57
31
  where_consumer_or_provider_is(selectors.first)
@@ -227,3 +201,26 @@ module PactBroker
227
201
  end
228
202
  end
229
203
  end
204
+
205
+ # Table: matrix
206
+ # Columns:
207
+ # consumer_id | integer |
208
+ # consumer_name | text |
209
+ # consumer_version_id | integer |
210
+ # consumer_version_number | text |
211
+ # consumer_version_order | integer |
212
+ # pact_publication_id | integer |
213
+ # pact_version_id | integer |
214
+ # pact_version_sha | text |
215
+ # pact_revision_number | integer |
216
+ # pact_created_at | timestamp without time zone |
217
+ # provider_id | integer |
218
+ # provider_name | text |
219
+ # provider_version_id | integer |
220
+ # provider_version_number | text |
221
+ # provider_version_order | integer |
222
+ # verification_id | integer |
223
+ # success | boolean |
224
+ # verification_number | integer |
225
+ # verification_executed_at | timestamp without time zone |
226
+ # verification_build_url | text |