fix: seed.ts migré PostgreSQL → MySQL (AppDataSource)
All checks were successful
CI/CD — Build & Deploy / Build & Deploy (push) Successful in 31s
All checks were successful
CI/CD — Build & Deploy / Build & Deploy (push) Successful in 31s
This commit is contained in:
@@ -1,31 +1,21 @@
|
|||||||
import 'reflect-metadata';
|
import 'reflect-metadata';
|
||||||
import { DataSource } from 'typeorm';
|
import { AppDataSource } from './data-source';
|
||||||
import { LevelThreshold } from '../character/entities/level-threshold.entity';
|
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() {
|
async function seed() {
|
||||||
await dataSource.initialize();
|
await AppDataSource.initialize();
|
||||||
console.log('DB connectée');
|
console.log('DB connectée (MySQL)');
|
||||||
|
|
||||||
const repo = dataSource.getRepository(LevelThreshold);
|
const repo = AppDataSource.getRepository(LevelThreshold);
|
||||||
const existing = await repo.count();
|
const existing = await repo.count();
|
||||||
|
|
||||||
if (existing >= 100) {
|
if (existing >= 100) {
|
||||||
console.log('Level thresholds déjà seedés — skip');
|
console.log('Level thresholds déjà seedés — skip');
|
||||||
await dataSource.destroy();
|
await AppDataSource.destroy();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// XP requis = 100 × level^1.5
|
// 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 thresholds: LevelThreshold[] = Array.from({ length: 100 }, (_, i) => {
|
||||||
const level = i + 1;
|
const level = i + 1;
|
||||||
const threshold = new LevelThreshold();
|
const threshold = new LevelThreshold();
|
||||||
@@ -37,7 +27,7 @@ async function seed() {
|
|||||||
await repo.save(thresholds);
|
await repo.save(thresholds);
|
||||||
console.log('✅ 100 level_thresholds seedés');
|
console.log('✅ 100 level_thresholds seedés');
|
||||||
|
|
||||||
await dataSource.destroy();
|
await AppDataSource.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
seed().catch((err) => {
|
seed().catch((err) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user