67 lines
1.8 KiB
JavaScript
67 lines
1.8 KiB
JavaScript
import { getDatabase } from '../src/db.js';
|
|
import { initDatabase } from '../src/db.js';
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
import config from '../src/config.js';
|
|
|
|
async function main() {
|
|
try {
|
|
console.log('🚀 Initializing and seeding database...');
|
|
await initDatabase(config.db.path);
|
|
const db = await getDatabase();
|
|
|
|
// Seed sample services
|
|
const services = [
|
|
{
|
|
id: uuidv4(),
|
|
name: 'API Service',
|
|
path: '/api',
|
|
target_url: 'http://localhost:3001',
|
|
require_auth: 1,
|
|
description: 'Internal API service',
|
|
},
|
|
{
|
|
id: uuidv4(),
|
|
name: 'Admin Dashboard',
|
|
path: '/admin-app',
|
|
target_url: 'http://localhost:4200',
|
|
require_auth: 1,
|
|
description: 'Admin dashboard application',
|
|
},
|
|
{
|
|
id: uuidv4(),
|
|
name: 'Public Service',
|
|
path: '/public',
|
|
target_url: 'http://localhost:5000',
|
|
require_auth: 0,
|
|
description: 'Public accessible service',
|
|
},
|
|
];
|
|
|
|
for (const service of services) {
|
|
const existing = await db.get(
|
|
'SELECT id FROM services WHERE name = ?',
|
|
[service.name]
|
|
);
|
|
|
|
if (!existing) {
|
|
await db.run(
|
|
`INSERT INTO services (id, name, path, target_url, require_auth, description)
|
|
VALUES (?, ?, ?, ?, ?, ?)`,
|
|
[service.id, service.name, service.path, service.target_url, service.require_auth, service.description]
|
|
);
|
|
console.log(`✓ Created service: ${service.name}`);
|
|
} else {
|
|
console.log(`⊙ Service already exists: ${service.name}`);
|
|
}
|
|
}
|
|
|
|
console.log('✓ Database seeded successfully!');
|
|
process.exit(0);
|
|
} catch (error) {
|
|
console.error('✗ Database seeding failed:', error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
main();
|