Repository navigation
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughUUIDv7 generation now probes Node.js native support with a package fallback. Dialect capability checks support minimum database versions, and PostgreSQL declares UUIDv7 support from version 18.0.0 with ChangesUUIDv7 support
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Sequelize
participant PostgresDialect
participant QueryGenerator
participant Database
Sequelize->>PostgresDialect: evaluate UUIDv7 support
PostgresDialect->>Database: retrieve database version
Database-->>PostgresDialect: return version
PostgresDialect->>QueryGenerator: request UUIDv7 function call
QueryGenerator-->>Sequelize: return uuidv7()
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Thanks for opening the PR! Please split the Node 26 and postgres 18 support to two different PRs. I have time to review those today, so it shouldn't delay this PR too much |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/core/src/expression-builders/uuid.ts (1)
9-13: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueCache the native UUIDv7 function reference.
Currently, the native
crypto.randomUUIDv7property is accessed and its type is checked on every single invocation. Caching the function reference at the module level avoids this overhead, which is particularly beneficial since UUID generation can be frequently called in hot paths like bulk inserts.♻️ Proposed refactor
-function getNativeUuidV7(): string | undefined { - const nativeUuidV7 = (crypto as typeof crypto & { randomUUIDv7?: unknown }).randomUUIDv7; - - return typeof nativeUuidV7 === 'function' ? nativeUuidV7() : undefined; -} +const nativeUuidV7Fn = (crypto as typeof crypto & { randomUUIDv7?: unknown }).randomUUIDv7; +const nativeUuidV7 = typeof nativeUuidV7Fn === 'function' ? (nativeUuidV7Fn as () => string) : undefined; + +function getNativeUuidV7(): string | undefined { + return nativeUuidV7?.(); +}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/core/src/expression-builders/uuid.ts` around lines 9 - 13, Cache the validated crypto.randomUUIDv7 function reference at module scope, then update getNativeUuidV7 to reuse that reference without rereading or rechecking the property on each invocation. Preserve the existing undefined fallback when the native function is unavailable.packages/core/test/unit/expression-builders/uuid.test.ts (1)
10-15: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueTest
generateUuidV7with its default argument.The current tests verify the injection of a custom generator and the fallback behavior, but they don't exercise the zero-argument behavior where it resolves the native generator (or fallback) by default. Adding a test for the default parameter ensures that the end-to-end integration works seamlessly.
♻️ Proposed refactor
it('uses the provided native fn when available', () => { const nativeUuidV7 = sinon.stub().returns('native-uuidv7'); expect(generateUuidV7(nativeUuidV7)).to.equal('native-uuidv7'); expect(nativeUuidV7.callCount).to.equal(1); }); + + it('generates a valid UUIDv7 without arguments', () => { + const generated = generateUuidV7(); + expect(generated).to.match( + /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, + ); + });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/core/test/unit/expression-builders/uuid.test.ts` around lines 10 - 15, Add a unit test alongside the existing generateUuidV7 tests that calls generateUuidV7() without passing a native generator, and assert it returns a valid UUID v7 result through the default native-or-fallback resolution path. Keep the existing injected-generator and fallback tests unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/core/src/expression-builders/uuid.ts`:
- Around line 9-13: Cache the validated crypto.randomUUIDv7 function reference
at module scope, then update getNativeUuidV7 to reuse that reference without
rereading or rechecking the property on each invocation. Preserve the existing
undefined fallback when the native function is unavailable.
In `@packages/core/test/unit/expression-builders/uuid.test.ts`:
- Around line 10-15: Add a unit test alongside the existing generateUuidV7 tests
that calls generateUuidV7() without passing a native generator, and assert it
returns a valid UUID v7 result through the default native-or-fallback resolution
path. Keep the existing injected-generator and fallback tests unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e40f4435-7b0e-43d5-be52-322516502748
📒 Files selected for processing (8)
.github/workflows/ci.ymldev/postgres/latest/docker-compose.ymlpackages/core/src/abstract-dialect/dialect.tspackages/core/src/expression-builders/uuid.tspackages/core/test/unit/expression-builders/uuid.test.tspackages/core/test/unit/query-interface/create-table.test.tspackages/postgres/src/dialect.tspackages/postgres/src/query-generator-typescript.internal.ts
eb8cc61 to
01d1707
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/core/test/unit/query-interface/create-table.test.ts (1)
97-118: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd cross-dialect test coverage for
sql.uuidV7.The test for
sql.uuidV7default values is currently gated inside theif (dialect.name === 'postgres')block. To prevent regressions and ensure that JS-side fallback generation translates into valid schema generation (i.e., emitting a column with noDEFAULTclause) across all other dialects, consider extracting this test into a cross-dialect assertion similar to the existingsupports sql.uuidV4 default valuestest.The
postgres < 18fallback test at line 120 should remain inside thepostgresblock.♻️ Proposed refactor to test across all dialects
Move this test outside the
if (dialect.name === 'postgres')block and adjust it as follows:it('supports sql.uuidV7 default values', async () => { const localSequelize = dialect.name === 'postgres' ? createSequelizeInstance({ databaseVersion: '18.0.0', }) : sequelize; const stub = sinon.stub(localSequelize, 'queryRaw'); await localSequelize.queryInterface.createTable('table', { id: { type: DataTypes.UUID, primaryKey: true, defaultValue: sql.uuidV7, }, }); expect(stub.callCount).to.eq(1); const firstCall = stub.getCall(0); expectsql(firstCall.args[0], { postgres: 'CREATE TABLE IF NOT EXISTS "table" ("id" UUID DEFAULT uuidv7(), PRIMARY KEY ("id"));', 'mariadb mysql': 'CREATE TABLE IF NOT EXISTS `table` (`id` CHAR(36) BINARY, PRIMARY KEY (`id`)) ENGINE=InnoDB;', mssql: `IF OBJECT_ID(N'[table]', 'U') IS NULL CREATE TABLE [table] ([id] UNIQUEIDENTIFIER, PRIMARY KEY ([id]));`, sqlite3: 'CREATE TABLE IF NOT EXISTS `table` (`id` TEXT PRIMARY KEY);', snowflake: 'CREATE TABLE IF NOT EXISTS "table" ("id" VARCHAR(36), PRIMARY KEY ("id"));', db2: 'CREATE TABLE IF NOT EXISTS "table" ("id" CHAR(36) FOR BIT DATA NOT NULL, PRIMARY KEY ("id"));', ibmi: `BEGIN DECLARE CONTINUE HANDLER FOR SQLSTATE VALUE '42710' BEGIN END; CREATE TABLE "table" ("id" CHAR(36), PRIMARY KEY ("id")); END`, oracle: `BEGIN EXECUTE IMMEDIATE 'CREATE TABLE "table" ("id" VARCHAR2(36),PRIMARY KEY ("id"))'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -955 THEN RAISE; END IF; END;`, }); });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/core/test/unit/query-interface/create-table.test.ts` around lines 97 - 118, Move the sql.uuidV7 default-value test outside the postgres-only block, following the existing cross-dialect sql.uuidV4 test pattern. Use the postgres-specific Sequelize instance with databaseVersion 18.0.0 only for postgres, use the shared sequelize instance for other dialects, and add expected SQL asserting no DEFAULT clause for non-Postgres dialects. Keep the postgres <18 fallback test inside the postgres block.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/core/test/unit/query-interface/create-table.test.ts`:
- Around line 97-118: Move the sql.uuidV7 default-value test outside the
postgres-only block, following the existing cross-dialect sql.uuidV4 test
pattern. Use the postgres-specific Sequelize instance with databaseVersion
18.0.0 only for postgres, use the shared sequelize instance for other dialects,
and add expected SQL asserting no DEFAULT clause for non-Postgres dialects. Keep
the postgres <18 fallback test inside the postgres block.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9fea08b5-a8ae-424b-b964-6bf5e6f5652e
📒 Files selected for processing (6)
packages/core/src/abstract-dialect/dialect.tspackages/core/src/expression-builders/uuid.tspackages/core/test/unit/expression-builders/uuid.test.tspackages/core/test/unit/query-interface/create-table.test.tspackages/postgres/src/dialect.tspackages/postgres/src/query-generator-typescript.internal.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- packages/core/test/unit/expression-builders/uuid.test.ts
- packages/postgres/src/dialect.ts
- packages/postgres/src/query-generator-typescript.internal.ts
- packages/core/src/abstract-dialect/dialect.ts
01d1707 to
9be67f2
Compare
|
Thanks for the review! I've updated the PR as requested.
Please let me know if there's anything else you'd like me to adjust. Thanks! |
|
Please open those PRs now, so I can review this with the proper changes |
|
Thanks for the review! I've split the changes as requested.
Please let me know if you'd like any further changes. |
|
I think I've been unclear. Apologies for that. I meant to say that we should have three PRs;
|
|
Thanks for clarifying, @WikiRik — understood, three PRs:
This PR already contains the full feature (native Node.js detection via |
Pull Request Checklist
Description of Changes
Closes #18253. Related to #17832.
Adds native UUIDv7 generation support:
node:crypto'srandomUUIDv7()is used when available (Node 26+), falling back to theuuidpackage'sv7()otherwise. The native detection is guarded with an explicittypeof === 'function'check.minimumDatabaseVersion: '18.0.0') instead of a static boolean. On Postgres 18+,sql.uuidV7produces a column default ofuuidv7(). On Postgres <18 (or when the database version is unknown), Sequelize falls back to JavaScript-side generation instead of emitting a SQL default.Files changed:
packages/core/src/expression-builders/uuid.ts— injectable native UUIDv7 detection + version-awaresupportsDialect()packages/core/src/abstract-dialect/dialect.ts— wideneduuidV7Generationtoboolean | { minimumDatabaseVersion: string }packages/postgres/src/dialect.ts— declared Postgres UUIDv7 support starting at18.0.0packages/postgres/src/query-generator-typescript.internal.ts— addedgetUuidV7FunctionCall()returninguuidv7()packages/core/test/unit/query-interface/create-table.test.ts— added Postgres 18 (uuidv7()default) and Postgres 17 (JS fallback, no default) casespackages/core/test/unit/expression-builders/uuid.test.ts— new tests for native-injected and fallback UUIDv7 generation.github/workflows/ci.yml— added Node 26 to the CI matrixdev/postgres/latest/docker-compose.yml— bumped the latest Postgres image to 18Notes for reviewers:
create-table.test.ts), and the native/fallback selection is covered inuuid.test.ts. I was unable to bring up a local Postgres 18 environment to run the integration path directly, so I'd appreciate confirmation from CI or a maintainer that the liveuuidv7()SQL path behaves as expected against a real database.List of Breaking Changes
None.
uuidV7Generationwidened frombooleantoboolean | { minimumDatabaseVersion: string }, but this is an internalDialectSupportscapability type, not part of the public API, and all existing dialects other than Postgres remain unaffected (default staysfalse).Summary by CodeRabbit
New Features
uuidv7()for UUID defaults.Bug Fixes