benjick
benjick
Explore posts from servers
DTDrizzle Team
Created by benjick on 9/24/2024 in #help
drizzle-kit picks wrong version in monorepo (pnpm)
Hello I have a monorepo with pnpm where I have two apps. One nextjs app and one Payload CMS app. Payload lags behind on drizzle-orm version but I want to update it for my nextjs app. I have installed different version in each project, but running drizzle-kit generate in the nextjs app complains about a too old drizzle-orm version (the one from the payload app) How can I resolve this? Can I force drizzle-kit to pick a specific version?
5 replies
DTDrizzle Team
Created by benjick on 7/22/2024 in #help
there is no unique or exclusion constraint matching the ON CONFLICT specification
Having this issue that I've seen others also getting, but without explanation. I'm only getting this error in production, not in my local dev environment.
.onConflictDoUpdate({
target: publishedTasks.taskId,
set: {
showName: input.showName,
showSchool: input.showSchool,
},
})
.onConflictDoUpdate({
target: publishedTasks.taskId,
set: {
showName: input.showName,
showSchool: input.showSchool,
},
})
I have a target, publishedTasks.taskId :
taskId: varchar("task_id")
.primaryKey()
.references(() => tasks.id, {
onDelete: "cascade",
})
taskId: varchar("task_id")
.primaryKey()
.references(() => tasks.id, {
onDelete: "cascade",
})
What am I doing wrong here?
48 replies
DTDrizzle Team
Created by benjick on 6/1/2024 in #help
Noob question about DROP TABLE ordering
Hello! I'm about to drop my first table with Drizzle, and I noticed the SQL file looks like this:
DROP TABLE "merlin_schools";--> statement-breakpoint
ALTER TABLE "merlin_auth_user" DROP CONSTRAINT "merlin_auth_user_school_merlin_schools_id_fk";
--> statement-breakpoint
ALTER TABLE "merlin_groups" DROP CONSTRAINT "merlin_groups_school_id_merlin_schools_id_fk";
--> statement-breakpoint
ALTER TABLE "merlin_auth_user" DROP COLUMN IF EXISTS "school";--> statement-breakpoint
ALTER TABLE "merlin_groups" DROP COLUMN IF EXISTS "school_id";
DROP TABLE "merlin_schools";--> statement-breakpoint
ALTER TABLE "merlin_auth_user" DROP CONSTRAINT "merlin_auth_user_school_merlin_schools_id_fk";
--> statement-breakpoint
ALTER TABLE "merlin_groups" DROP CONSTRAINT "merlin_groups_school_id_merlin_schools_id_fk";
--> statement-breakpoint
ALTER TABLE "merlin_auth_user" DROP COLUMN IF EXISTS "school";--> statement-breakpoint
ALTER TABLE "merlin_groups" DROP COLUMN IF EXISTS "school_id";
won't dropping the table first cause issues with the FK contraints?
4 replies
DTDrizzle Team
Created by benjick on 5/28/2024 in #help
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'
}
4 replies
DTDrizzle Team
Created by benjick on 5/12/2024 in #help
Find needed indexes
Hello! Is there any way to find unindexed columns which should be indexed with drizzle? Firebase has this feature where it yells at you if you select or sort on columns which hasn't been indexed. Cheers
1 replies
DTDrizzle Team
Created by benjick on 11/29/2023 in #help
Property '[IsDrizzleTable]' is missing in type
Hello! I've just updated to [email protected] and I can't use drizzle-zod anymore (@0.5.1). This is my code:
export const GroupCategoriesInsertSchema = createInsertSchema(
groupCategories,
)
export const GroupCategoriesInsertSchema = createInsertSchema(
groupCategories,
)
Gives me the following error:
Argument of type 'PgTableWithColumns<{ name: "group_categories"; schema: undefined; columns: { id: PgColumn<{ name: string; tableName: "group_categories"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [...]; baseColumn: never; }, {}, {}>; ... 6 more ...; ...' is not assignable to parameter of type 'Table<TableConfig<Column<any, object, object>>>'.
Argument of type 'PgTableWithColumns<{ name: "group_categories"; schema: undefined; columns: { id: PgColumn<{ name: string; tableName: "group_categories"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [...]; baseColumn: never; }, {}, {}>; ... 6 more ...; ...' is not assignable to parameter of type 'Table<TableConfig<Column<any, object, object>>>'.
What can I do?
12 replies
DTDrizzle Team
Created by benjick on 10/24/2023 in #help
column "summary" cannot be cast automatically to type jsonb
Hello! I'm getting this error when running my migrations, I used to have a text field and now it's a jsonb
summary: jsonb("summary").notNull(),
summary: jsonb("summary").notNull(),
How can I resolve this? This is the migration:
ALTER TABLE "merlin_task_results" ALTER COLUMN "summary" SET DATA TYPE jsonb;--> statement-breakpoint
ALTER TABLE "merlin_task_results" ALTER COLUMN "summary" SET NOT NULL;
ALTER TABLE "merlin_task_results" ALTER COLUMN "summary" SET DATA TYPE jsonb;--> statement-breakpoint
ALTER TABLE "merlin_task_results" ALTER COLUMN "summary" SET NOT NULL;
10 replies
DTDrizzle Team
Created by benjick on 9/23/2023 in #help
How to handle relations during insert?
Is this correct? Feels like I should be able to do it in one call, but values doesn't accept anything else
const group = await db
.insert(groups)
.values({ name: inputs.name })
.returning();
await db.insert(usersToGroups).values({
groupId: group[0]!.id,
userId: session.user.id,
});
const group = await db
.insert(groups)
.values({ name: inputs.name })
.returning();
await db.insert(usersToGroups).values({
groupId: group[0]!.id,
userId: session.user.id,
});
8 replies