-
-
Notifications
You must be signed in to change notification settings - Fork 758
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
[BUG]: Drizzle keep removing and re-adding a unique index with multiple fields #3764
Comments
I have the same but when i use the nullsNotDistinct option:
When i leave out the option the push command doesn't ask to recreate. |
@kaeon Try |
I think what happens is when the db introspection happens, the columns are sorted. This is compared against your current state, which is always out of order. Not sure of the mechanisms used, but either they both should be sorted, or the order should be deemed to be important and neither should be sorted, any column reordering should result in a dangerous operation. Trying to be clever and ascertaining in which situations column order definition will not matter seems like a recipe for disaster |
thanks for the suggestion but unfortunately result is the same. I also tried to order them in the order of the columns in my schema now but also same result
|
What does it say when you do an introspect, what is the diff between your
schema and the generated one?
…On Fri, 24 Jan 2025 at 23:30, kaeon ***@***.***> wrote:
@kaeon <https://github.com/kaeon> Try t => [
unique('unique_assignment').on(t.assetId, t.buildingId, t.companyId,
t.documentId, t.templateId ).nullsNotDistinct(), ]
thanks for the suggestion but unfortunately result is the same. I also
tried to order them in the order of the columns in my schema now but also
same result
export const tCompDocumentAssignment = pgTable(
'comp_document_assignment', { id: nanoIdCharPrimary, documentId:
nanoIdChar() .references(() => tCompDocument.id) .notNull(), assetId:
nanoIdChar().references(() => tCompAsset.id), buildingId:
nanoIdChar().references(() => tCompBuilding.id), templateId: nanoIdChar()
.references(() => tBcDocument.id) .notNull(), companyId: nanoIdChar()
.references(() => tCompany.id) .notNull(), ...commonFields, }, t => [
unique('unique_doc_assignment').on(t.documentId, t.assetId, t.buildingId,
t.templateId, t.companyId).nullsNotDistinct(), ] );
—
Reply to this email directly, view it on GitHub
<#3764 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB2QMPRF4T4GLSPSFHNH7D2MJL7NAVCNFSM6AAAAABTS5EKSGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMJSHAYDCNBUG4>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Good suggestion! export const compDocumentAssignment = pgTable("comp_document_assignment", { |
I put a PR in which appears to fix it. I tested OP's example and it now doesn't try to re-create the index with the columns ordered wrongly. |
Hi @Mardoxx Mardoxx, thanks for this PR! Probably it will take a while before implemented. Can you think of a workaround for me to get these unique NullsNotDistinct implemented anyway with the current version. It's blocking my project! |
Temporarily replace it in the relevant file in node_modules (cli.cjs or
something?) If you do a global search in node_modiles for part of the old
query you should be able to find it.
- that’s what I did
…On Tue, 28 Jan 2025 at 14:24, kaeon ***@***.***> wrote:
I put a PR in which appears to fix it. I tested OP's example and it now
doesn't try to re-create the index with the columns ordered wrongly.
Hi @Mardoxx <https://github.com/Mardoxx> Mardoxx, thanks for this PR!
Probably it will take a while before implemented. Can you think of a
workaround for me to get these unique NullsNotDistinct implemented anyway
with the current version. It's blocking my project!
—
Reply to this email directly, view it on GitHub
<#3764 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB2QMKPG752F2URYGIDZIT2M4PBBAVCNFSM6AAAAABTS5EKSGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMJYGAYTQNBSGU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Report hasn't been filed before.
What version of
drizzle-orm
are you using?0.38.2
What version of
drizzle-kit
are you using?0.30.1
Other packages
No response
Describe the Bug
I notice that the command
drizzle-kit push
can remove and recreate the unique index over and over again if I used multiple fields and not in the right order.In the repo below, the following will recreate each run:
But the following won't:
Seems like something in the ordering of the columns confuse the script.
Use the following code to test it:
https://github.com/moshest/drizzle-unique-bug/tree/main
Best way to verify is to add a single row to the table and then get the warning about truncating the table each time.
The text was updated successfully, but these errors were encountered: