Skip to content

[FEATURE]: Support generating default uuid v7 #5721

@axel7083

Description

@axel7083

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Since Postgres v18 we can use the

  • gen_random_uuid -> uuid v4
  • uuidv4 -> uuid v4
  • uuidv7 -> uuid v7

https://www.postgresql.org/docs/current/functions-uuid.html

It would be nice to have an optional parameter to defaultRandom function of the UUID column builder to easily choose between v4 and v7 (and keep a default to v4 for backward compatibility).

/**
* Adds `default gen_random_uuid()` to the column definition.
*/
defaultRandom(): ReturnType<this['default']> {
return this.default(sql`gen_random_uuid()`) as ReturnType<this['default']>;
}


Alternative

We can do the following

uuid('id').primaryKey().default(sql`uuidv7()`),

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions