Thiago Felisberto
Thiago Felisberto
DTDrizzle Team
Created by Thiago Felisberto on 1/5/2024 in #help
Insert/update statements not executed during migrations
Hi. Does Drizzle support DML statements when running migrations? My use case is to add a new column, populate it and then make it not null.
ALTER TABLE "conversations" ADD COLUMN "channel_id" text;
--> statement-breakpoint
UPDATE "conversations" SET channel_id = 'some value';
--> statement-breakpoint
ALTER TABLE "conversations" ALTER COLUMN "channel_id" SET NOT NULL;
ALTER TABLE "conversations" ADD COLUMN "channel_id" text;
--> statement-breakpoint
UPDATE "conversations" SET channel_id = 'some value';
--> statement-breakpoint
ALTER TABLE "conversations" ALTER COLUMN "channel_id" SET NOT NULL;
PostgresError: column "channel_id" of relation "conversations" contains null values
PostgresError: column "channel_id" of relation "conversations" contains null values
1 replies
DTDrizzle Team
Created by Thiago Felisberto on 10/20/2023 in #help
Drizzle generates PG statement with parentheses on order by clause
Hello! I'm trying to execute a simple query with Drizzle, but it generates an invalid SQL statement.
import { desc, eq } from 'drizzle-orm';
await db
.select()
.from(messages)
.where(eq(messages.conversationId, id))
.orderBy([desc(messages.id)])
.limit(10)
import { desc, eq } from 'drizzle-orm';
await db
.select()
.from(messages)
.where(eq(messages.conversationId, id))
.orderBy([desc(messages.id)])
.limit(10)
This is the generated SQL:
select "id", "conversation_id", "content", "created_at", "updated_at"
from "messages"
where "messages"."conversation_id" = $1
order by ("messages"."id" desc)
limit $2
select "id", "conversation_id", "content", "created_at", "updated_at"
from "messages"
where "messages"."conversation_id" = $1
order by ("messages"."id" desc)
limit $2
(error: syntax error at or near "desc" at character 113) Looks like a parentheses is added on the order by clause. Am I doing something wrong?
6 replies