-
Notifications
You must be signed in to change notification settings - Fork 46k
feat(backend): use sortable UUIDv7 for ID defaults #12961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ea62012
feat(backend): use sortable UUIDv7 for ID defaults
majdyz 251fde8
review fixups: address polish round 1
majdyz ae83c3a
fix(backend): keep persisted link.id in sync with returned graph
majdyz ea75c7c
Merge branch 'dev' into feat/sortable-uuid-v7-defaults
majdyz ca335af
docs(backend): note when uuid_generate_v7() can be retired
majdyz 183656a
fix(backend): mint IntegrationWebhook ids via new_uuid()
majdyz 2eec18e
fix(backend): mint remaining pre-insert ids via new_uuid()
majdyz 4201d0f
fix(backend): mint remaining v7 ids in chat session and raw SQL inserts
majdyz f386ff5
Merge branch 'master' of github.com:Significant-Gravitas/AutoGPT into…
majdyz c92150c
Merge branch 'dev' into feat/sortable-uuid-v7-defaults
majdyz d787b67
fix(backend): restore dev-side schema fields lost in merge
majdyz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| """Sortable identifier helpers.""" | ||
|
|
||
| from uuid_utils import uuid7 | ||
|
|
||
|
|
||
| def new_uuid() -> str: | ||
| """Return a fresh sortable UUIDv7 as a lower-case canonical string. | ||
|
|
||
| Use this for any application-level ID generation that lands in a Prisma | ||
| column. Schema-level ``@default(dbgenerated("uuid_generate_v7()"))`` | ||
| covers the path where Prisma populates the id; this helper is the | ||
| Python-side counterpart for code that needs the id before insert. | ||
| """ | ||
| return str(uuid7()) | ||
67 changes: 67 additions & 0 deletions
67
autogpt_platform/backend/migrations/20260430120000_use_uuidv7_for_id_defaults/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| -- Sortable UUIDv7 generator (RFC 9562). Built on gen_random_uuid() | ||
| -- (pgcrypto, already in use). The first 48 bits encode the unix | ||
| -- timestamp in milliseconds, so values are k-sortable on insert order. | ||
| CREATE OR REPLACE FUNCTION uuid_generate_v7() | ||
| RETURNS uuid | ||
| AS $$ | ||
| BEGIN | ||
| RETURN encode( | ||
| set_bit( | ||
| set_bit( | ||
| overlay( | ||
| uuid_send(gen_random_uuid()) | ||
| PLACING substring(int8send(floor(extract(epoch FROM clock_timestamp()) * 1000)::bigint) FROM 3) | ||
| FROM 1 FOR 6 | ||
| ), | ||
| 52, 1 | ||
| ), | ||
| 53, 1 | ||
| ), | ||
| 'hex' | ||
| )::uuid; | ||
| END | ||
| $$ | ||
| LANGUAGE plpgsql | ||
|
majdyz marked this conversation as resolved.
|
||
| VOLATILE; | ||
|
|
||
| -- Repoint existing id defaults from Prisma-client uuid()/gen_random_uuid() to uuid_generate_v7(). | ||
| ALTER TABLE "UserOnboarding" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "CoPilotUnderstanding" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "UserWorkspace" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "UserWorkspaceFile" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "SharedExecutionFile" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "BuilderSearchHistory" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "ChatSession" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "ChatMessage" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "AgentGraph" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "AgentPreset" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "NotificationEvent" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "UserNotificationBatch" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "PushSubscription" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "LibraryAgent" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "LibraryFolder" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "AgentNode" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "AgentNodeLink" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "AgentBlock" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "AgentGraphExecution" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "AgentNodeExecution" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "AgentNodeExecutionInputOutput" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "IntegrationWebhook" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "AnalyticsDetails" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "AnalyticsMetrics" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "CreditTransaction" ALTER COLUMN "transactionKey" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "CreditRefundRequest" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "PlatformCostLog" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "Profile" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "StoreListing" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "StoreListingVersion" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "UnifiedContentEmbedding" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "StoreListingReview" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "APIKey" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "OAuthApplication" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "OAuthAuthorizationCode" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "OAuthAccessToken" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "OAuthRefreshToken" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "PlatformLink" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "PlatformUserLink" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
| ALTER TABLE "PlatformLinkToken" ALTER COLUMN "id" SET DEFAULT uuid_generate_v7(); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.