EENE Dashboard upload to Gitea
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
28
backend/scripts/seed-if-empty.ts
Normal file
28
backend/scripts/seed-if-empty.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 로컬 DB가 비어 있을 때만 seed 실행 (최초 1회용)
|
||||
*/
|
||||
import 'dotenv/config';
|
||||
import { execSync } from 'child_process';
|
||||
import path from 'path';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
const users = await prisma.user.count();
|
||||
if (users > 0) {
|
||||
console.log('✓ Local DB has data — skip initial seed');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('📦 Empty local DB — loading initial sample data...');
|
||||
const backendRoot = path.resolve(__dirname, '..');
|
||||
execSync('tsx prisma/seed.ts', { stdio: 'inherit', cwd: backendRoot });
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(() => prisma.$disconnect());
|
||||
Reference in New Issue
Block a user