- Complete monorepo structure with pnpm workspaces - Prisma database schema with 20+ entities - NestJS API with 9 core modules - BullMQ orchestration worker - AWS and Azure provider adapters - Docker Compose infrastructure - Complete documentation
161 lines
3.8 KiB
TypeScript
161 lines
3.8 KiB
TypeScript
import { PrismaClient } from '@sdi/database';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
console.log('Seeding database...');
|
|
|
|
// Create providers
|
|
const awsProvider = await prisma.provider.create({
|
|
data: {
|
|
name: 'Amazon Web Services',
|
|
type: 'aws',
|
|
status: 'active',
|
|
metadata: {
|
|
description: 'AWS Direct Connect',
|
|
},
|
|
},
|
|
});
|
|
|
|
const azureProvider = await prisma.provider.create({
|
|
data: {
|
|
name: 'Microsoft Azure',
|
|
type: 'azure',
|
|
status: 'active',
|
|
metadata: {
|
|
description: 'Azure ExpressRoute',
|
|
},
|
|
},
|
|
});
|
|
|
|
console.log('✓ Created providers');
|
|
|
|
// Create AWS endpoints
|
|
const awsEndpoints = [
|
|
{ region: 'us-east-1', metro: 'Washington DC', location: 'Equinix DC2' },
|
|
{ region: 'us-west-2', metro: 'Seattle', location: 'Equinix SE2' },
|
|
{ region: 'eu-west-1', metro: 'Dublin', location: 'Equinix DB3' },
|
|
];
|
|
|
|
for (const ep of awsEndpoints) {
|
|
await prisma.endpoint.create({
|
|
data: {
|
|
providerId: awsProvider.id,
|
|
kind: 'cloud_region',
|
|
region: ep.region,
|
|
metro: ep.metro,
|
|
location: ep.location,
|
|
status: 'available',
|
|
metadata: { provider: 'aws' },
|
|
},
|
|
});
|
|
}
|
|
|
|
console.log('✓ Created AWS endpoints');
|
|
|
|
// Create Azure endpoints
|
|
const azureEndpoints = [
|
|
{ region: 'eastus', metro: 'Washington DC', location: 'Equinix DC2' },
|
|
{ region: 'westus2', metro: 'Seattle', location: 'Equinix SE2' },
|
|
{ region: 'westeurope', metro: 'Amsterdam', location: 'Equinix AM3' },
|
|
];
|
|
|
|
for (const ep of azureEndpoints) {
|
|
await prisma.endpoint.create({
|
|
data: {
|
|
providerId: azureProvider.id,
|
|
kind: 'cloud_region',
|
|
region: ep.region,
|
|
metro: ep.metro,
|
|
location: ep.location,
|
|
status: 'available',
|
|
metadata: { provider: 'azure' },
|
|
},
|
|
});
|
|
}
|
|
|
|
console.log('✓ Created Azure endpoints');
|
|
|
|
// Create product offerings
|
|
await prisma.productOffering.create({
|
|
data: {
|
|
providerId: awsProvider.id,
|
|
name: 'AWS Direct Connect - 1Gbps',
|
|
description: 'Dedicated 1Gbps connection to AWS',
|
|
type: 'cloud_interconnect',
|
|
status: 'active',
|
|
pricing: {
|
|
setupFee: 500,
|
|
monthlyRecurring: 50,
|
|
currency: 'USD',
|
|
},
|
|
},
|
|
});
|
|
|
|
await prisma.productOffering.create({
|
|
data: {
|
|
providerId: azureProvider.id,
|
|
name: 'Azure ExpressRoute - 1Gbps',
|
|
description: 'Dedicated 1Gbps connection to Azure',
|
|
type: 'cloud_interconnect',
|
|
status: 'active',
|
|
pricing: {
|
|
setupFee: 600,
|
|
monthlyRecurring: 60,
|
|
currency: 'USD',
|
|
},
|
|
},
|
|
});
|
|
|
|
console.log('✓ Created product offerings');
|
|
|
|
// Create demo tenant
|
|
const tenant = await prisma.tenant.create({
|
|
data: {
|
|
name: 'Demo Corporation',
|
|
slug: 'demo-corp',
|
|
status: 'active',
|
|
},
|
|
});
|
|
|
|
console.log('✓ Created demo tenant');
|
|
|
|
// Create demo user
|
|
const user = await prisma.user.create({
|
|
data: {
|
|
tenantId: tenant.id,
|
|
email: 'admin@demo-corp.com',
|
|
name: 'Demo Admin',
|
|
status: 'active',
|
|
},
|
|
});
|
|
|
|
await prisma.role.create({
|
|
data: {
|
|
userId: user.id,
|
|
name: 'admin',
|
|
permissions: {
|
|
orders: ['create', 'read', 'update', 'delete'],
|
|
services: ['read', 'modify', 'suspend', 'terminate'],
|
|
},
|
|
},
|
|
});
|
|
|
|
console.log('✓ Created demo user with admin role');
|
|
|
|
console.log('\n✅ Database seeded successfully!');
|
|
console.log('\nDemo credentials:');
|
|
console.log(` Tenant: ${tenant.slug}`);
|
|
console.log(` Email: ${user.email}`);
|
|
console.log(` Tenant ID: ${tenant.id}`);
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error('Error seeding database:', e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|