Private
Public Access
1
0

Auto-create tenant for any hostname that reaches the app

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>
This commit is contained in:
Catherine Renelle
2026-02-25 22:30:05 -05:00
parent 7b540a37ee
commit 80c17d4c6f
2 changed files with 67 additions and 30 deletions
+11 -22
View File
@@ -6,28 +6,19 @@ const prisma = new PrismaClient();
async function main() {
console.log('Seeding database...');
// Create default tenant
const tenant = await prisma.tenant.upsert({
where: { slug: 'default' },
update: {},
create: {
name: 'Default Workspace',
slug: 'default'
}
});
// Map hostnames to default tenant
const hostnames = ['localhost', '127.0.0.1', 'pounce.catrenelle.com'];
for (const hostname of hostnames) {
await prisma.tenantHostname.upsert({
where: { hostname },
update: {},
create: {
hostname,
tenantId: tenant.id,
isPrimary: hostname === 'localhost'
// 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
@@ -46,8 +37,6 @@ async function main() {
});
console.log('Seed complete.');
console.log(` Tenant: ${tenant.name} (${tenant.id})`);
console.log(` Hostnames: ${hostnames.join(', ')}`);
console.log(' Admin: admin@example.com / admin123');
}