Merge pull request #1395 from Retrospring/fix/type-in-relationship-unique

Include type in relationship unique constraint
This commit is contained in:
Karina Kwiatek 2023-10-18 21:21:14 +02:00 committed by GitHub
commit b8fd519e2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -0,0 +1,10 @@
# frozen_string_literal: true
class IncludeTypeInRelationshipUniqueConstraint < ActiveRecord::Migration[6.1]
def change
change_table :relationships do |t|
t.remove_index(%i[source_id target_id])
t.index(%i[source_id target_id type], unique: true)
end
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2023_05_26_181715) do
ActiveRecord::Schema.define(version: 2023_10_18_172518) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -159,7 +159,7 @@ ActiveRecord::Schema.define(version: 2023_05_26_181715) do
t.datetime "created_at"
t.datetime "updated_at"
t.string "type", null: false
t.index ["source_id", "target_id"], name: "index_relationships_on_source_id_and_target_id", unique: true
t.index ["source_id", "target_id", "type"], name: "index_relationships_on_source_id_and_target_id_and_type", unique: true
t.index ["source_id"], name: "index_relationships_on_source_id"
t.index ["target_id"], name: "index_relationships_on_target_id"
t.index ["type"], name: "index_relationships_on_type"