最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Running the dataSource.initialize() launches typeorm cli immediately - Stack Overflow

programmeradmin4浏览0评论

I tried to run the migrations directly from the code in runtime, but when the datasource is initialized, the cli typeorm is immediately launched.

typeorm ver. 0.3.2
nodejs ver. v22.13.1
ts-node ver. v10.9.2
typescript ver. 5.8.2

Code:

import { DataSource } from 'typeorm'

const dataSource = new DataSource({
  type: 'postgres',
  host: '...',
  port: 5432,
  username: '...',
  password: '...',
  database: '...',
  migrationsTableName: '...',
  migrationsRun: false,
  synchronize: false,
  migrations: ['../migrations/**/*.js'],
})

dataSource.initialize()

Result:

$ npx ts-node src/test.ts
Usage: bin.js <command> [options]

Commands:
  bin.js schema:sync                Synchronizes your entities with database
                                    schema. It runs schema update queries on all
                                    connections you have. To run update queries
                                    on a concrete connection use -c option.
  bin.js schema:log                 Shows sql to be executed by schema:sync

...
...
...

If you remove the line with the path to migrations, cli does not start. Tried to run compiled js but the same thing happens.

发布评论

评论列表(0)

  1. 暂无评论