Skip to content
Snippets Groups Projects
ormconfig.ts 834 B
Newer Older
  • Learn to ignore specific revisions
  • Sébastien DA ROCHA's avatar
    Sébastien DA ROCHA committed
    // tslint:disable-next-line:no-var-requires
    const dotenv = require('dotenv');
    // tslint:disable-next-line:no-var-requires
    const fs = require('fs');
    
    let root = 'src';
    
    // For prod build, the files are in a dist folder
    if (process.env.PRODBUILD) {
      root = 'dist';
    }
    
    const ormConfig = {
      type: 'postgres',
      host: process.env.POSTGRES_HOST,
      port: process.env.POSTGRES_PORT,
      username: process.env.MIGRATING === '1' ? 'postgres' : process.env.POSTGRES_USER,
      password: process.env.MIGRATING === '1' ? process.env.POSTGRES_ADMIN_PASSWORD : process.env.POSTGRES_PASSWORD,
      database: process.env.POSTGRES_DB,
      entities: [`${root}/**/**.entity{.ts,.js}`],
      synchronize: false,
      migrations: [`${root}/migrations/*.ts`],
      cli: { migrationsDir: `${root}/migrations` },
      logging: [
        'error',
      ],
    };
    
    module.exports = ormConfig;