Skip to content
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-kit push generate excess command that crash migration #3189

Open
Disimasa opened this issue Oct 23, 2024 · 0 comments
Open

[BUG]: drizzle-kit push generate excess command that crash migration #3189

Disimasa opened this issue Oct 23, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Disimasa
Copy link

What version of drizzle-orm are you using?

0.31.4

What version of drizzle-kit are you using?

0.22.8

Describe the Bug

I use drizzle-orm with postgres on my project. I have the table with composite primary key like that

export const dbtBranches = pgTable('dbt_branches', {
		id: text('id').notNull().default(sql`gen_random_uuid()`),
		dbtProjectId: text('dbt_project_id').references(() => dbtProjects.id).notNull(),
	},
	(table) => {
		return {
			pk: primaryKey({ columns: [table.dbtProjectId, table.id] }),
		}
	}

Also there's the table with multicolumn foreign key that relate to dbtBranches.

export const dbtRuns = pgTable('dbt_runs', {
	dbtProjectId: text('dbt_project_id').references(() => dbtProjects.id).notNull(),
	dbtBranchId: text('dbt_branch_id').notNull(),
},
	(t) => {
		return {
			branchReference: foreignKey({
				columns: [t.dbtProjectId, t.dbtBranchId],
				foreignColumns: [dbtBranches.dbtProjectId, dbtBranches.id],
			}),
		}
	})

When I run drizzle-kit push, it generates the query with

ALTER TABLE "dbt_branches" DROP CONSTRAINT dbt_branches_dbt_project_id_id_pk;
--> statement-breakpoint
ALTER TABLE "dbt_branches" ADD CONSTRAINT dbt_branches_dbt_project_id_id_pk PRIMARY KEY(dbt_project_id,id);

And this query crashes because of
constraint dbt_runs_dbt_project_id_dbt_branch_id_dbt_branches_dbt_project_ on table dbt_runs depends on index dbt_branches_dbt_project_id_id_pk'

I tried to run drop constraint cascade by my own and after that drizzle-kit push worked successfully. However if I run drizzle-kit push again (even without changes) the same error appears.

Expected behavior

I guess that drizzle-kit generate excess sql queries here, because this constraint already exists in my database.

ALTER TABLE "dbt_branches" DROP CONSTRAINT dbt_branches_dbt_project_id_id_pk;
--> statement-breakpoint
ALTER TABLE "dbt_branches" ADD CONSTRAINT dbt_branches_dbt_project_id_id_pk PRIMARY KEY(dbt_project_id,id);

Environment & setup

No response

@Disimasa Disimasa added the bug Something isn't working label Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant