I have Typeorm loaded asynchronously app.module.ts:
TypeOrmModule.forRootAsync({ inject: [ConfigService], useFactory: getTypeormConfig}), typeorm.config.ts: export const getTypeormConfig = async (config: ConfigService) => ({ type: 'postgres' as const, host: config.get<string>('TYPEORM_HOST'), port: config.get<number>('TYPEORM_PORT'), password: config.get<string>('TYPEORM_PASSWORD'), ....
It seems that the typeORM documentation is outdated, as they say:: https://wanago.io/2022/07/25/api-nestjs-database-migrations-typeorm/
I'm trying to follow this example. Created a separate second configuration for CLI migration typeorm-migration.config.ts at the root of the project:
import { BusinessLog } from 'src/yandex-ndd-api-client/entity/business-log.entity';
import { ClientStatus } from 'src/yandex-ndd-api-client/entity/client-status.entity';
import { Item } from 'src/yandex-ndd-api-client/entity/item.entity'; ...
export default new DataSource({
type: 'postgres' as const,
host: 'postgres', port: 5432, username: 'postgres', database: 'childrensworld',
subscribers: [TruckSubscriber, RequestSubscriber],
entities: [ Request, Item, BusinessLog, Place, ClientStatus, ....
I also wrote in package.json:
"typeorm": "ts-node ./node_modules/typeorm/cli", "typeorm:run-migrations": "npm run typeorm migration:run -- -d ./typeorm-migration.config.ts", "typeorm:generate-migration": "npm run typeorm -- -d ./typeorm-migration.config.ts migration:generate ./migrations/test_migration_name", "typeorm:create-migration": "npm run typeorm -- migration:create ./migrations/test_migration_name", "typeorm:revert-migration": "npm run typeorm -- -d ./typeorm-migration.config.ts migration:revert"
launching npm run typeorm:generate-migration --name=CreatePost as in the example and get:
Error during migration run: Error: Unable to open file: "E:\Programming\Nodejs\..........\typeorm-migration.config.ts". Cannot find module 'src/yandex-ndd-api-client/entity/business-log.entity' Require stack: - E:\Programming\Nodejs\LandPro\сhildsworld\Projects\tests\test_migrationTypeOrm\typeorm-migration.config.ts
As if it cannot read entities from typeorm-migration.config.ts The example says nothing about this. Maybe this config is for CLI migration(typeorm-migration.config.ts)do you need to connect somewhere else?