import { index, integer, sqliteTable, text } from "drizzle-orm/sqlite-core"; export const users = sqliteTable("users", { id: integer().primaryKey(), username: text().notNull().unique(), email: text(), nickname: text(), password: text().notNull(), avatar: text(), role: text().notNull().default("user"), status: text().notNull().default("active"), publicSlug: text("public_slug").unique(), bioMarkdown: text("bio_markdown"), bioVisibility: text("bio_visibility").notNull().default("private"), socialLinksJson: text("social_links_json").notNull().default("[]"), avatarVisibility: text("avatar_visibility").notNull().default("private"), discoverVisible: integer("discover_visible", { mode: "boolean" }).notNull().default(false), discoverLocation: text("discover_location"), discoverShowLocation: integer("discover_show_location", { mode: "boolean" }).notNull().default(false), createdAt: integer("created_at", { mode: "timestamp_ms" }).defaultNow().notNull(), updatedAt: integer("updated_at", { mode: "timestamp_ms" }) .defaultNow() .$onUpdate(() => new Date()) .notNull(), }); export const sessions = sqliteTable( "sessions", { id: text().primaryKey(), userId: integer("user_id") .notNull() .references(() => users.id, { onDelete: "cascade" }), expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(), createdAt: integer("created_at", { mode: "timestamp_ms" }).defaultNow().notNull(), }, (table) => [index("sessions_user_id_idx").on(table.userId)], );