-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: create integrations table (#522)
- Loading branch information
Showing
16 changed files
with
194 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Sequel.migration do | ||
up do | ||
# need to fully qualify build_url because versions now has a build_url too. | ||
# We don't use this view any more but we get an error when dropping the integrations | ||
# view if we don't update this, so it must force some re-calculation to be done. | ||
create_or_replace_view(:all_verifications, | ||
from(:verifications).select( | ||
Sequel[:verifications][:id], | ||
Sequel[:verifications][:number], | ||
:success, | ||
:provider_version_id, | ||
Sequel[:v][:number].as(:provider_version_number), | ||
Sequel[:v][:order].as(:provider_version_order), | ||
Sequel[:verifications][:build_url], | ||
:pact_version_id, | ||
:execution_date, | ||
Sequel[:verifications][:created_at], | ||
:test_results | ||
).join(:versions, {id: :provider_version_id}, {:table_alias => :v}) | ||
) | ||
end | ||
|
||
down do | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Sequel.migration do | ||
up do | ||
create_table(:temp_integrations, charset: "utf8") do | ||
primary_key :id | ||
foreign_key(:consumer_id, :pacticipants, null: false, on_delete: :cascade, foreign_key_constraint_name: "integrations_consumer_id_foreign_key") | ||
foreign_key(:provider_id, :pacticipants, null: false, on_delete: :cascade, foreign_key_constraint_name: "integrations_provider_id_foreign_key") | ||
String :consumer_name | ||
String :provider_name | ||
DateTime :created_at, null: false | ||
end | ||
|
||
# TODO drop these columns | ||
# They are just for backwards compatiblity during schema migrations | ||
# alter_table(:integrations) do | ||
# drop_column(:consumer_name) | ||
# drop_column(:provider_name) | ||
# end | ||
end | ||
|
||
down do | ||
drop_table(:temp_integrations) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Sequel.migration do | ||
up do | ||
from(:temp_integrations).insert( | ||
[:consumer_id, :consumer_name, :provider_id, :provider_name, :created_at], | ||
from(:pact_publications) | ||
.select( | ||
:consumer_id, | ||
Sequel[:c][:name].as(:consumer_name), | ||
:provider_id, | ||
Sequel[:p][:name].as(:provider_name), | ||
Sequel[:c][:created_at] | ||
).distinct | ||
.join(:pacticipants, {:id => :consumer_id}, {:table_alias => :c, implicit_qualifier: :pact_publications}) | ||
.join(:pacticipants, {:id => :provider_id}, {:table_alias => :p, implicit_qualifier: :pact_publications}) | ||
) | ||
end | ||
|
||
down do | ||
|
||
end | ||
end |
25 changes: 25 additions & 0 deletions
25
db/migrations/20211104_switch_integrations_and_temp_integrations.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Sequel.migration do | ||
up do | ||
transaction do | ||
drop_view :integrations | ||
rename_table :temp_integrations, :integrations | ||
end | ||
end | ||
|
||
down do | ||
transaction do | ||
rename_table :integrations, :temp_integrations | ||
create_view(:integrations, | ||
from(:pact_publications) | ||
.select( | ||
:consumer_id, | ||
Sequel[:c][:name].as(:consumer_name), | ||
:provider_id, | ||
Sequel[:p][:name].as(:provider_name) | ||
).distinct | ||
.join(:pacticipants, {:id => :consumer_id}, {:table_alias => :c, implicit_qualifier: :pact_publications}) | ||
.join(:pacticipants, {:id => :provider_id}, {:table_alias => :p, implicit_qualifier: :pact_publications}) | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require "pact_broker/integrations/integration" | ||
|
||
module PactBroker | ||
module Integrations | ||
class Repository | ||
def create_for_pact(consumer_id, provider_id) | ||
if Integration.where(consumer_id: consumer_id, provider_id: provider_id).empty? | ||
Integration.new( | ||
consumer_id: consumer_id, | ||
provider_id: provider_id, | ||
created_at: Sequel.datetime_class.now | ||
).insert_ignore | ||
end | ||
nil | ||
end | ||
|
||
def delete(consumer_id, provider_id) | ||
Integration.where(consumer_id: consumer_id, provider_id: provider_id).delete | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters