drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: Support generating default uuid v7

Open
#5,721 0 comments 30 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Feature hasn't been suggested before.

- [x] 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).

https://github.com/drizzle-team/drizzle-orm/blob/48e5406027103a9fca6eb66417187c4a8b5c6aa3/drizzle-orm/src/pg-core/columns/uuid.ts#L24-L29

---

Alternative

We can do the following

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.