From 210f32b9cc519485a4749ff9c36e44520269a405 Mon Sep 17 00:00:00 2001 From: Tetardtek Date: Tue, 24 Mar 2026 17:26:02 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20seed.ts=20migr=C3=A9=20PostgreSQL=20?= =?UTF-8?q?=E2=86=92=20MySQL=20(AppDataSource)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/seed.ts | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) 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) => {