drizzle-kit push fails every second time

Hello I'm having this annoying issue where I have to wipe my postgres database before doing a push. How can I resolve this? I'm attaching a log below, this is without changing anything in between:
pnpm db:push

> @nextgen/[email protected] db:push /Users/me/dev/merlin/apps/nextjs
> dotenv drizzle-kit push

drizzle-kit: v0.21.4
drizzle-orm: v0.29.1

No config path provided, using default path
Reading config file '/Users/me/dev/merlin/apps/nextjs/drizzle.config.ts'
Using 'pg' driver for database querying
[✓] Pulling schema from database...[✓] Changes applied
pnpm db:push

> @nextgen/[email protected] db:push /Users/me/dev/merlin/apps/nextjs
> dotenv drizzle-kit push

drizzle-kit: v0.21.4
drizzle-orm: v0.29.1

No config path provided, using default path
Reading config file '/Users/me/dev/merlin/apps/nextjs/drizzle.config.ts'
Using 'pg' driver for database querying
[✓] Pulling schema from database...error: relation "pt_task_id_idx" already exists
at /Users/me/dev/merlin/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:69429:15
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.query (/Users/me/dev/merlin/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:111366:26)
at async pgPush (/Users/me/dev/merlin/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:114524:13)
at async Command.<anonymous> (/Users/me/dev/merlin/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:121480:7) {
length: 96,
severity: 'ERROR',
code: '42P07',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'index.c',
line: '885',
routine: 'index_create'
}
pnpm db:push

> @nextgen/[email protected] db:push /Users/me/dev/merlin/apps/nextjs
> dotenv drizzle-kit push

drizzle-kit: v0.21.4
drizzle-orm: v0.29.1

No config path provided, using default path
Reading config file '/Users/me/dev/merlin/apps/nextjs/drizzle.config.ts'
Using 'pg' driver for database querying
[✓] Pulling schema from database...[✓] Changes applied
pnpm db:push

> @nextgen/[email protected] db:push /Users/me/dev/merlin/apps/nextjs
> dotenv drizzle-kit push

drizzle-kit: v0.21.4
drizzle-orm: v0.29.1

No config path provided, using default path
Reading config file '/Users/me/dev/merlin/apps/nextjs/drizzle.config.ts'
Using 'pg' driver for database querying
[✓] Pulling schema from database...error: relation "pt_task_id_idx" already exists
at /Users/me/dev/merlin/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:69429:15
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.query (/Users/me/dev/merlin/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:111366:26)
at async pgPush (/Users/me/dev/merlin/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:114524:13)
at async Command.<anonymous> (/Users/me/dev/merlin/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:121480:7) {
length: 96,
severity: 'ERROR',
code: '42P07',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'index.c',
line: '885',
routine: 'index_create'
}
1 Reply
benjick
benjickOP7mo ago
Here's the schema:
export const taskId = pgTypeId("task_id")
.primaryKey()
.references(() => tasks.id, {
onDelete: "cascade",
});

export const publishedTasks = pgTable(
"published_tasks",
{
taskId,
duplicateCount: integer("duplicate_count").notNull().default(0),
instanceCount: integer("instance_count").notNull().default(0),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow(),
},
(table) => {
return {
taskIdIdx: unique("pt_task_id_idx").on(table.taskId),
};
},
);
export const taskId = pgTypeId("task_id")
.primaryKey()
.references(() => tasks.id, {
onDelete: "cascade",
});

export const publishedTasks = pgTable(
"published_tasks",
{
taskId,
duplicateCount: integer("duplicate_count").notNull().default(0),
instanceCount: integer("instance_count").notNull().default(0),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow(),
},
(table) => {
return {
taskIdIdx: unique("pt_task_id_idx").on(table.taskId),
};
},
);
pgTypeId is just a varchar with a max length I guess I can remove it, since it's already a PK Removed it and it work now, sorry
Want results from more Discord servers?
Add your server