seed data
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { EnsureInitialData } from '../../../../../adapters/bootstrap/EnsureInitialData';
|
||||
import { SeedInMemoryRacingData } from '../../../../../adapters/bootstrap/SeedInMemoryRacingData';
|
||||
import { Module, OnModuleInit } from '@nestjs/common';
|
||||
import { BootstrapProviders } from './BootstrapProviders';
|
||||
|
||||
@@ -6,16 +7,33 @@ import { BootstrapProviders } from './BootstrapProviders';
|
||||
providers: BootstrapProviders,
|
||||
})
|
||||
export class BootstrapModule implements OnModuleInit {
|
||||
constructor(private readonly ensureInitialData: EnsureInitialData) {}
|
||||
constructor(
|
||||
private readonly ensureInitialData: EnsureInitialData,
|
||||
private readonly seedInMemoryRacingData: SeedInMemoryRacingData,
|
||||
) {}
|
||||
|
||||
async onModuleInit() {
|
||||
console.log('[Bootstrap] Initializing application data...');
|
||||
try {
|
||||
await this.ensureInitialData.execute();
|
||||
|
||||
if (this.shouldSeedInMemory()) {
|
||||
await this.seedInMemoryRacingData.execute();
|
||||
}
|
||||
|
||||
console.log('[Bootstrap] Application data initialized successfully');
|
||||
} catch (error) {
|
||||
console.error('[Bootstrap] Failed to initialize application data:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
private shouldSeedInMemory(): boolean {
|
||||
const configured = (process.env.GRIDPILOT_API_PERSISTENCE ?? '').toLowerCase();
|
||||
if (configured) {
|
||||
return configured === 'inmemory';
|
||||
}
|
||||
|
||||
return process.env.DATABASE_URL === undefined;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user