diff --git a/scripts/db-init.js b/scripts/db-init.js index 5c0e16b..53a6eda 100644 --- a/scripts/db-init.js +++ b/scripts/db-init.js @@ -63,6 +63,17 @@ async function main() { `); console.log("[DB Init] Table session_snapshots is verified/created."); + await tempPool.query(` + CREATE TABLE IF NOT EXISTS "users" ( + "id" serial PRIMARY KEY NOT NULL, + "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("[DB Init] Table users is verified/created."); + await tempPool.end(); console.log("[DB Init] Initialization successful. Exiting."); process.exit(0); diff --git a/src/features/auth/logic/seed-admin.ts b/src/features/auth/logic/seed-admin.ts index 0827dbc..5fe79f1 100644 --- a/src/features/auth/logic/seed-admin.ts +++ b/src/features/auth/logic/seed-admin.ts @@ -10,18 +10,7 @@ import { count, eq, sql } from "drizzle-orm"; */ export async function ensureAdminExists() { try { - // 1. Auto-repair: Ensure table exists - 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() - ); - `); - - // 2. Check if admin specifically exists + // 1. Check if admin specifically exists const adminUser = await db.select() .from(users) .where(eq(users.username, "admin"))