fix(seed): upsert admin so re-runs sync password from .env

Using findUnique+create skipped admin creation on re-runs, leaving
the password in .env out of sync with the DB hash after a failed
install. Upsert ensures the DB password always matches .env.
This commit is contained in:
NixReaper
2026-04-12 05:05:04 -05:00
parent aa9998cbd8
commit ba9e00d65b
4 changed files with 17 additions and 15 deletions
+7
View File
@@ -6,6 +6,13 @@ Pre-1.0 versions treat MINOR as feature releases and PATCH as bug fixes.
--- ---
## [0.6.6] — 2026-04-12
### Bug Fixes
- **`seed.ts` skips admin on re-run** — `findUnique` + `create` meant re-running the seed after a failed install left the admin password in `.env` out of sync with the hashed password in the database. Changed to `upsert` so the seed always writes the current `.env` password, making re-runs safe.
---
## [0.6.5] — 2026-04-12 ## [0.6.5] — 2026-04-12
### Bug Fixes ### Bug Fixes
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "nixpanel-server", "name": "nixpanel-server",
"version": "0.6.5", "version": "0.6.6",
"private": true, "private": true,
"workspaces": [ "workspaces": [
"server", "server",
+1 -1
View File
@@ -73,7 +73,7 @@ export async function buildApp() {
fastify.get('/api/health', async () => ({ fastify.get('/api/health', async () => ({
status: 'ok', status: 'ok',
version: '0.6.5', version: '0.6.6',
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),
})) }))
+8 -13
View File
@@ -7,19 +7,14 @@ const prisma = new PrismaClient()
async function main() { async function main() {
console.log('Seeding database...') console.log('Seeding database...')
// Admin user // Admin user — upsert so re-runs always sync the password from .env
const existing = await prisma.adminUser.findUnique({ where: { username: config.admin.username } }) const hash = await bcrypt.hash(config.admin.password, 12)
if (!existing) { await prisma.adminUser.upsert({
const hash = await bcrypt.hash(config.admin.password, 12) where: { username: config.admin.username },
await prisma.adminUser.create({ update: { passwordHash: hash, email: config.admin.email },
data: { create: { username: config.admin.username, passwordHash: hash, email: config.admin.email },
username: config.admin.username, })
passwordHash: hash, console.log(`Admin user ready: ${config.admin.username}`)
email: config.admin.email,
},
})
console.log(`Created admin user: ${config.admin.username}`)
}
// Default packages // Default packages
const packages = [ const packages = [