80c17d4c6f
DNS is the gatekeeper — if a request arrives, it was pointed here intentionally. Every new hostname gets its own tenant automatically, no manual setup or seeding required. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
51 lines
1.1 KiB
TypeScript
51 lines
1.1 KiB
TypeScript
import { PrismaClient } from '@prisma/client';
|
|
import bcrypt from 'bcrypt';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
console.log('Seeding database...');
|
|
|
|
// The app auto-creates a tenant on first request,
|
|
// but the seed ensures an admin user exists.
|
|
let tenant = await prisma.tenant.findFirst();
|
|
if (!tenant) {
|
|
tenant = await prisma.tenant.create({
|
|
data: {
|
|
name: 'Pounce',
|
|
slug: 'default'
|
|
}
|
|
});
|
|
console.log(` Created tenant: ${tenant.name} (${tenant.id})`);
|
|
} else {
|
|
console.log(` Existing tenant: ${tenant.name} (${tenant.id})`);
|
|
}
|
|
|
|
// Create admin user
|
|
const passwordHash = await bcrypt.hash('admin123', 12);
|
|
await prisma.user.upsert({
|
|
where: { tenantId_email: { tenantId: tenant.id, email: 'admin@example.com' } },
|
|
update: {},
|
|
create: {
|
|
tenantId: tenant.id,
|
|
email: 'admin@example.com',
|
|
name: 'Admin',
|
|
passwordHash,
|
|
globalRole: 'SITE_ADMIN',
|
|
tenantRole: 'ADMIN'
|
|
}
|
|
});
|
|
|
|
console.log('Seed complete.');
|
|
console.log(' Admin: admin@example.com / admin123');
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|