whatever...
This commit is contained in:
+22
-1
@@ -20,8 +20,29 @@ export async function register() {
|
||||
const client = postgres(process.env.DATABASE_URL!, { max: 1, connect_timeout: 10 })
|
||||
const db = drizzle(client)
|
||||
await migrate(db, { migrationsFolder: './lib/db/migrations' })
|
||||
await client.end()
|
||||
console.log('[migrations] Done')
|
||||
|
||||
// Seed admin user from ADMIN_EMAIL if not already present
|
||||
const adminEmail = process.env.ADMIN_EMAIL
|
||||
if (adminEmail) {
|
||||
const { user } = await import('./lib/db/schema')
|
||||
const { eq } = await import('drizzle-orm')
|
||||
const existing = await db.select({ id: user.id }).from(user).where(eq(user.email, adminEmail)).limit(1)
|
||||
if (existing.length === 0) {
|
||||
const { default: crypto } = await import('crypto')
|
||||
await db.insert(user).values({
|
||||
id: crypto.randomUUID(),
|
||||
email: adminEmail,
|
||||
name: adminEmail.split('@')[0],
|
||||
emailVerified: true,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
console.log('[seed] Admin user created:', adminEmail)
|
||||
}
|
||||
}
|
||||
|
||||
await client.end()
|
||||
} catch (err) {
|
||||
console.error('[migrations] Failed:', err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user