Skip to content

feat: add uuidv7 support for pgsql#16113

Open
W1ckh3ad wants to merge 3 commits intopayloadcms:mainfrom
W1ckh3ad:feat/add-uuid-v7-support
Open

feat: add uuidv7 support for pgsql#16113
W1ckh3ad wants to merge 3 commits intopayloadcms:mainfrom
W1ckh3ad:feat/add-uuid-v7-support

Conversation

@W1ckh3ad
Copy link
Copy Markdown

@W1ckh3ad W1ckh3ad commented Mar 31, 2026

Goal

Let projects use UUID v7 (time-ordered UUIDs) for collection IDs via idType: 'uuidv7' on Postgres-related adapters (and SQLite wiring), while keeping the same storage shape as v4 UUIDs (native uuid on Postgres, text on SQLite).

What?

  • Adds a new adapter option idType: 'uuidv7' alongside existing 'serial' | 'uuid' (Postgres) and 'number' | 'uuid' (SQLite).
  • Generates IDs in application code with uuid package v7() (not database-native), so older Postgres versions are still supported.
  • Reuses the same Drizzle column modeling as UUID v4 where appropriate (defaultV7 on the raw column, $defaultFn / generated schema code).
  • Adds integration tests behind PAYLOAD_DATABASE=postgres-uuidv7 and a test adapter preset postgres-uuidv7.

Why?

UUID v7 is sortable by creation time and tends to be friendlier for B-tree indexes than random UUID v4, without changing the wire format or Postgres column type.

How?

  • Bump uuid in @payloadcms/drizzle to a version that exports v7.
  • Extend TypeScript idType unions and UUIDRawColumn with defaultV7.
  • In schema builders (setColumnID, buildDrizzleTable, columnToCodeConverter), set app-side defaults for v7; treat uuidv7 like uuid for relationships and query sanitization via a small isUUIDType helper and getCollectionIdType mapping to 'text'.

Fixes #11449

@DanRibbens DanRibbens requested a review from r1tsuu March 31, 2026 17:34
@W1ckh3ad W1ckh3ad force-pushed the feat/add-uuid-v7-support branch from f964a62 to 16f4941 Compare April 1, 2026 12:57
@W1ckh3ad
Copy link
Copy Markdown
Author

W1ckh3ad commented Apr 1, 2026

Hello I saw that the e2e failed
after some digging by Composer it mentioned to extend the dbs for testing in .github/workflows/int.config.ts

import { createIntConfig } from './utilities/int-matrix.ts'

createIntConfig({
  databases: [
    'mongodb',
    'mongodb-atlas',
    'documentdb',
    'cosmosdb',
    'firestore',
    'postgres',
    'postgres-custom-schema',
    'postgres-uuid',
+   'postgres-uuidv7',
    'postgres-read-replica',
    'supabase',
    'sqlite',
    'sqlite-uuid',
+   'sqlite-uuidv7',
  ],
  shards: 3,
})

Should i update the file as shown?

Also i uploaded a rebase :)

@r1tsuu
Copy link
Copy Markdown
Member

r1tsuu commented Apr 1, 2026

Looks like the build is failing also. But yes, I think we might want to add those to GitHub CI as well

@W1ckh3ad W1ckh3ad requested a review from denolfe as a code owner April 1, 2026 15:13
@W1ckh3ad
Copy link
Copy Markdown
Author

W1ckh3ad commented Apr 1, 2026

Build is working locally

I fixed the lockfile now the build should work,

now i test e2e locally

@W1ckh3ad
Copy link
Copy Markdown
Author

W1ckh3ad commented Apr 1, 2026

tests:

  • int: 10 failed | 110 passed | 2215 skipped
  • e2e: fails because of element not found ( await expect(textCell).toHaveText('example post'))
  • unit: 1156 passed | 2 skipped (1158)

running those tests i get changed in those two files (result of git diff numstat):

  • 13 0 test/_community/payload-types.ts
  • 111 90 test/database/payload-types.ts

it changes mostly id types from number to string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

payloadcms not working with uuid v7

2 participants