DT
Drizzle Team•10mo ago
BaNuni

"Duplicate Index" - but no dupliacte index...

Hey there, I've HAD a duplicate index in one of my schemas:
{ tenantId, f0, f1, f2 }) => ({
myUniqueIdx: uniqueIndex('uniqueIdx').on(tenantId, f1, f2),
myIdx: index('imyIdx').on(tenantId, f0, f1, f2),
myOtherIdx: index('myIdx').on(tenantId, f0, f2, f1),
}
{ tenantId, f0, f1, f2 }) => ({
myUniqueIdx: uniqueIndex('uniqueIdx').on(tenantId, f1, f2),
myIdx: index('imyIdx').on(tenantId, f0, f1, f2),
myOtherIdx: index('myIdx').on(tenantId, f0, f2, f1),
}
which resulted in the first one overridden in the generated migration. this code is already deployed I added 2 columns, (e.g f3 and f4) and when I'm trying to generate migrations (pg) I'm getting
We've found duplicated index name across public schema. Please rename your index in either the myTable table or the table with the duplicated index name
We've found duplicated index name across public schema. Please rename your index in either the myTable table or the table with the duplicated index name
Even though currently I've no duplication nowhere... I want to fix it now, so I changed to the very very sure that's not duplicate:
{ tenantId, f0, f1, f2 }) => ({
myUniqueIdx: uniqueIndex('aaa').on(tenantId, f1, f2),
myIdx: index('bbb').on(tenantId, f0, f1, f2),
myOtherIdx: index('ccc').on(tenantId, f0, f2, f1),
}
{ tenantId, f0, f1, f2 }) => ({
myUniqueIdx: uniqueIndex('aaa').on(tenantId, f1, f2),
myIdx: index('bbb').on(tenantId, f0, f1, f2),
myOtherIdx: index('ccc').on(tenantId, f0, f2, f1),
}
but I get the same error... If I remove all of them completely, The generation succeeds. Whay am I missing?
8 Replies
Angelelz
Angelelz•10mo ago
Try manually running the following query and see what comes out. I feel like this is a good first debugging step:
const indexes = db.execute(sql`SELECT tablename, indexname, indexdef
FROM pg_indexes
WHERE schemaname = 'public'
ORDER BY tablename, indexname`
);
console.log(indexes);
const indexes = db.execute(sql`SELECT tablename, indexname, indexdef
FROM pg_indexes
WHERE schemaname = 'public'
ORDER BY tablename, indexname`
);
console.log(indexes);
Also, your diplicate index, might be comming from another table, so check the migration file and to actually see that index drizzle-kit is actually trying to create
BaNuni
BaNuni•10mo ago
this was coming out when I was trying to generate migrations... Anyway, I think it had to do with some weird state of files on my machine
Angelelz
Angelelz•10mo ago
Very likely
Andrii Sherman
Andrii Sherman•10mo ago
index names should be unique across all tables
Keroz
Keroz•10mo ago
In case you are still having this issue and do not have any duplicate index, I was having this issue with no duplicate indexes (using Postgres) doing the following commands (im using pnpm): First i ran: pnpm drizzle-kit up:pg Then uninstalled both packages: pnpm remove drizzle-kit drizzle-orm Then installed both packages (clean install) pnpm add drizzle-kit drizzle-orm My version of drizzle-kit was updated to a newer version and i was able to run pnpm drizzle-kit generate:pg without any issue successfully adding the migration i was trying to add.
BaNuni
BaNuni•10mo ago
cool! thanks for giving an answer 🙂 I actually had to workaround this problem, but it's good to know that a valid solution is available
Keroz
Keroz•10mo ago
Just out of curiosity, what was your workaround? ThinkThink
BaNuni
BaNuni•9mo ago
drop all indexes, recreate them... =[
Want results from more Discord servers?
Add your server