Repository navigation
Description
Issue Creation Checklist
- I understand that my issue will be automatically closed if I don't fill in the requested information
- I have read the contribution guidelines
Feature Description
Describe the feature you'd like to see implemented
Add native support for generating UUIDv7 values without requiring the external uuid npm package. Node.js has native crypto.randomUUID() for v4-style UUIDs, and native UUIDv7 generation is landing in newer Node versions (see nodejs/node#62529). PostgreSQL has also added native UUIDv7 generation support.
Example of the proposed usage:
```ts
@Attribute(DataTypes.UUID)
@PrimaryKey
@default(fn('uuidv7'))
declare id: CreationOptional;
```
This would let users generate time-ordered, sortable UUIDs as primary keys directly through Sequelize's fn() helper, similar to how UUIDV4 is currently supported.
Describe why you would like this feature to be added to Sequelize
Sequelize currently depends on the external uuid package for UUID generation, which has caused ESM/CommonJS interoperability issues in the past (see #18224, fixed via #18230). Native UUIDv7 support would reduce this dependency surface for a very common use case (time-sortable primary keys) and align Sequelize with what Node.js and PostgreSQL are already offering natively. This was raised by @SippieCup during review of #18230, but is out of scope there since that PR targets the v6 branch, which still needs to support older Node versions.
Is this feature dialect-specific?
- No. This feature is relevant to Sequelize as a whole.
- Yes. This feature only applies to the following dialect(s):
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I will need guidance.
- No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
- No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in implementing my feature.
Activity
vineetj12 commentedon Jul 13, 2026
I'd like to work on this — I opened #18230 on the v6 side, which is where this idea came from. Could someone point me to where UUID-related helpers/DataTypes live in the v7 branch, and any existing pattern for adding a new fn() helper (like how UUIDV4 works today)? Happy to start digging myself in the meantime, just want to make sure I follow the right convention.
WikiRik commentedon Jul 13, 2026
#17832 already added support for UUID v7. I don't think we need native postgres or Node support right now. Node shipped it in a version that's not LTS yet and postgres has shipped in only in their most recent major version. We could add fallbacks and version checks, but I don't think it's worth it at this moment. That's also why we marked it as a P4.
If you still want to work on it, this is what AI came up with. I think it's a good start. It also mentions CI changes, they would need to land in a separate PR before the UUIDv7 PR.
Native UUIDv7 implementation guidance
For native Node.js UUIDv7 generation and PostgreSQL 18 UUIDv7 generation—with fallbacks—the likely patch touches the following files.
Required source files
packages/core/src/expression-builders/uuid.tsPrefer
node:crypto.randomUUIDv7()when it exists; otherwise calluuid.v7(). This preserves Node 20, 22, and 24 support.SqlUuidV7.supportsDialect()also needs to returnfalsefor PostgreSQL versions below 18, causing Sequelize to use JavaScript generation instead of placing a database default in the schema.packages/core/src/abstract-dialect/dialect.tsThe current
uuidV7Generationcapability is only a static boolean. That cannot express “PostgreSQL supports this starting with version 18.”A possible version-aware capability shape is:
Its default remains
false.packages/postgres/src/dialect.tsDeclare PostgreSQL's capability:
packages/postgres/src/query-generator-typescript.internal.tsAdd:
The version decision should happen before this method is called, in the capability check. That way PostgreSQL 17 and older omit the SQL default and retain JavaScript generation rather than throwing.
Required tests
packages/core/test/unit/query-interface/create-table.test.tsAdd two PostgreSQL cases:
PostgreSQL 18 produces a UUID default using
uuidv7():"id" UUID DEFAULT uuidv7()PostgreSQL 17 omits the database
DEFAULT, proving the JavaScript fallback remains in effect.packages/core/test/unit/expression-builders/uuid.test.tsAdd a focused test file covering:
randomUUIDv7()selected when available.uuid.v7()selected when unavailable.To make both branches reliably testable, it may be worth extracting the selection into a small exported-internal function that accepts the native function as an argument. Mocking an imported
node:cryptobinding directly will otherwise be awkward.CI changes needed to exercise both native paths
.github/workflows/ci.ymlThe current matrix only runs Node 20, 22, and 24—all fallback runtimes. Add Node 26 so CI also exercises native
randomUUIDv7().dev/postgres/latest/docker-compose.yml“Latest” is currently PostgreSQL 17. Update or add a PostgreSQL 18 service so integration tests actually exercise
uuidv7().Files that should not need changes
packages/core/src/abstract-dialect/data-types.ts:DataTypes.UUID.V7already exists.packages/core/src/expression-builders/sql.ts:sql.uuidV7is already registered.packages/core/src/abstract-dialect/query-generator-typescript.ts:getUuidV7FunctionCall()already exists.packages/core/package.json: keepuuidbecause it remains the fallback and UUIDv1 still depends on it.Expected scope
The core patch is four source files, two test locations, and ideally the Node and PostgreSQL CI matrices.
LeonxLJX commentedon Sep 2, 2026
SippieCup commentedon Sep 2, 2026
That's generally the approach I take.
Thanks for doing this!