racing typeorm
This commit is contained in:
@@ -2,13 +2,13 @@ import type { Logger } from '@core/shared/application';
|
||||
import type { EnsureInitialData } from '../../../../../adapters/bootstrap/EnsureInitialData';
|
||||
import { SeedRacingData, type RacingSeedDependencies } from '../../../../../adapters/bootstrap/SeedRacingData';
|
||||
import { Inject, Module, OnModuleInit } from '@nestjs/common';
|
||||
import { getApiPersistence } from '../../env';
|
||||
import { InMemoryRacingPersistenceModule } from '../../persistence/inmemory/InMemoryRacingPersistenceModule';
|
||||
import { getApiPersistence, getEnableBootstrap } from '../../env';
|
||||
import { RacingPersistenceModule } from '../../persistence/racing/RacingPersistenceModule';
|
||||
import { InMemorySocialPersistenceModule } from '../../persistence/inmemory/InMemorySocialPersistenceModule';
|
||||
import { BootstrapProviders, ENSURE_INITIAL_DATA_TOKEN } from './BootstrapProviders';
|
||||
|
||||
@Module({
|
||||
imports: [InMemoryRacingPersistenceModule, InMemorySocialPersistenceModule],
|
||||
imports: [RacingPersistenceModule, InMemorySocialPersistenceModule],
|
||||
providers: BootstrapProviders,
|
||||
})
|
||||
export class BootstrapModule implements OnModuleInit {
|
||||
@@ -21,9 +21,14 @@ export class BootstrapModule implements OnModuleInit {
|
||||
async onModuleInit() {
|
||||
console.log('[Bootstrap] Initializing application data...');
|
||||
try {
|
||||
if (!getEnableBootstrap()) {
|
||||
this.logger.info('[Bootstrap] Bootstrap disabled via GRIDPILOT_API_BOOTSTRAP; skipping initialization');
|
||||
return;
|
||||
}
|
||||
|
||||
await this.ensureInitialData.execute();
|
||||
|
||||
if (this.shouldSeedRacingData()) {
|
||||
if (await this.shouldSeedRacingData()) {
|
||||
await new SeedRacingData(this.logger, this.seedDeps).execute();
|
||||
}
|
||||
|
||||
@@ -34,7 +39,21 @@ export class BootstrapModule implements OnModuleInit {
|
||||
}
|
||||
}
|
||||
|
||||
private shouldSeedRacingData(): boolean {
|
||||
return getApiPersistence() === 'inmemory';
|
||||
private async shouldSeedRacingData(): Promise<boolean> {
|
||||
const persistence = getApiPersistence();
|
||||
|
||||
if (persistence === 'inmemory') return true;
|
||||
if (persistence !== 'postgres') return false;
|
||||
if (process.env.NODE_ENV === 'production') return false;
|
||||
|
||||
return this.isRacingDatabaseEmpty();
|
||||
}
|
||||
|
||||
private async isRacingDatabaseEmpty(): Promise<boolean> {
|
||||
const count = await this.seedDeps.leagueRepository.countAll?.();
|
||||
if (typeof count === 'number') return count === 0;
|
||||
|
||||
const leagues = await this.seedDeps.leagueRepository.findAll();
|
||||
return leagues.length === 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user