Merge pull request #13163 from cyrillefr/FixRailsUniqueValidationWithoutIndex

Fixes Rails/UniqueValidationWithoutIndex (part of #11482)
This commit is contained in:
Maikel
2025-06-10 16:35:13 +10:00
committed by GitHub
7 changed files with 45 additions and 7 deletions

View File

@@ -63,7 +63,6 @@ Metrics/ClassLength:
- 'app/controllers/spree/admin/payment_methods_controller.rb'
- 'app/controllers/spree/admin/payments_controller.rb'
- 'app/controllers/spree/admin/products_controller.rb'
- 'app/controllers/spree/admin/users_controller.rb'
- 'app/controllers/spree/orders_controller.rb'
- 'app/models/enterprise.rb'
- 'app/models/invoice/data_presenter.rb'
@@ -149,7 +148,7 @@ Metrics/MethodLength:
- 'lib/spree/localized_number.rb'
- 'lib/tasks/sample_data/product_factory.rb'
# Offense count: 49
# Offense count: 47
# Configuration parameters: CountComments, Max, CountAsOne.
Metrics/ModuleLength:
Exclude:
@@ -176,12 +175,10 @@ Metrics/ModuleLength:
- 'spec/controllers/admin/order_cycles_controller_spec.rb'
- 'spec/controllers/api/v0/order_cycles_controller_spec.rb'
- 'spec/controllers/api/v0/orders_controller_spec.rb'
- 'spec/controllers/payment_gateways/stripe_controller_spec.rb'
- 'spec/controllers/spree/admin/adjustments_controller_spec.rb'
- 'spec/controllers/spree/admin/payment_methods_controller_spec.rb'
- 'spec/controllers/spree/admin/variants_controller_spec.rb'
- 'spec/lib/open_food_network/address_finder_spec.rb'
- 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb'
- 'spec/lib/open_food_network/order_cycle_form_applicator_spec.rb'
- 'spec/lib/open_food_network/order_cycle_permissions_spec.rb'
- 'spec/lib/open_food_network/permissions_spec.rb'

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -105,7 +105,7 @@ ActiveRecord::Schema[7.0].define(version: 2025_03_04_234657) do
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"
@@ -270,7 +270,7 @@ ActiveRecord::Schema[7.0].define(version: 2025_03_04_234657) do
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|
@@ -834,7 +834,7 @@ ActiveRecord::Schema[7.0].define(version: 2025_03_04_234657) do
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|
@@ -872,6 +872,7 @@ ActiveRecord::Schema[7.0].define(version: 2025_03_04_234657) do
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|
@@ -1001,6 +1002,7 @@ ActiveRecord::Schema[7.0].define(version: 2025_03_04_234657) do
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|