diff --git a/src/database/seed.ts b/src/database/seed.ts index 4c98cb9..bcb155a 100644 --- a/src/database/seed.ts +++ b/src/database/seed.ts @@ -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) => {