Skip to content

Commit

Permalink
chore: revert table name to latest_verification_id_for_pact_version_a…
Browse files Browse the repository at this point in the history
…nd_provider_version

Needed to specify custom foreign key name to avoid fk constraint name length violation in mysql
  • Loading branch information
bethesque committed Aug 4, 2018
1 parent 8fd3862 commit 3d415e2
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion db/migrations/20180311_optimise_head_matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Add provider_version_order to original definition
# The most recent verification for each pact_version
# provider_version column is DEPRECATED, use provider_version_number
# Think this can be replaced by latest_verif_id_for_pact_version_and_provider_version?
# Think this can be replaced by latest_verification_id_for_pact_version_and_provider_version?
v = :verifications
create_or_replace_view(:latest_verifications,
from(v)
Expand Down
15 changes: 8 additions & 7 deletions db/migrations/20180723_create_latest_verification_ids.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
# latest revision speeds queries up.
# There is no way to delete an individual verification result yet, but when there
# is, we'll need to re-calculate the latest.
create_table(:latest_verif_id_for_pact_version_and_provider_version, charset: 'utf8') do
foreign_key :consumer_id, :pacticipants, null: false, on_delete: :cascade # not required, but useful to avoid extra joins
foreign_key :pact_version_id, :pact_versions, null: false, on_delete: :cascade
foreign_key :provider_id, :pacticipants, null: false, on_delete: :cascade # not required, but useful to avoid extra joins
foreign_key :provider_version_id, :versions, null: false, on_delete: :cascade
foreign_key :verification_id, :verifications, null: false, on_delete: :cascade, unique: true
create_table(:latest_verification_id_for_pact_version_and_provider_version, charset: 'utf8') do
foreign_key :consumer_id, :pacticipants, null: false, on_delete: :cascade, foreign_key_constraint_name: 'latest_v_id_for_pv_and_pv_consumer_id_fk' # not required, but useful to avoid extra joins
foreign_key :pact_version_id, :pact_versions, null: false, on_delete: :cascade, foreign_key_constraint_name: 'latest_v_id_for_pv_and_pv_pact_version_id_fk'
foreign_key :provider_id, :pacticipants, null: false, on_delete: :cascade, foreign_key_constraint_name: 'latest_v_id_for_pv_and_pv_provider_id_fk' # not required, but useful to avoid extra joins
foreign_key :provider_version_id, :versions, null: false, on_delete: :cascade, foreign_key_constraint_name: 'latest_v_id_for_pv_and_pv_provider_version_id_fk'
foreign_key :verification_id, :verifications, null: false, on_delete: :cascade, foreign_key_constraint_name: 'latest_v_id_for_pv_and_pv_verification_id_fk'
index [:verification_id], unique: true, name: "latest_v_id_for_pv_and_pv_v_id_unq"
index [:pact_version_id, :provider_version_id], unique: true, name: "unq_latest_verifid_pvid_provid"
end
end

down do
drop_table(:latest_verif_id_for_pact_version_and_provider_version)
drop_table(:latest_verification_id_for_pact_version_and_provider_version)
end
end
4 changes: 2 additions & 2 deletions db/migrations/20180724_migrate_latest_verification_ids.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
.select_append{ max(verifications[id]).as(verification_id) }

# The danger with this migration is that a verification created by an old node will be lost
from(:latest_verif_id_for_pact_version_and_provider_version).insert(rows)
from(:latest_verification_id_for_pact_version_and_provider_version).insert(rows)
end

down do
from(:latest_verif_id_for_pact_version_and_provider_version).delete
from(:latest_verification_id_for_pact_version_and_provider_version).delete
end
end
2 changes: 1 addition & 1 deletion db/migrations/20180726_recreate_views.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from latest_pact_publication_ids_by_consumer_versions lpp
inner join pact_publications pp
on pp.id = lpp.pact_publication_id
left outer join latest_verif_id_for_pact_version_and_provider_version lv
left outer join latest_verification_id_for_pact_version_and_provider_version lv
on lv.pact_version_id = pp.pact_version_id"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
v.consumer_id,
t.name as consumer_version_tag_name,
max(v.verification_id) as latest_verification_id
from latest_verif_id_for_pact_version_and_provider_version v
from latest_verification_id_for_pact_version_and_provider_version v
join latest_pact_publication_ids_by_consumer_versions lpp
on v.pact_version_id = lpp.pact_version_id
join tags t
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/api/resources/verification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def content_types_provided
[["application/hal+json", :to_json], ["application/json", :to_json]]
end

# Remember to update latest_verif_id_for_pact_version_and_provider_version
# Remember to update latest_verification_id_for_pact_version_and_provider_version
# if/when DELETE is implemented
def allowed_methods
["GET", "OPTIONS"]
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/verifications/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def update_latest_verification_id verification
consumer_id: verification.consumer_id
}

table = PactBroker::Domain::Verification.db[:latest_verif_id_for_pact_version_and_provider_version]
table = PactBroker::Domain::Verification.db[:latest_verification_id_for_pact_version_and_provider_version]
PactBroker::Repositories::Helpers.upsert(table, key, other)
end

Expand Down

0 comments on commit 3d415e2

Please sign in to comment.