- Can use import datasource config from another ts file in datasource file?
This my migration script? - Can use
./src/data-source/postgres.ts(typeorm datasource path) that is ts file for run migration?
"migration:generate": "pnpm typeorm migration:generate -d ./src/data-source/postgres.ts",
"migration:create": "pnpm typeorm migration:create",
"migration:run": "pnpm typeorm migration:run -d ./src/data-source/postgres.ts",
"migration:revert": "pnpm typeorm migration:revert -d ./src/data-source/postgres.ts"
data-source/postgres.ts
import { DataSource } from 'typeorm'
import { postgresConfig } from '../config/data-source/postgres'
export default new DataSource(postgresConfig)
config file
import { TypeOrmModuleOptions } from '@nestjs/typeorm'
import { DataSourceOptions } from 'typeorm'
import 'dotenv/config'
export const postgresConfig: TypeOrmModuleOptions & DataSourceOptions = {
type: 'postgres',
name: 'postgres',
host: process.env.POSTGRES_HOST,
port: parseInt(process.env.POSTGRES_PORT, 10) || 5432,
username: process.env.POSTGRES_USERNAME,
password: process.env.POSTGRES_PASSWORD,
database: process.env.POSTGRES_DB,
entities: [__dirname + '/../../entities/postgres/*.entity.ts'],
synchronize: false,
logging: process.env.NODE_ENV !== 'production',
}
Error in comment ↓ ↓ ↓ ↓ ↓ ↓ ↓