default db sqlite

This commit is contained in:
Joe Arndt 2026-02-09 23:11:53 -06:00
parent 2ca91b97fb
commit 104b9067c1
4 changed files with 1405 additions and 34 deletions

View file

@ -13,16 +13,26 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
synchronize: configService.get<boolean>('DB_SYNC') ?? true,
type: 'postgres',
host: configService.get<string>('DB_HOST') ?? 'localhost',
port: configService.get<number>('DB_PORT') ?? 5432,
username: configService.get<string>('DB_USER') ?? 'common-cents',
password: configService.get<string>('DB_PASS') ?? 'CommonCents_123!',
database: configService.get<string>('DB_NAME') ?? 'common-cents',
autoLoadEntities: true
})
useFactory: (configService: ConfigService) => {
const type = configService.get<'sqlite' | 'postgres'>('DB_TYPE') ?? 'sqlite';
const synchronize = configService.get<boolean>('DB_SYNC') ?? true;
const autoLoadEntities = true;
const database = type === 'sqlite' ? 'common-cents.db' : 'common-cents';
const defaults = { type, database, synchronize, autoLoadEntities };
if (type === 'postgres') {
return {
...defaults,
host: configService.get<string>('PG_HOST') ?? 'localhost',
port: configService.get<number>('PG_PORT') ?? 5432,
username: configService.get<string>('PG_USER') ?? 'common-cents',
password: configService.get<string>('PG_PASS') ?? 'CommonCents_123!'
};
}
return defaults;
}
}),
MerchantsModule,
TagsModule,