diff --git a/src/features/auth/logic/seed-admin.ts b/src/features/auth/logic/seed-admin.ts index 5fe79f1..6ae0e1b 100644 --- a/src/features/auth/logic/seed-admin.ts +++ b/src/features/auth/logic/seed-admin.ts @@ -10,7 +10,18 @@ import { count, eq, sql } from "drizzle-orm"; */ export async function ensureAdminExists() { try { - // 1. Check if admin specifically exists + // 1. Auto-repair: Ensure table exists (Fallback if db-init failed) + // Note: Using raw SQL to avoid Drizzle mapping issues during initialization + await db.execute(sql` + CREATE TABLE IF NOT EXISTS "users" ( + id SERIAL PRIMARY KEY, + username VARCHAR(50) NOT NULL UNIQUE, + password_hash TEXT NOT NULL, + role VARCHAR(20) NOT NULL DEFAULT 'user', + created_at TIMESTAMP DEFAULT NOW() + ); + `); + console.log("[AUTH] users table verified/created."); const adminUser = await db.select() .from(users) .where(eq(users.username, "admin"))