Start-Command für Production hinzufügen

This commit is contained in:
2026-08-30 11:36:44 +02:00
parent b6b2878482
commit 357fafe6b8
2 changed files with 65 additions and 1 deletions
-1
View File
@@ -11,4 +11,3 @@ dist-ssr
.vinxi .vinxi
__unconfig* __unconfig*
todos.json todos.json
scripts
+65
View File
@@ -0,0 +1,65 @@
import { config } from 'dotenv'
config({ path: ['.env.local', '.env'] })
const { eq } = await import('drizzle-orm')
const { db } = await import('#/db/index.ts')
const { account, user } = await import('#/db/schema.ts')
const { auth } = await import('#/lib/auth.ts')
const email = process.env.SEED_ADMIN_EMAIL
const password = process.env.SEED_ADMIN_PASSWORD
const name = process.env.SEED_ADMIN_NAME ?? 'Admin'
if (!email || !password) {
console.error(
'Fehlende Env-Variablen: SEED_ADMIN_EMAIL und SEED_ADMIN_PASSWORD setzen.',
)
process.exit(1)
}
const existing = await db.query.user.findFirst({
where: eq(user.email, email),
})
if (existing) {
if (existing.role !== 'admin') {
await db
.update(user)
.set({ role: 'admin', updatedAt: new Date() })
.where(eq(user.id, existing.id))
console.log(`Rolle fuer ${email} auf admin gesetzt.`)
} else {
console.log(`Admin ${email} existiert bereits.`)
}
process.exit(0)
}
const ctx = await auth.$context
const hashedPassword = await ctx.password.hash(password)
const id = crypto.randomUUID()
const now = new Date()
await db.insert(user).values({
id,
email,
name,
emailVerified: true,
role: 'admin',
createdAt: now,
updatedAt: now,
})
await db.insert(account).values({
id: crypto.randomUUID(),
accountId: id,
providerId: 'credential',
issuer: 'local:credential',
userId: id,
password: hashedPassword,
createdAt: now,
updatedAt: now,
})
console.log(`Admin ${email} angelegt.`)
process.exit(0)