-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(): Remove redundant indexes to resolve schema warnings #13736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Several tables within the cart module had duplicate indexes created by older migrations. These provide no performance benefit and add unnecessary overhead to write operations (INSERT, UPDATE). This commit introduces a new migration to safely drop the older, redundant indexes, keeping the more explicitly named ones. Removes the following indexes: - `IDX_line_item_cart_id` from `cart_line_item` - `IDX_adjustment_item_id` from `cart_line_item_adjustment` - `IDX_tax_line_item_id` from `cart_line_item_tax_line` - `IDX_shipping_method_cart_id` from `cart_shipping_method` - `IDX_adjustment_shipping_method_id` from `cart_shipping_method_adjustment` - `IDX_tax_line_shipping_method_id` from `cart_shipping_method_tax_line`
Database linters identified several instances of duplicate indexes on the `order_item` and `order_shipping` tables.
An analysis of the database schema identified two functionally identical unique indexes on the `name` column of the `customer_group` table: `IDX_customer_group_name` and `IDX_customer_group_name_unique`.
A database schema analysis revealed two functionally identical unique composite indexes on the `inventory_level` table: `IDX_inventory_level_item_location` and `IDX_inventory_level_location_id_inventory_item_id`.
🦋 Changeset detectedLatest commit: 3d6bacd The changes in this PR will be included in the next version bump. This PR includes changesets to release 74 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@DDA1O1 is attempting to deploy a commit to the medusajs Team on Vercel. A member of the Team first needs to authorize it. |
fcc7791
to
00d2b9d
Compare
packages/modules/order/src/migrations/Migration20251010125912.ts
Outdated
Show resolved
Hide resolved
packages/modules/order/src/migrations/Migration20251010125912.ts
Outdated
Show resolved
Hide resolved
packages/modules/product/src/migrations/Migration20251011090616.ts
Outdated
Show resolved
Hide resolved
hey @willbouch , I've made all the changes you suggested. |
hey thanks for letting me know definitely going to clean the dropped indexes |
Removed unused index 'IDX_order_shipping_version' from order shipping methods model.
I see you cleaned them up, but the thing is that I feel some are missing no? You cleaned up duplicates, that's fine, but it looks like the model now do not define the IDX that actually live in the database. The model has one IDX defined, which you removed, but the database had 2 IDX and you removed one. That means that the model is missing the actual IDX missing no? |
I should have talked to you before implementing any change. Is there anything else that i should watch out or should i define the indexes that actually live in the database |
@DDA1O1 Yeah I did not know before yesterday that the IDS were defined in the model too, sorry on that one. That being said, I believe you should just clean up the ones that are not in the model. Even if the name of the index is not the best one of the 2, it is simpler to get rid of those ones that are not in the model I think |
Fixes #13735
What
This Pull Request introduces new database migrations to remove multiple redundant indexes across several core modules, including product, cart, order, customer, and inventory.
Why
As detailed in issue #13735, a fresh Medusa installation produces numerous "Duplicate Index" warnings. These legacy indexes add unnecessary write overhead and provide no performance benefit. This PR cleans up the schema to resolve these warnings and improve database health.
How
I have added one new, reversible migration file for each of the five affected modules:
@medusajs/product
@medusajs/cart
@medusajs/order
@medusajs/customer
@medusajs/inventory
Each migration's
up()
method safely drops the older, redundant index, and itsdown()
method re-creates it, ensuring the change is fully reversible and non-destructive.Testing
I have tested these migrations by following the local development workflow outlined in the
CONTRIBUTING.md
guide.Setup:
npx create-medusa-app@latest my-medusa-store
.Linking Local Source Code:
package.json
, I modified all@medusajs/*
dependencies and resolutions to point to the local packages in my forked repository (e.g.,"@medusajs/product": "file:../medusa/packages/modules/product"
).yarn install
to link the local, modified Medusa source code into itsnode_modules
.Build & Migration:
yarn build
to compile the new TypeScript migration files.npx medusa migration run
.Verification:
product_collection
,customer_group
, etc.).