@@ -11,8 +11,58 @@ import {
1111} from "drizzle-orm/pg-core" ;
1212import { relations } from "drizzle-orm" ;
1313
14- // Better Auth creates its own tables: user, session, account, verification
15- // We reference user.id (text) in our app tables
14+ // Better Auth tables
15+ export const user = pgTable ( "user" , {
16+ id : text ( "id" ) . primaryKey ( ) ,
17+ name : text ( "name" ) . notNull ( ) ,
18+ email : text ( "email" ) . notNull ( ) . unique ( ) ,
19+ emailVerified : boolean ( "email_verified" ) . notNull ( ) ,
20+ image : text ( "image" ) ,
21+ createdAt : timestamp ( "created_at" ) . notNull ( ) ,
22+ updatedAt : timestamp ( "updated_at" ) . notNull ( ) ,
23+ } ) ;
24+
25+ export const session = pgTable ( "session" , {
26+ id : text ( "id" ) . primaryKey ( ) ,
27+ expiresAt : timestamp ( "expires_at" ) . notNull ( ) ,
28+ token : text ( "token" ) . notNull ( ) . unique ( ) ,
29+ createdAt : timestamp ( "created_at" ) . notNull ( ) ,
30+ updatedAt : timestamp ( "updated_at" ) . notNull ( ) ,
31+ ipAddress : text ( "ip_address" ) ,
32+ userAgent : text ( "user_agent" ) ,
33+ userId : text ( "user_id" )
34+ . notNull ( )
35+ . references ( ( ) => user . id , { onDelete : "cascade" } ) ,
36+ } ) ;
37+
38+ export const account = pgTable ( "account" , {
39+ id : text ( "id" ) . primaryKey ( ) ,
40+ accountId : text ( "account_id" ) . notNull ( ) ,
41+ providerId : text ( "provider_id" ) . notNull ( ) ,
42+ userId : text ( "user_id" )
43+ . notNull ( )
44+ . references ( ( ) => user . id , { onDelete : "cascade" } ) ,
45+ accessToken : text ( "access_token" ) ,
46+ refreshToken : text ( "refresh_token" ) ,
47+ idToken : text ( "id_token" ) ,
48+ accessTokenExpiresAt : timestamp ( "access_token_expires_at" ) ,
49+ refreshTokenExpiresAt : timestamp ( "refresh_token_expires_at" ) ,
50+ scope : text ( "scope" ) ,
51+ password : text ( "password" ) ,
52+ createdAt : timestamp ( "created_at" ) . notNull ( ) ,
53+ updatedAt : timestamp ( "updated_at" ) . notNull ( ) ,
54+ } ) ;
55+
56+ export const verification = pgTable ( "verification" , {
57+ id : text ( "id" ) . primaryKey ( ) ,
58+ identifier : text ( "identifier" ) . notNull ( ) ,
59+ value : text ( "value" ) . notNull ( ) ,
60+ expiresAt : timestamp ( "expires_at" ) . notNull ( ) ,
61+ createdAt : timestamp ( "created_at" ) ,
62+ updatedAt : timestamp ( "updated_at" ) ,
63+ } ) ;
64+
65+ // App tables - reference user.id (text)
1666
1767// Conversations table
1868export const conversations = pgTable ( "conversations" , {
0 commit comments