mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-11 17:26:32 +02:00
feat: Introduce ensureAdminExists function to seed a default admin user and create the users table if needed.
This commit is contained in:
1 parent
086da9dfde
commit
4819ad7743
1 file changed
+12
-1
@@ -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"))
|
||||
|
||||
Reference in new issue
Block a user