diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 42a63b3b7db..1fb9f14157c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -604,17 +604,6 @@ Rails/TransactionExitStatement: Exclude: - 'app/services/place_proxy_order.rb' -# Offense count: 5 -# Configuration parameters: Include. -# Include: app/models/**/*.rb -Rails/UniqueValidationWithoutIndex: - Exclude: - - 'app/models/customer.rb' - - 'app/models/exchange.rb' - - 'app/models/spree/stock_item.rb' - - 'app/models/spree/tax_category.rb' - - 'app/models/spree/zone.rb' - # Offense count: 1 Security/Open: Exclude: diff --git a/db/migrate/20250214192930_add_unique_index_email_entreprise_to_customers.rb b/db/migrate/20250214192930_add_unique_index_email_entreprise_to_customers.rb new file mode 100644 index 00000000000..c41d4baecef --- /dev/null +++ b/db/migrate/20250214192930_add_unique_index_email_entreprise_to_customers.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class AddUniqueIndexEmailEntrepriseToCustomers < ActiveRecord::Migration[7.0] + def change + remove_index :customers, :email, name: :index_customers_on_email + add_index(:customers, [:email, :enterprise_id], unique: true) + end +end diff --git a/db/migrate/20250214200526_add_unique_index_sender_id_and_others_to_exchanges.rb b/db/migrate/20250214200526_add_unique_index_sender_id_and_others_to_exchanges.rb new file mode 100644 index 00000000000..5f3e072129f --- /dev/null +++ b/db/migrate/20250214200526_add_unique_index_sender_id_and_others_to_exchanges.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddUniqueIndexSenderIdAndOthersToExchanges < ActiveRecord::Migration[7.0] + def change + remove_index :exchanges, :sender_id, name: :index_exchanges_on_sender_id + add_index(:exchanges, [:sender_id, :order_cycle_id, :receiver_id, :incoming], + unique: true, name: :index_exchanges_on_sender_id) + end +end diff --git a/db/migrate/20250215083320_add_unique_index_variant_id_and_deleted_at_to_stock_items.rb b/db/migrate/20250215083320_add_unique_index_variant_id_and_deleted_at_to_stock_items.rb new file mode 100644 index 00000000000..667643d2dd4 --- /dev/null +++ b/db/migrate/20250215083320_add_unique_index_variant_id_and_deleted_at_to_stock_items.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class AddUniqueIndexVariantIdAndDeletedAtToStockItems < ActiveRecord::Migration[7.0] + def change + remove_index :spree_stock_items, :variant_id, name: :index_spree_stock_items_on_variant_id + add_index(:spree_stock_items, [:variant_id, :deleted_at], unique: true) + end +end diff --git a/db/migrate/20250215085838_add_unique_index_name_and_deleted_at_to_tax_categories.rb b/db/migrate/20250215085838_add_unique_index_name_and_deleted_at_to_tax_categories.rb new file mode 100644 index 00000000000..06b34970fa4 --- /dev/null +++ b/db/migrate/20250215085838_add_unique_index_name_and_deleted_at_to_tax_categories.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddUniqueIndexNameAndDeletedAtToTaxCategories < ActiveRecord::Migration[7.0] + def change + add_index(:spree_tax_categories, [:name, :deleted_at], unique: true) + end +end diff --git a/db/migrate/20250215091227_add_unique_index_name_to_zones.rb b/db/migrate/20250215091227_add_unique_index_name_to_zones.rb new file mode 100644 index 00000000000..975d42be520 --- /dev/null +++ b/db/migrate/20250215091227_add_unique_index_name_to_zones.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddUniqueIndexNameToZones < ActiveRecord::Migration[7.0] + def change + add_index(:spree_zones, :name, unique: true) + end +end diff --git a/db/schema.rb b/db/schema.rb index a20327a48ad..48eec2e56cb 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: 2025_01_28_031518) do +ActiveRecord::Schema[7.0].define(version: 2025_02_15_091227) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" enable_extension "plpgsql" @@ -105,7 +105,7 @@ t.boolean "created_manually", default: false t.index ["bill_address_id"], name: "index_customers_on_bill_address_id" t.index ["created_manually"], name: "index_customers_on_created_manually" - t.index ["email"], name: "index_customers_on_email" + t.index ["email", "enterprise_id"], name: "index_customers_on_email_and_enterprise_id", unique: true t.index ["enterprise_id", "code"], name: "index_customers_on_enterprise_id_and_code", unique: true t.index ["ship_address_id"], name: "index_customers_on_ship_address_id" t.index ["user_id"], name: "index_customers_on_user_id" @@ -268,7 +268,7 @@ t.text "receival_instructions" t.index ["order_cycle_id"], name: "index_exchanges_on_order_cycle_id" t.index ["receiver_id"], name: "index_exchanges_on_receiver_id" - t.index ["sender_id"], name: "index_exchanges_on_sender_id" + t.index ["sender_id", "order_cycle_id", "receiver_id", "incoming"], name: "index_exchanges_on_sender_id", unique: true end create_table "flipper_features", id: :serial, force: :cascade do |t| @@ -832,7 +832,7 @@ t.integer "lock_version", default: 0 t.index ["stock_location_id", "variant_id"], name: "stock_item_by_loc_and_var_id" t.index ["stock_location_id"], name: "index_spree_stock_items_on_stock_location_id" - t.index ["variant_id"], name: "index_spree_stock_items_on_variant_id", unique: true + t.index ["variant_id", "deleted_at"], name: "index_spree_stock_items_on_variant_id_and_deleted_at", unique: true end create_table "spree_stock_locations", id: :serial, force: :cascade do |t| @@ -870,6 +870,7 @@ t.datetime "updated_at", precision: nil, null: false t.boolean "is_default", default: false t.datetime "deleted_at", precision: nil + t.index ["name", "deleted_at"], name: "index_spree_tax_categories_on_name_and_deleted_at", unique: true end create_table "spree_tax_rates", id: :serial, force: :cascade do |t| @@ -999,6 +1000,7 @@ t.datetime "updated_at", precision: nil, null: false t.boolean "default_tax", default: false t.integer "zone_members_count", default: 0 + t.index ["name"], name: "index_spree_zones_on_name", unique: true end create_table "stripe_accounts", id: :serial, force: :cascade do |t|