From 2132582f6d6ebac080352354df95fa55d2e489a3 Mon Sep 17 00:00:00 2001 From: Aniket Patidar Date: Sat, 19 Sep 2026 21:03:41 +0530 Subject: [PATCH 1/2] Clean up old kit table and items.kit_id column (#5679) --- app/models/concrete_item.rb | 1 - app/models/item.rb | 1 - app/models/kit.rb | 1 - ...0000_remove_kits_table_and_items_kit_id.rb | 14 ++++++++++++++ db/schema.rb | 19 +------------------ spec/factories/items.rb | 1 - spec/factories/kits.rb | 1 - spec/models/item_spec.rb | 1 - spec/models/kit_spec.rb | 1 - 9 files changed, 15 insertions(+), 25 deletions(-) create mode 100644 db/migrate/20260919150000_remove_kits_table_and_items_kit_id.rb diff --git a/app/models/concrete_item.rb b/app/models/concrete_item.rb index f5a9c31e15..260c4abe65 100644 --- a/app/models/concrete_item.rb +++ b/app/models/concrete_item.rb @@ -20,7 +20,6 @@ # created_at :datetime not null # updated_at :datetime not null # item_category_id :integer -# kit_id :integer # organization_id :integer # class ConcreteItem < Item diff --git a/app/models/item.rb b/app/models/item.rb index 2920322500..4cacd71f4f 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -20,7 +20,6 @@ # created_at :datetime not null # updated_at :datetime not null # item_category_id :integer -# kit_id :integer # organization_id :integer # diff --git a/app/models/kit.rb b/app/models/kit.rb index 59d79bd846..29993843ef 100644 --- a/app/models/kit.rb +++ b/app/models/kit.rb @@ -20,7 +20,6 @@ # created_at :datetime not null # updated_at :datetime not null # item_category_id :integer -# kit_id :integer # organization_id :integer # class Kit < Item diff --git a/db/migrate/20260919150000_remove_kits_table_and_items_kit_id.rb b/db/migrate/20260919150000_remove_kits_table_and_items_kit_id.rb new file mode 100644 index 0000000000..0662f0766e --- /dev/null +++ b/db/migrate/20260919150000_remove_kits_table_and_items_kit_id.rb @@ -0,0 +1,14 @@ +class RemoveKitsTableAndItemsKitId < ActiveRecord::Migration[8.1] + def up + safety_assured do + remove_foreign_key :items, :kits if foreign_key_exists?(:items, :kits) + remove_foreign_key :kit_allocations, :kits if foreign_key_exists?(:kit_allocations, :kits) + remove_column :items, :kit_id, :integer if column_exists?(:items, :kit_id) + drop_table :kits if table_exists?(:kits) + end + end + + def down + fail ActiveRecord::IrreversibleMigration + end +end diff --git a/db/schema.rb b/db/schema.rb index c9e1d95553..e3bc379973 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[8.1].define(version: 2026_08_29_112930) do +ActiveRecord::Schema[8.1].define(version: 2026_09_19_150000) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" @@ -398,7 +398,6 @@ t.datetime "created_at", precision: nil, null: false t.integer "distribution_quantity" t.integer "item_category_id" - t.integer "kit_id" t.string "name" t.integer "on_hand_minimum_quantity", default: 0, null: false t.integer "on_hand_recommended_quantity" @@ -411,7 +410,6 @@ t.datetime "updated_at", precision: nil, null: false t.integer "value_in_cents", default: 0 t.boolean "visible_to_partners", default: true, null: false - t.index ["kit_id"], name: "index_items_on_kit_id" t.index ["organization_id"], name: "index_items_on_organization_id" t.index ["partner_key"], name: "index_items_on_partner_key" t.check_constraint "distribution_quantity >= 0", name: "distribution_quantity_nonnegative" @@ -429,18 +427,6 @@ t.index ["storage_location_id"], name: "index_kit_allocations_on_storage_location_id" end - create_table "kits", force: :cascade do |t| - t.boolean "active", default: true - t.datetime "created_at", null: false - t.string "name", null: false - t.integer "organization_id", null: false - t.datetime "updated_at", null: false - t.integer "value_in_cents", default: 0 - t.boolean "visible_to_partners", default: true, null: false - t.index ["name", "organization_id"], name: "index_kits_on_name_and_organization_id", unique: true - t.index ["organization_id"], name: "index_kits_on_organization_id" - end - create_table "line_items", id: :serial, force: :cascade do |t| t.datetime "created_at", precision: nil, null: false t.integer "item_id" @@ -878,11 +864,8 @@ add_foreign_key "item_categories_partner_groups", "partner_groups" add_foreign_key "item_units", "items" add_foreign_key "items", "item_categories" - add_foreign_key "items", "kits" - add_foreign_key "kit_allocations", "kits" add_foreign_key "kit_allocations", "organizations" add_foreign_key "kit_allocations", "storage_locations" - add_foreign_key "kits", "organizations" add_foreign_key "manufacturers", "organizations" add_foreign_key "organizations", "account_requests" add_foreign_key "organizations", "ndbn_members", primary_key: "ndbn_member_id" diff --git a/spec/factories/items.rb b/spec/factories/items.rb index 9eb6df4fdf..dbe8c6aa34 100644 --- a/spec/factories/items.rb +++ b/spec/factories/items.rb @@ -20,7 +20,6 @@ # created_at :datetime not null # updated_at :datetime not null # item_category_id :integer -# kit_id :integer # organization_id :integer # diff --git a/spec/factories/kits.rb b/spec/factories/kits.rb index fa61583aad..c057aefe8a 100644 --- a/spec/factories/kits.rb +++ b/spec/factories/kits.rb @@ -20,7 +20,6 @@ # created_at :datetime not null # updated_at :datetime not null # item_category_id :integer -# kit_id :integer # organization_id :integer # FactoryBot.define do diff --git a/spec/models/item_spec.rb b/spec/models/item_spec.rb index 02e2ae7083..f4b0c35262 100644 --- a/spec/models/item_spec.rb +++ b/spec/models/item_spec.rb @@ -20,7 +20,6 @@ # created_at :datetime not null # updated_at :datetime not null # item_category_id :integer -# kit_id :integer # organization_id :integer # diff --git a/spec/models/kit_spec.rb b/spec/models/kit_spec.rb index 8ed9b3996e..030ae3b0f2 100644 --- a/spec/models/kit_spec.rb +++ b/spec/models/kit_spec.rb @@ -20,7 +20,6 @@ # created_at :datetime not null # updated_at :datetime not null # item_category_id :integer -# kit_id :integer # organization_id :integer # From 8564e2887b0999537837ade7e132f927311a681e Mon Sep 17 00:00:00 2001 From: Aniket Patidar Date: Sat, 26 Sep 2026 01:23:17 +0530 Subject: [PATCH 2/2] Drop unused kit_allocations table and enum (#5679) --- ...19150000_remove_kits_table_and_items_kit_id.rb | 3 ++- db/schema.rb | 15 --------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/db/migrate/20260919150000_remove_kits_table_and_items_kit_id.rb b/db/migrate/20260919150000_remove_kits_table_and_items_kit_id.rb index 0662f0766e..6016bc424c 100644 --- a/db/migrate/20260919150000_remove_kits_table_and_items_kit_id.rb +++ b/db/migrate/20260919150000_remove_kits_table_and_items_kit_id.rb @@ -1,8 +1,9 @@ class RemoveKitsTableAndItemsKitId < ActiveRecord::Migration[8.1] def up safety_assured do + drop_table :kit_allocations if table_exists?(:kit_allocations) + drop_enum :kit_allocation_type, if_exists: true remove_foreign_key :items, :kits if foreign_key_exists?(:items, :kits) - remove_foreign_key :kit_allocations, :kits if foreign_key_exists?(:kit_allocations, :kits) remove_column :items, :kit_id, :integer if column_exists?(:items, :kit_id) drop_table :kits if table_exists?(:kits) end diff --git a/db/schema.rb b/db/schema.rb index e3bc379973..aebfe3bfa5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -17,7 +17,6 @@ # Custom types defined in this database. # Note that some types may not work with other database engines. Be careful if changing database. create_enum "category", ["US_County", "Other"] - create_enum "kit_allocation_type", ["inventory_in", "inventory_out"] create_table "account_requests", force: :cascade do |t| t.datetime "confirmed_at", precision: nil @@ -415,18 +414,6 @@ t.check_constraint "distribution_quantity >= 0", name: "distribution_quantity_nonnegative" end - create_table "kit_allocations", force: :cascade do |t| - t.datetime "created_at", null: false - t.enum "kit_allocation_type", default: "inventory_in", null: false, enum_type: "kit_allocation_type" - t.bigint "kit_id", null: false - t.bigint "organization_id", null: false - t.bigint "storage_location_id", null: false - t.datetime "updated_at", null: false - t.index ["kit_id"], name: "index_kit_allocations_on_kit_id" - t.index ["organization_id"], name: "index_kit_allocations_on_organization_id" - t.index ["storage_location_id"], name: "index_kit_allocations_on_storage_location_id" - end - create_table "line_items", id: :serial, force: :cascade do |t| t.datetime "created_at", precision: nil, null: false t.integer "item_id" @@ -864,8 +851,6 @@ add_foreign_key "item_categories_partner_groups", "partner_groups" add_foreign_key "item_units", "items" add_foreign_key "items", "item_categories" - add_foreign_key "kit_allocations", "organizations" - add_foreign_key "kit_allocations", "storage_locations" add_foreign_key "manufacturers", "organizations" add_foreign_key "organizations", "account_requests" add_foreign_key "organizations", "ndbn_members", primary_key: "ndbn_member_id"