Open aydrian opened 1 year ago
You can use uuid
field in pg-core
, I guess it's just missing in docs, will fix it!
import { pgTable, text, uuid } from "drizzle-orm/pg-core";
export const users = pgTable("users", {
id: uuid("uuid1").defaultRandom(),
name: text("name"),
});
Would that work for you?
Also you can use .default
for any sql defaults, so you can write like this:
import { pgTable, text, uuid } from "drizzle-orm/pg-core";
export const users = pgTable("users", {
id: uuid("uuid1").default(sql`gen_random_uuid()`),
name: text("name"),
});
We have an example here: https://orm.drizzle.team/docs/column-types/pg#default-value Just never made it in a list of types, just created an issue in docs repo: https://github.com/drizzle-team/drizzle-orm-docs/issues/120
I'm not referring to the tables I create in my schema, but rather the table Drizzle creates to hold information about migrations. It uses a serial type for the primary key.
makes sense, assigning to myself
Just ran into another issue using push/migration after I added a foreign key to my schema. Looks like we don't yet support anonymous code blocks. We do have a ticket for it.
DO $$ BEGIN
ALTER TABLE "count_downs" ADD CONSTRAINT "count_downs_id_lists_id_fk" FOREIGN KEY ("id") REFERENCES "lists"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
Describe what you want
For at least the pg-core dialect, it would be great if we had the option to set the id column type to something non sequential like a
UUID
. I have been trying Drizzle with CockroachDB and everything seems to be working okay but it does complain about theSERIAL
id type on the migrationsTable. Sequential primary keys in distributed databases can cause hot spotting. CockroachDB recommends using aUUID
with a default value ofgen_random_uuid()
. I don't think this will cause a problem in the long run but it would remove the warning when running a migration.