fix: seed.ts migré PostgreSQL → MySQL (AppDataSource)
All checks were successful
CI/CD — Build & Deploy / Build & Deploy (push) Successful in 31s

This commit is contained in:
2026-03-24 17:26:02 +01:00
parent 014ffdd789
commit 210f32b9cc

View File

@@ -1,31 +1,21 @@
import 'reflect-metadata';
import { DataSource } from 'typeorm';
import { AppDataSource } from './data-source';
import { LevelThreshold } from '../character/entities/level-threshold.entity';
const dataSource = new DataSource({
type: 'postgres',
url: process.env.DATABASE_URL ?? 'postgresql://tetardpg:password@localhost:5432/tetardpg',
entities: [LevelThreshold],
synchronize: false,
});
async function seed() {
await dataSource.initialize();
console.log('DB connectée');
await AppDataSource.initialize();
console.log('DB connectée (MySQL)');
const repo = dataSource.getRepository(LevelThreshold);
const repo = AppDataSource.getRepository(LevelThreshold);
const existing = await repo.count();
if (existing >= 100) {
console.log('Level thresholds déjà seedés — skip');
await dataSource.destroy();
await AppDataSource.destroy();
return;
}
// XP requis = 100 × level^1.5
// Level 1 : 100 XP
// Level 10 : 3162 XP
// Level 100: 1 000 000 XP
const thresholds: LevelThreshold[] = Array.from({ length: 100 }, (_, i) => {
const level = i + 1;
const threshold = new LevelThreshold();
@@ -37,7 +27,7 @@ async function seed() {
await repo.save(thresholds);
console.log('✅ 100 level_thresholds seedés');
await dataSource.destroy();
await AppDataSource.destroy();
}
seed().catch((err) => {