From 2a6d88abfcf7f99d2d52130e243aa04152726205 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Wed, 18 Oct 2023 19:29:44 +0200 Subject: [PATCH] Include type in relationship unique constraint --- ...8_include_type_in_relationship_unique_constraint.rb | 10 ++++++++++ db/schema.rb | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20231018172518_include_type_in_relationship_unique_constraint.rb diff --git a/db/migrate/20231018172518_include_type_in_relationship_unique_constraint.rb b/db/migrate/20231018172518_include_type_in_relationship_unique_constraint.rb new file mode 100644 index 00000000..171fe00f --- /dev/null +++ b/db/migrate/20231018172518_include_type_in_relationship_unique_constraint.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index c45fb69c..ea268655 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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"