#Migrations ready for development & production environment

2 messages · Page 1 of 1 (latest)

subtle wind
#

Hello guys, by following NestJS docs and TypeOrm docs i was able to connect my project with a Database, generate the data source file and make everything work as expected in development mode (npm run start:dev).
My question now is, how could i make it so it properly works for both dev and prod environments? i have questions such as...

  • Why does .dist folder after npm run build includes .ts files
  • Should i have my migrations in/outside src folder.
  • Should my data-source.ts file (code below) define different directory names based on the NODE_ENV var?
// data-source.ts 
import 'reflect-metadata';
import 'dotenv/config';
import { DataSource } from 'typeorm';
import { join } from 'path';
///////////////////////////////////////////////////////
// ONLY USED FOR TYPEORM MIGRATIONS
///////////////////////////////////////////////////////
export const AppDataSource = new DataSource({
  type: 'postgres',
  host: process.env.DB_HOST,
  port: Number(process.env.DB_PORT),
  username: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,

  entities: [join(__dirname, '**', 'entities', '*.entity.{ts,js}')],
  migrations: [join(__dirname, '**', 'migrations', '*.{ts,js}')],

  synchronize: false,

  migrationsRun: false,
  migrationsTableName: 'migrations',
  migrationsTransactionMode: 'all',
});

I Tried to find examples of this, but haven't found it yet. Thanks!

mortal river
#
  1. this could be source files?
  2. Doest really matter, Migration just needs to know where the migration files are. convention is to but it outside.
    3.Yes you can define what ever you want for the folder path or name in your env variable