diff --git a/app/models/contact.rb b/app/models/contact.rb index ef48a7dda..ba10139ba 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -23,6 +23,7 @@ # index_contacts_on_name_email_phone_number_identifier (name,email,phone_number,identifier) USING gin # index_contacts_on_nonempty_fields (account_id,email,phone_number,identifier) WHERE (((email)::text <> ''::text) OR ((phone_number)::text <> ''::text) OR ((identifier)::text <> ''::text)) # index_contacts_on_phone_number_and_account_id (phone_number,account_id) +# index_resolved_contact_account_id (account_id) WHERE (((email)::text <> ''::text) OR ((phone_number)::text <> ''::text) OR ((identifier)::text <> ''::text)) # uniq_email_per_account_contact (email,account_id) UNIQUE # uniq_identifier_per_account_contact (identifier,account_id) UNIQUE # diff --git a/db/migrate/20230727065605_add_partial_index_contact_account_id.rb b/db/migrate/20230727065605_add_partial_index_contact_account_id.rb new file mode 100644 index 000000000..a04e2a5c5 --- /dev/null +++ b/db/migrate/20230727065605_add_partial_index_contact_account_id.rb @@ -0,0 +1,8 @@ +class AddPartialIndexContactAccountId < ActiveRecord::Migration[7.0] + disable_ddl_transaction! + + def change + add_index :contacts, [:account_id], where: "(email <> '' OR phone_number <> '' OR identifier <> '')", + name: 'index_resolved_contact_account_id', algorithm: :concurrently + end +end diff --git a/db/schema.rb b/db/schema.rb index 373dfbec1..13d5e6925 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[7.0].define(version: 2023_07_14_054138) do +ActiveRecord::Schema[7.0].define(version: 2023_07_27_065605) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" enable_extension "pg_trgm" @@ -408,6 +408,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_14_054138) do t.index "lower((email)::text), account_id", name: "index_contacts_on_lower_email_account_id" t.index ["account_id", "email", "phone_number", "identifier"], name: "index_contacts_on_nonempty_fields", where: "(((email)::text <> ''::text) OR ((phone_number)::text <> ''::text) OR ((identifier)::text <> ''::text))" t.index ["account_id"], name: "index_contacts_on_account_id" + t.index ["account_id"], name: "index_resolved_contact_account_id", where: "(((email)::text <> ''::text) OR ((phone_number)::text <> ''::text) OR ((identifier)::text <> ''::text))" t.index ["email", "account_id"], name: "uniq_email_per_account_contact", unique: true t.index ["identifier", "account_id"], name: "uniq_identifier_per_account_contact", unique: true t.index ["name", "email", "phone_number", "identifier"], name: "index_contacts_on_name_email_phone_number_identifier", opclass: :gin_trgm_ops, using: :gin