Fix: seed-demo now links demo accounts to existing school

- seed-demo.ts now finds any existing school (from seed.ts) instead of creating a separate 'Demo Schule'
- This ensures demo accounts have access to the seeded data (classes, students, etc.)
- Falls back to creating a school if none exists
This commit is contained in:
Z User committed 2026-08-10 16:09:51 +00:00
1 parent f63326c29b
commit 9f26c6da38
1 file changed
+19 -3
+19 -3
View File
@@ -20,11 +20,27 @@ async function main() {
parallelism: 1,
})
// Find any existing school (from seed.ts) or create one
let school = await prisma.school.findFirst()
if (!school) {
school = await prisma.school.create({
data: {
name: 'Demo Schule',
schoolType: 'GYMNASIUM',
country: 'DE',
timezone: 'Europe/Berlin',
},
})
console.log(`Created demo school: ${school.id}`)
} else {
console.log(`Using existing school: ${school.name} (${school.id})`)
}
for (const user of demoUsers) {
await prisma.user.upsert({
where: { email: user.email },
update: { isDemo: true, passwordHash },
create: { ...user, passwordHash, locale: 'de', isDemo: true },
update: { isDemo: true, passwordHash, schoolId: school.id },
create: { ...user, passwordHash, locale: 'de', isDemo: true, schoolId: school.id },
})
}
@@ -33,7 +49,7 @@ async function main() {
})
if (seededCount !== demoUsers.length) throw new Error(`Expected ${demoUsers.length} demo accounts, found ${seededCount}`)
console.log(`Ensured ${seededCount} demo accounts.`)
console.log(`Ensured ${seededCount} demo accounts (schoolId: ${school.id}).`)
}
main()