From 3ee6b7d6e9a2ae330a181cd874a84fb7791050bc Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Wed, 8 Dec 2021 20:15:27 +0530 Subject: [PATCH] chore: Add the ability to use same key for conversation and contact (#3526) --- app/models/custom_attribute_definition.rb | 4 ++-- ...ttribute_model_index_on_custom_attribute_definition.rb | 8 ++++++++ db/schema.rb | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20211208081344_add_attribute_model_index_on_custom_attribute_definition.rb diff --git a/app/models/custom_attribute_definition.rb b/app/models/custom_attribute_definition.rb index cc8590f45..72b67ce06 100644 --- a/app/models/custom_attribute_definition.rb +++ b/app/models/custom_attribute_definition.rb @@ -16,7 +16,7 @@ # # Indexes # -# attribute_key_index (attribute_key,account_id) UNIQUE +# attribute_key_model_index (attribute_key,attribute_model,account_id) UNIQUE # index_custom_attribute_definitions_on_account_id (account_id) # class CustomAttributeDefinition < ApplicationRecord @@ -25,7 +25,7 @@ class CustomAttributeDefinition < ApplicationRecord validates :attribute_key, presence: true, - uniqueness: { scope: :account_id } + uniqueness: { scope: [:account_id, :attribute_model] } validates :attribute_display_type, presence: true validates :attribute_model, presence: true diff --git a/db/migrate/20211208081344_add_attribute_model_index_on_custom_attribute_definition.rb b/db/migrate/20211208081344_add_attribute_model_index_on_custom_attribute_definition.rb new file mode 100644 index 000000000..a79826668 --- /dev/null +++ b/db/migrate/20211208081344_add_attribute_model_index_on_custom_attribute_definition.rb @@ -0,0 +1,8 @@ +class AddAttributeModelIndexOnCustomAttributeDefinition < ActiveRecord::Migration[6.1] + def change + remove_index :custom_attribute_definitions, [:attribute_key, :account_id], name: 'attribute_key_index', + if_exists: true + add_index :custom_attribute_definitions, [:attribute_key, :attribute_model, :account_id], unique: true, name: 'attribute_key_model_index', + if_not_exists: true + end +end diff --git a/db/schema.rb b/db/schema.rb index b172e2bfd..06ff9e42c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -368,7 +368,7 @@ ActiveRecord::Schema.define(version: 2021_12_08_085931) do t.text "attribute_description" t.jsonb "attribute_values", default: [] t.index ["account_id"], name: "index_custom_attribute_definitions_on_account_id" - t.index ["attribute_key", "account_id"], name: "attribute_key_index", unique: true + t.index ["attribute_key", "attribute_model", "account_id"], name: "attribute_key_model_index", unique: true end create_table "custom_filters", force: :cascade do |t|