medusajs / medusa

Building blocks for digital commerce
https://medusajs.com
MIT License
24.63k stars 2.43k forks source link

Wrong column name in migration for unique key with camelCase naming #9049

Closed Bosek closed 6 days ago

Bosek commented 1 week ago

Consider this snippet from model definition: vatId: model.text().unique()

After calling npx medusa db:generate

create table if not exists "economic_subject" ("id" text not null, "vat_id" text not null, ...
CREATE UNIQUE INDEX IF NOT EXISTS "IDX_economic_subject_vat_unique" ON "economic_subject" (vatId) WHERE deleted_at IS NULL;

It will correctly change column name from vatId to vat_id(first row), but will not use it for setting up a unique key(second row). Error: CREATE UNIQUE INDEX IF NOT EXISTS "IDX_economic_subject_vatId_unique" ON "economic_subject" (vatId) WHERE deleted_at IS NULL; - column "vatId" does not exist

System information

Medusa version: 1.20.6-preview-20240906120706 Node.js version: v21.2.0

olivermrbl commented 1 week ago

@Bosek, thanks for highlighting. We are not handling casing on our custom modifiers, such as unique. The ORM we use under the hood converts column names to a lowercase + underscored version and I believe we will need to do the same.

We'll get back with a solution asap.

Until then, you can use snake_cased column names, and it should work as expected.