Fixes Rails/UniqueValidationWithoutIndex (part of #11482)

- When you define a uniqueness validation in Active Record model,
  you also should add a unique index for the column.
- Cf. https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsuniquevalidationwithoutindex
- Therefore : migration files to match DB structure and Ruby code.
This commit is contained in:
cyrillefr
2025-02-18 14:59:23 +01:00
committed by Maikel Linke
parent c9ec7e13d3
commit 774aaf4fd8
6 changed files with 40 additions and 4 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