// Drizzle schema for the tables Better Auth's drizzleAdapter manages. // Keep names + columns aligned with worker/src/db/migrations/0001_init.sql. // // Property names are snake_case to match the column names AND what Better // Auth's `fields` mapping resolves to. Better Auth's TS API still uses // camelCase (user.emailVerified); the adapter applies the `fields` map and // then looks the resolved name up as a property here — so the property name // has to match the renamed value, not the camelCase API name. import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'; export const users = sqliteTable('users', { id: text('id').primaryKey(), email: text('email').notNull().unique(), email_verified: integer('email_verified', { mode: 'boolean' }).notNull().default(true), name: text('name'), image: text('image'), role: text('role').notNull().default('viewer'), created_at: integer('created_at', { mode: 'timestamp' }).notNull(), updated_at: integer('updated_at', { mode: 'timestamp' }).notNull(), }); export const accounts = sqliteTable('accounts', { id: text('id').primaryKey(), account_id: text('account_id').notNull(), provider_id: text('provider_id').notNull(), user_id: text('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }), access_token: text('access_token'), refresh_token: text('refresh_token'), id_token: text('id_token'), access_token_expires_at: integer('access_token_expires_at', { mode: 'timestamp' }), refresh_token_expires_at: integer('refresh_token_expires_at', { mode: 'timestamp' }), scope: text('scope'), password: text('password'), created_at: integer('created_at', { mode: 'timestamp' }).notNull(), updated_at: integer('updated_at', { mode: 'timestamp' }).notNull(), }); export const sessions = sqliteTable('sessions', { id: text('id').primaryKey(), token: text('token').notNull().unique(), user_id: text('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }), expires_at: integer('expires_at', { mode: 'timestamp' }).notNull(), ip_address: text('ip_address'), user_agent: text('user_agent'), created_at: integer('created_at', { mode: 'timestamp' }).notNull(), updated_at: integer('updated_at', { mode: 'timestamp' }).notNull(), }); export const verifications = sqliteTable('verifications', { id: text('id').primaryKey(), identifier: text('identifier').notNull(), value: text('value').notNull(), expires_at: integer('expires_at', { mode: 'timestamp' }).notNull(), created_at: integer('created_at', { mode: 'timestamp' }).notNull(), updated_at: integer('updated_at', { mode: 'timestamp' }).notNull(), });