diff --git a/api/ormconfig.ts b/api/ormconfig.ts index c4d8d9f6ab4d251e3de02e035a54e01ca6d2cf26..adf2b5ede0315c246c886d10dc84e484dcf084f9 100644 --- a/api/ormconfig.ts +++ b/api/ormconfig.ts @@ -1,4 +1,5 @@ import { ConfigModule } from '@nestjs/config'; +import { DataSource } from 'typeorm'; import dbConfiguration from './src/config/db.config'; ConfigModule.forRoot({ @@ -12,9 +13,10 @@ const ormconfig = { entities: ['dist/**/*.entity.js', 'dist/**/*.model.js'], migrations: ['dist/migrations/*{.ts,.js}'], migrationsRun: false, - cli: { - migrationsDir: 'src/migrations', - }, }; -export default ormconfig; +const connSource = new DataSource(ormconfig); + +connSource.initialize(); + +export default connSource; diff --git a/api/package.json b/api/package.json index 9675ece59f68120ef56133a481f961e6c3e5d6cc..f7fc1f21d53ec8b06442ff9dc4da89dced718ff6 100644 --- a/api/package.json +++ b/api/package.json @@ -22,8 +22,8 @@ "test:we2e": "jest --watch --config ./test/jest.e2e-config.ts", "prepare": "cd .. && husky install api/.husky", "typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js", - "typeorm:migration:generate": "npm run typeorm -- migration:generate -n", - "typeorm:migration:run": "npm run typeorm -- migration:run" + "typeorm:migration:generate": "npm run typeorm -- migration:generate -d ormconfig.ts", + "typeorm:migration:run": "npm run typeorm -- migration:run -d ormconfig.ts" }, "dependencies": { "@nestjs/apollo": "^10.0.22", diff --git a/api/src/config/db.config.ts b/api/src/config/db.config.ts index 346dbffe42c0724fe8cf6aa15b6376bab4113c87..5203c3fc692e7c73281bad5285f41b9d95d72636 100644 --- a/api/src/config/db.config.ts +++ b/api/src/config/db.config.ts @@ -1,6 +1,7 @@ import { registerAs } from '@nestjs/config'; +import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions'; -export default registerAs('database', () => { +export default registerAs('database', (): PostgresConnectionOptions => { return { type: 'postgres', host: process.env.DB_HOST || 'localhost', @@ -8,5 +9,6 @@ export default registerAs('database', () => { username: process.env.DB_USERNAME || 'postgres', password: process.env.DB_PASSWORD || 'pass123', database: process.env.DB_NAME || 'postgres', + synchronize: process.env.NODE_ENV === 'development', }; });