-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Description
Package.json file
This issue is not specific to a single user project's `package.json`. It is a schema bug originating from the migration files within the core Medusa repository (`@medusajs/cart`, `@medusajs/product`, etc.). The bug is present in the latest version of Medusa created via `npx create-medusa-app@latest my-medusa-store`.
Node.js version
v21.0.0
Database and its version
PostgreSQL 16.2
Operating system name and version
Any
Browser name
N/A
What happended?
After a fresh installation of Medusa pointing to a new PostgreSQL database, the database schema contains multiple duplicate indexes. These are identified by database analysis tools like the Supabase Advisor.
The redundant indexes exist on tables across several core modules, including:
product_collection
cart_line_item
and other cart-related tablesorder_item
andorder_shipping
customer_group
inventory_level
This is caused by legacy database migrations creating indexes that were later replaced by newer migrations with better-named indexes, but the old ones were never dropped
Expected behavior
The database schema generated by Medusa's migrations should be clean, efficient, and free of redundant objects. No Duplicate Index
warnings should be present after a fresh installation.
Actual behavior
The database contains unnecessary duplicate indexes. This adds a small but real performance overhead to all write operations (INSERT, UPDATE, DELETE) on the affected tables and causes warnings in database health-checking tools.
A separate reproduction repository is not required as the issue can be reproduced directly with the Medusa CLI.
Steps to Reproduce:
Create a new Medusa project: npx create-medusa-app@latest my-medusa-store
Configure the .env file to point to a fresh, empty PostgreSQL database (e.g., on Supabase).
Inspect the database schema by running the following SQL query on one of the affected tables:
SELECT
tablename,
indexname,
indexdef
FROM
pg_indexes
WHERE
tablename = 'customer_group';
Observe that two functionally identical indexes exist on the name column. The same pattern exists for the other tables mentioned.
Link to reproduction repo
N/A