68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
|
|
/**
|
||
|
|
* Initialize database with default configurations
|
||
|
|
* Run with: npx ts-node scripts/init-db.ts
|
||
|
|
*/
|
||
|
|
|
||
|
|
import { PrismaClient } from '@prisma/client';
|
||
|
|
|
||
|
|
const prisma = new PrismaClient();
|
||
|
|
|
||
|
|
async function initDatabase() {
|
||
|
|
try {
|
||
|
|
console.log('=== Initializing Database ===\n');
|
||
|
|
|
||
|
|
// Create default system configs
|
||
|
|
const defaultConfigs = [
|
||
|
|
{
|
||
|
|
key: 'push_notification_provider',
|
||
|
|
value: 'firebase',
|
||
|
|
description: 'Default push notification provider',
|
||
|
|
category: 'notifications',
|
||
|
|
},
|
||
|
|
{
|
||
|
|
key: 'max_deployment_retries',
|
||
|
|
value: 3,
|
||
|
|
description: 'Maximum number of deployment retries',
|
||
|
|
category: 'deployment',
|
||
|
|
},
|
||
|
|
{
|
||
|
|
key: 'deployment_timeout',
|
||
|
|
value: 300000, // 5 minutes
|
||
|
|
description: 'Deployment timeout in milliseconds',
|
||
|
|
category: 'deployment',
|
||
|
|
},
|
||
|
|
{
|
||
|
|
key: 'audit_log_retention_days',
|
||
|
|
value: 90,
|
||
|
|
description: 'Number of days to retain audit logs',
|
||
|
|
category: 'logging',
|
||
|
|
},
|
||
|
|
{
|
||
|
|
key: 'rate_limit_requests_per_minute',
|
||
|
|
value: 100,
|
||
|
|
description: 'Default rate limit for API requests',
|
||
|
|
category: 'security',
|
||
|
|
},
|
||
|
|
];
|
||
|
|
|
||
|
|
for (const config of defaultConfigs) {
|
||
|
|
await prisma.systemConfig.upsert({
|
||
|
|
where: { key: config.key },
|
||
|
|
update: {},
|
||
|
|
create: config,
|
||
|
|
});
|
||
|
|
console.log(`✅ Created config: ${config.key}`);
|
||
|
|
}
|
||
|
|
|
||
|
|
console.log('\n✅ Database initialization complete!');
|
||
|
|
} catch (error: any) {
|
||
|
|
console.error('\n❌ Error initializing database:', error.message);
|
||
|
|
process.exit(1);
|
||
|
|
} finally {
|
||
|
|
await prisma.$disconnect();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
initDatabase();
|
||
|
|
|