import { pgTable, uuid, text, timestamp, integer } from 'drizzle-orm/pg-core'; import { users } from './users'; // Better Auth Sessions export const sessions = pgTable('sessions', { id: uuid('id').primaryKey().defaultRandom(), userId: uuid('user_id') .references(() => users.id, { onDelete: 'cascade' }) .notNull(), token: text('token').notNull().unique(), expiresAt: timestamp('expires_at').notNull(), ipAddress: text('ip_address'), userAgent: text('user_agent'), createdAt: timestamp('created_at').defaultNow().notNull(), updatedAt: timestamp('updated_at').defaultNow().notNull(), }); // Better Auth Accounts (for OAuth providers) export const accounts = pgTable('accounts', { id: uuid('id').primaryKey().defaultRandom(), userId: uuid('user_id') .references(() => users.id, { onDelete: 'cascade' }) .notNull(), providerId: text('provider_id').notNull(), // 'credential', 'google', 'apple', etc. accountId: text('account_id').notNull(), // Provider's user ID or email for credential accessToken: text('access_token'), refreshToken: text('refresh_token'), accessTokenExpiresAt: timestamp('access_token_expires_at'), refreshTokenExpiresAt: timestamp('refresh_token_expires_at'), scope: text('scope'), password: text('password'), // Hashed, only for credential provider createdAt: timestamp('created_at').defaultNow().notNull(), updatedAt: timestamp('updated_at').defaultNow().notNull(), }); // Better Auth Verification Tokens export const verifications = pgTable('verifications', { id: uuid('id').primaryKey().defaultRandom(), identifier: text('identifier').notNull(), // email or other identifier value: text('value').notNull(), // the token expiresAt: timestamp('expires_at').notNull(), createdAt: timestamp('created_at').defaultNow().notNull(), updatedAt: timestamp('updated_at').defaultNow().notNull(), }); export type Session = typeof sessions.$inferSelect; export type NewSession = typeof sessions.$inferInsert; export type Account = typeof accounts.$inferSelect; export type NewAccount = typeof accounts.$inferInsert; export type Verification = typeof verifications.$inferSelect; export type NewVerification = typeof verifications.$inferInsert;