diff --git a/.changeset/hot-coins-itch.md b/.changeset/hot-coins-itch.md new file mode 100644 index 0000000000000..4f4a08dbf5486 --- /dev/null +++ b/.changeset/hot-coins-itch.md @@ -0,0 +1,5 @@ +--- +"@medusajs/utils": patch +--- + +feat(utils): make psql index util return index instead of constraint for unique indicies becuase partial constraints don't exist :'( diff --git a/packages/utils/src/common/__tests__/create-psql-index-helper.ts b/packages/utils/src/common/__tests__/create-psql-index-helper.ts index ec2c70178e80f..321e87c913290 100644 --- a/packages/utils/src/common/__tests__/create-psql-index-helper.ts +++ b/packages/utils/src/common/__tests__/create-psql-index-helper.ts @@ -73,9 +73,9 @@ describe("createPsqlIndexStatementHelper", function () { const indexStatement = createPsqlIndexStatementHelper(options) expect(indexStatement).toEqual( - `ALTER TABLE IF EXISTS "${options.tableName}" ADD CONSTRAINT "${ - options.name - }" UNIQUE (${options.columns.join(", ")}) WHERE ${options.where}` + `CREATE UNIQUE INDEX IF NOT EXISTS "${options.name}" ON "${ + options.tableName + }" (${options.columns.join(", ")}) WHERE ${options.where}` ) }) }) diff --git a/packages/utils/src/common/create-psql-index-helper.ts b/packages/utils/src/common/create-psql-index-helper.ts index 8d7529d58224f..f482bd360617a 100644 --- a/packages/utils/src/common/create-psql-index-helper.ts +++ b/packages/utils/src/common/create-psql-index-helper.ts @@ -45,10 +45,7 @@ export function createPsqlIndexStatementHelper({ columns = Array.isArray(columns) ? columns.join(", ") : columns const typeStr = type ? ` USING ${type}` : "" const optionsStr = where ? ` WHERE ${where}` : "" + const uniqueStr = unique ? "UNIQUE " : "" - if (!unique) { - return `CREATE INDEX IF NOT EXISTS "${name}" ON "${tableName}"${typeStr} (${columns})${optionsStr}` - } else { - return `ALTER TABLE IF EXISTS "${tableName}" ADD CONSTRAINT "${name}" UNIQUE (${columns})${optionsStr}` - } + return `CREATE ${uniqueStr}INDEX IF NOT EXISTS "${name}" ON "${tableName}"${typeStr} (${columns})${optionsStr}` }