chore: configure angular and postgres foundation
This commit is contained in:
16
apps/api/src/database/data-source.ts
Normal file
16
apps/api/src/database/data-source.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import 'dotenv/config';
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
const databaseUrl = process.env.DATABASE_URL;
|
||||
|
||||
if (!databaseUrl?.trim()) {
|
||||
throw new Error('DATABASE_URL is required');
|
||||
}
|
||||
|
||||
export const AppDataSource = new DataSource({
|
||||
type: 'postgres',
|
||||
url: databaseUrl,
|
||||
entities: [__dirname + '/../**/*.entity.{ts,js}'],
|
||||
migrations: [__dirname + '/migrations/*.{ts,js}'],
|
||||
synchronize: false,
|
||||
});
|
||||
12
apps/api/src/database/database.module.ts
Normal file
12
apps/api/src/database/database.module.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { createDatabaseConfig } from '../config/database.config';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forRootAsync({
|
||||
useFactory: () => createDatabaseConfig(process.env.DATABASE_URL ?? ''),
|
||||
}),
|
||||
],
|
||||
})
|
||||
export class DatabaseModule {}
|
||||
Reference in New Issue
Block a user