11import { relations } from "drizzle-orm" ;
2- import { boolean , index , integer , jsonb , pgTable , text , timestamp } from "drizzle-orm/pg-core" ;
2+ import {
3+ boolean ,
4+ index ,
5+ integer ,
6+ jsonb ,
7+ pgTable ,
8+ text ,
9+ timestamp ,
10+ uniqueIndex ,
11+ } from "drizzle-orm/pg-core" ;
312
413export const user = pgTable ( "user" , {
514 id : text ( "id" ) . primaryKey ( ) ,
@@ -44,6 +53,7 @@ export const account = pgTable(
4453 "account" ,
4554 {
4655 id : text ( "id" ) . primaryKey ( ) ,
56+ issuer : text ( "issuer" ) . notNull ( ) ,
4757 accountId : text ( "account_id" ) . notNull ( ) ,
4858 providerId : text ( "provider_id" ) . notNull ( ) ,
4959 userId : text ( "user_id" )
@@ -61,7 +71,10 @@ export const account = pgTable(
6171 . $onUpdate ( ( ) => /* @__PURE__ */ new Date ( ) )
6272 . notNull ( ) ,
6373 } ,
64- ( table ) => [ index ( "account_userId_idx" ) . on ( table . userId ) ] ,
74+ ( table ) => [
75+ uniqueIndex ( "account_issuer_accountId_uidx" ) . on ( table . issuer , table . accountId ) ,
76+ index ( "account_userId_idx" ) . on ( table . userId ) ,
77+ ] ,
6578) ;
6679
6780export const verification = pgTable (
@@ -128,6 +141,8 @@ export const jwks = pgTable("jwks", {
128141 privateKey : text ( "private_key" ) . notNull ( ) ,
129142 createdAt : timestamp ( "created_at" ) . notNull ( ) ,
130143 expiresAt : timestamp ( "expires_at" ) ,
144+ alg : text ( "alg" ) ,
145+ crv : text ( "crv" ) ,
131146} ) ;
132147
133148export const oauthClient = pgTable (
@@ -136,11 +151,13 @@ export const oauthClient = pgTable(
136151 id : text ( "id" ) . primaryKey ( ) ,
137152 clientId : text ( "client_id" ) . notNull ( ) . unique ( ) ,
138153 clientSecret : text ( "client_secret" ) ,
154+ clientDiscoveryId : text ( "client_discovery_id" ) ,
139155 disabled : boolean ( "disabled" ) . default ( false ) ,
140156 skipConsent : boolean ( "skip_consent" ) ,
141157 enableEndSession : boolean ( "enable_end_session" ) ,
142158 subjectType : text ( "subject_type" ) ,
143159 scopes : text ( "scopes" ) . array ( ) ,
160+ clientCredentialsScopes : text ( "client_credentials_scopes" ) . array ( ) . default ( [ ] ) ,
144161 userId : text ( "user_id" ) . references ( ( ) => user . id , { onDelete : "cascade" } ) ,
145162 createdAt : timestamp ( "created_at" ) ,
146163 updatedAt : timestamp ( "updated_at" ) ,
@@ -155,18 +172,63 @@ export const oauthClient = pgTable(
155172 softwareStatement : text ( "software_statement" ) ,
156173 redirectUris : text ( "redirect_uris" ) . array ( ) . notNull ( ) ,
157174 postLogoutRedirectUris : text ( "post_logout_redirect_uris" ) . array ( ) ,
175+ backchannelLogoutUri : text ( "backchannel_logout_uri" ) ,
176+ backchannelLogoutSessionRequired : boolean ( "backchannel_logout_session_required" ) ,
158177 tokenEndpointAuthMethod : text ( "token_endpoint_auth_method" ) ,
178+ applicationType : text ( "application_type" ) ,
179+ jwks : text ( "jwks" ) ,
180+ jwksUri : text ( "jwks_uri" ) ,
159181 grantTypes : text ( "grant_types" ) . array ( ) ,
160182 responseTypes : text ( "response_types" ) . array ( ) ,
161- public : boolean ( "public" ) ,
162- type : text ( "type" ) ,
163183 requirePKCE : boolean ( "require_pkce" ) ,
184+ dpopBoundAccessTokens : boolean ( "dpop_bound_access_tokens" ) . default ( false ) ,
164185 referenceId : text ( "reference_id" ) ,
165186 metadata : jsonb ( "metadata" ) ,
166187 } ,
167188 ( table ) => [ index ( "oauthClient_userId_idx" ) . on ( table . userId ) ] ,
168189) ;
169190
191+ export const oauthResource = pgTable ( "oauth_resource" , {
192+ id : text ( "id" ) . primaryKey ( ) ,
193+ identifier : text ( "identifier" ) . notNull ( ) . unique ( ) ,
194+ name : text ( "name" ) . notNull ( ) ,
195+ accessTokenTtl : integer ( "access_token_ttl" ) ,
196+ refreshTokenTtl : integer ( "refresh_token_ttl" ) ,
197+ signingAlgorithm : text ( "signing_algorithm" ) ,
198+ signingKeyId : text ( "signing_key_id" ) ,
199+ allowedScopes : text ( "allowed_scopes" ) . array ( ) ,
200+ customClaims : jsonb ( "custom_claims" ) ,
201+ dpopBoundAccessTokensRequired : boolean ( "dpop_bound_access_tokens_required" ) . default ( false ) ,
202+ disabled : boolean ( "disabled" ) . default ( false ) ,
203+ createdAt : timestamp ( "created_at" ) ,
204+ updatedAt : timestamp ( "updated_at" ) ,
205+ policyVersion : integer ( "policy_version" ) . default ( 1 ) ,
206+ metadata : jsonb ( "metadata" ) ,
207+ } ) ;
208+
209+ export const oauthClientResource = pgTable (
210+ "oauth_client_resource" ,
211+ {
212+ id : text ( "id" ) . primaryKey ( ) ,
213+ clientId : text ( "client_id" )
214+ . notNull ( )
215+ . references ( ( ) => oauthClient . clientId , { onDelete : "cascade" } ) ,
216+ resourceId : text ( "resource_id" )
217+ . notNull ( )
218+ . references ( ( ) => oauthResource . identifier , { onDelete : "cascade" } ) ,
219+ metadata : jsonb ( "metadata" ) ,
220+ createdAt : timestamp ( "created_at" ) ,
221+ } ,
222+ ( table ) => [
223+ uniqueIndex ( "oauthClientResource_clientId_resourceId_uidx" ) . on (
224+ table . clientId ,
225+ table . resourceId ,
226+ ) ,
227+ index ( "oauthClientResource_clientId_idx" ) . on ( table . clientId ) ,
228+ index ( "oauthClientResource_resourceId_idx" ) . on ( table . resourceId ) ,
229+ ] ,
230+ ) ;
231+
170232export const oauthRefreshToken = pgTable (
171233 "oauth_refresh_token" ,
172234 {
@@ -182,16 +244,24 @@ export const oauthRefreshToken = pgTable(
182244 . notNull ( )
183245 . references ( ( ) => user . id , { onDelete : "cascade" } ) ,
184246 referenceId : text ( "reference_id" ) ,
247+ authorizationCodeId : text ( "authorization_code_id" ) ,
248+ resources : text ( "resources" ) . array ( ) ,
249+ requestedUserInfoClaims : text ( "requested_user_info_claims" ) . array ( ) ,
185250 expiresAt : timestamp ( "expires_at" ) . notNull ( ) ,
186251 createdAt : timestamp ( "created_at" ) . notNull ( ) ,
187252 revoked : timestamp ( "revoked" ) ,
253+ rotatedAt : timestamp ( "rotated_at" ) ,
254+ rotationReplayResponse : text ( "rotation_replay_response" ) ,
255+ rotationReplayExpiresAt : timestamp ( "rotation_replay_expires_at" ) ,
188256 authTime : timestamp ( "auth_time" ) ,
257+ confirmation : jsonb ( "confirmation" ) ,
189258 scopes : text ( "scopes" ) . array ( ) . notNull ( ) ,
190259 } ,
191260 ( table ) => [
192261 index ( "oauthRefreshToken_clientId_idx" ) . on ( table . clientId ) ,
193262 index ( "oauthRefreshToken_sessionId_idx" ) . on ( table . sessionId ) ,
194263 index ( "oauthRefreshToken_userId_idx" ) . on ( table . userId ) ,
264+ index ( "oauthRefreshToken_authorizationCodeId_idx" ) . on ( table . authorizationCodeId ) ,
195265 ] ,
196266) ;
197267
@@ -208,17 +278,23 @@ export const oauthAccessToken = pgTable(
208278 } ) ,
209279 userId : text ( "user_id" ) . references ( ( ) => user . id , { onDelete : "cascade" } ) ,
210280 referenceId : text ( "reference_id" ) ,
281+ authorizationCodeId : text ( "authorization_code_id" ) ,
282+ resources : text ( "resources" ) . array ( ) ,
283+ requestedUserInfoClaims : text ( "requested_user_info_claims" ) . array ( ) ,
211284 refreshId : text ( "refresh_id" ) . references ( ( ) => oauthRefreshToken . id , {
212285 onDelete : "cascade" ,
213286 } ) ,
214287 expiresAt : timestamp ( "expires_at" ) . notNull ( ) ,
215288 createdAt : timestamp ( "created_at" ) . notNull ( ) ,
289+ revoked : timestamp ( "revoked" ) ,
290+ confirmation : jsonb ( "confirmation" ) ,
216291 scopes : text ( "scopes" ) . array ( ) . notNull ( ) ,
217292 } ,
218293 ( table ) => [
219294 index ( "oauthAccessToken_clientId_idx" ) . on ( table . clientId ) ,
220295 index ( "oauthAccessToken_sessionId_idx" ) . on ( table . sessionId ) ,
221296 index ( "oauthAccessToken_userId_idx" ) . on ( table . userId ) ,
297+ index ( "oauthAccessToken_authorizationCodeId_idx" ) . on ( table . authorizationCodeId ) ,
222298 index ( "oauthAccessToken_refreshId_idx" ) . on ( table . refreshId ) ,
223299 ] ,
224300) ;
@@ -232,6 +308,8 @@ export const oauthConsent = pgTable(
232308 . references ( ( ) => oauthClient . clientId , { onDelete : "cascade" } ) ,
233309 userId : text ( "user_id" ) . references ( ( ) => user . id , { onDelete : "cascade" } ) ,
234310 referenceId : text ( "reference_id" ) ,
311+ resources : text ( "resources" ) . array ( ) ,
312+ requestedUserInfoClaims : text ( "requested_user_info_claims" ) . array ( ) ,
235313 scopes : text ( "scopes" ) . array ( ) . notNull ( ) ,
236314 createdAt : timestamp ( "created_at" ) . notNull ( ) ,
237315 updatedAt : timestamp ( "updated_at" ) . notNull ( ) ,
@@ -242,6 +320,11 @@ export const oauthConsent = pgTable(
242320 ] ,
243321) ;
244322
323+ export const oauthClientAssertion = pgTable ( "oauth_client_assertion" , {
324+ id : text ( "id" ) . primaryKey ( ) ,
325+ expiresAt : timestamp ( "expires_at" ) . notNull ( ) ,
326+ } ) ;
327+
245328export const userRelations = relations ( user , ( { many } ) => ( {
246329 sessions : many ( session ) ,
247330 accounts : many ( account ) ,
@@ -288,11 +371,27 @@ export const oauthClientRelations = relations(oauthClient, ({ one, many }) => ({
288371 fields : [ oauthClient . userId ] ,
289372 references : [ user . id ] ,
290373 } ) ,
374+ oauthClientResources : many ( oauthClientResource ) ,
291375 oauthRefreshTokens : many ( oauthRefreshToken ) ,
292376 oauthAccessTokens : many ( oauthAccessToken ) ,
293377 oauthConsents : many ( oauthConsent ) ,
294378} ) ) ;
295379
380+ export const oauthResourceRelations = relations ( oauthResource , ( { many } ) => ( {
381+ oauthClientResources : many ( oauthClientResource ) ,
382+ } ) ) ;
383+
384+ export const oauthClientResourceRelations = relations ( oauthClientResource , ( { one } ) => ( {
385+ oauthClient : one ( oauthClient , {
386+ fields : [ oauthClientResource . clientId ] ,
387+ references : [ oauthClient . clientId ] ,
388+ } ) ,
389+ oauthResource : one ( oauthResource , {
390+ fields : [ oauthClientResource . resourceId ] ,
391+ references : [ oauthResource . identifier ] ,
392+ } ) ,
393+ } ) ) ;
394+
296395export const oauthRefreshTokenRelations = relations ( oauthRefreshToken , ( { one, many } ) => ( {
297396 oauthClient : one ( oauthClient , {
298397 fields : [ oauthRefreshToken . clientId ] ,
0 commit comments