-
-
Notifications
You must be signed in to change notification settings - Fork 713
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
[FEATURE]: Allow for non sequential primary key for id of migrationsTable #1267
Comments
You can use 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 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 |
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 $$; |
The new Aurora DSQL also does not support serial or sequences in general, so this feature will be a great help for this database as well. |
In the code below, the drizzle-orm/drizzle-orm/src/pg-core/dialect.ts Lines 73 to 112 in 866c257
Therefore, it seems we could swap the definition of the column to |
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.The text was updated successfully, but these errors were encountered: