@@ -69,6 +69,7 @@ model User {
6969 invitationCode InvitationCode ? @relation (fields : [invitationCodeId ] , references : [id ] )
7070 invitationCodeId String ?
7171 personalAccessTokens PersonalAccessToken []
72+ createdApiKeys ApiKey []
7273 deployments WorkerDeployment []
7374 backupCodes MfaBackupCode []
7475 bulkActions BulkActionGroup []
@@ -392,6 +393,7 @@ model RuntimeEnvironment {
392393 playgroundConversations PlaygroundConversation []
393394 errorGroupStates ErrorGroupState []
394395 taskIdentifiers TaskIdentifier []
396+ apiKeys ApiKey []
395397 revokedApiKeys RevokedApiKey []
396398
397399 // A partial unique index also enforces one STAGING/PREVIEW root per project and type.
@@ -403,6 +405,31 @@ model RuntimeEnvironment {
403405 @@index ([organizationId ] )
404406}
405407
408+ model ApiKey {
409+ id String @id @default (cuid () )
410+ name String
411+ keyHash String @unique @map (" key_hash " )
412+ lastFour String @map (" last_four " )
413+
414+ runtimeEnvironment RuntimeEnvironment @relation (fields : [runtimeEnvironmentId ] , references : [id ] , onDelete : Cascade , onUpdate : Cascade )
415+ runtimeEnvironmentId String @map (" runtime_environment_id " )
416+
417+ createdBy User ? @relation (fields : [createdByUserId ] , references : [id ] , onDelete : SetNull , onUpdate : Cascade )
418+ createdByUserId String ? @map (" created_by_user_id " )
419+
420+ presetId String ? @map (" preset_id " )
421+ scopes String []
422+
423+ lastUsedAt DateTime ? @map (" last_used_at " )
424+ revokedAt DateTime ? @map (" revoked_at " )
425+ expiresAt DateTime ? @map (" expires_at " )
426+ updatedAt DateTime @updatedAt @map (" updated_at " )
427+ createdAt DateTime @default (now () ) @map (" created_at " )
428+
429+ @@index ([runtimeEnvironmentId , revokedAt , createdAt (sort : Desc ) ] )
430+ @@map (" api_keys " )
431+ }
432+
406433/// Records of previously-valid API keys that are still accepted for authentication
407434/// during a grace window after rotation. Extend or end the grace period by updating `expiresAt`.
408435model RevokedApiKey {
0 commit comments