diff --git a/app/models/school.rb b/app/models/school.rb index 39ff2d48..24531d48 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -23,7 +23,6 @@ class School < ApplicationRecord format: { with: /\A\d{5,6}\z/, allow_nil: true, message: I18n.t('validations.school.reference') }, if: :united_kingdom? validates :district_nces_id, - uniqueness: { conditions: -> { where(rejected_at: nil) }, case_sensitive: false, allow_blank: true, message: I18n.t('validations.school.district_nces_id_exists') }, format: { with: /\A\d{7}\z/, allow_nil: true, message: I18n.t('validations.school.district_nces_id') }, if: :united_states? validates :district_name, presence: true, if: :united_states? diff --git a/config/locales/en.yml b/config/locales/en.yml index 3cfba122..5cef4714 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -18,7 +18,6 @@ en: reference: "must be 5-6 digits (e.g., 100000)" reference_urn_exists: "URN number already exists" district_nces_id: "must be 7 digits (e.g., 0100000)" - district_nces_id_exists: "NCES ID already exists" school_roll_number: "must be numbers followed by letters (e.g., 01572D)" school_roll_number_exists: "School roll number already exists" invitation: diff --git a/db/migrate/20260116164502_remove_unique_index_from_schools_district_nces_id.rb b/db/migrate/20260116164502_remove_unique_index_from_schools_district_nces_id.rb new file mode 100644 index 00000000..025502ed --- /dev/null +++ b/db/migrate/20260116164502_remove_unique_index_from_schools_district_nces_id.rb @@ -0,0 +1,5 @@ +class RemoveUniqueIndexFromSchoolsDistrictNcesId < ActiveRecord::Migration[7.2] + def change + remove_index :schools, name: "index_schools_on_district_nces_id" + end +end diff --git a/db/schema.rb b/db/schema.rb index 447f0582..0b9bf772 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.2].define(version: 2025_12_08_134354) do +ActiveRecord::Schema[7.2].define(version: 2026_01_16_164502) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -311,7 +311,6 @@ t.string "school_roll_number" t.index ["code"], name: "index_schools_on_code", unique: true t.index ["creator_id"], name: "index_schools_on_creator_id", unique: true - t.index ["district_nces_id"], name: "index_schools_on_district_nces_id", unique: true, where: "(rejected_at IS NULL)" t.index ["reference"], name: "index_schools_on_reference", unique: true, where: "(rejected_at IS NULL)" t.index ["school_roll_number"], name: "index_schools_on_school_roll_number", unique: true, where: "(rejected_at IS NULL)" end diff --git a/spec/models/school_spec.rb b/spec/models/school_spec.rb index 5e2b7f1c..06846060 100644 --- a/spec/models/school_spec.rb +++ b/spec/models/school_spec.rb @@ -241,12 +241,6 @@ expect(duplicate_school).not_to be_valid end - it 'returns error if district_nces_id is not unique' do - duplicate_school = build(:school, country_code: 'US', district_nces_id: '0100000') - duplicate_school.valid? - expect(duplicate_school.errors.details[:district_nces_id]).to include(hash_including(error: :taken)) - end - it 'accepts a valid district_nces_id format (7 digits)' do us_school.district_nces_id = '0100000' expect(us_school).to be_valid