首页 文章

如何为typeorm指定ormconfig.ts?

提问于
浏览
0

我使用typeorm cli创建了一个示例typeorm项目,默认情况下有ormconfig.json:

{
   "type": "postgres",
   "host": "localhost",
   "port": 5432,
   "username": "postgres",
   "password": "postgres",
   "database": "test",
   "synchronize": false,
   "entities": [
      "src/entity/**/*.ts"
   ],
   "migrations": [
      "database/migrations/**/*.ts"
   ],
   "subscribers": [
      "src/subscriber/**/*.ts"
   ],
   "cli": {
      "entitiesDir": "src/entity",
      "migrationsDir": "database/migrations",
      "subscribersDir": "src/subscriber"
   }
}

这是目录结构:

-database
  -migrations
-src
  -entity
-ormconfig.json

这将在数据库/迁移文件夹中正确创建迁移,并从中执行迁移 .

我用以下ormconfig.ts替换了ormconfig.json:

export default {
    type: 'postgres',
    host: 'localhost',
    port: 5432,
    username: 'postgres',
    password: 'postgres',
    database: 'test',
    synchronize: false,
    "entities": [
        "src/entity/**/*.ts"
    ],
    "migrations": [
         "database/migrations/**/*.ts"
    ],
    "subscribers": [
        "src/subscriber/**/*.ts"
    ],
    "cli": {
        "entitiesDir": "src/entity",
        "migrationsDir": "database/migrations",
        "subscribersDir": "src/subscriber"
    }
};

但是,这会在根目录中而不是在数据库/迁移内部创建迁移 .

任何人都可以帮我弄清楚这里丢失的是什么以及如何使用ormconfig.ts在目标目录中生成迁移?

谢谢!

2 回答

  • 1

    在撰写本文时,TypeORM仅查找 ormconfig.json 并忽略 ormconfig.ts . 虽然有work in progress支持它 .

  • 0

    你为什么不跟随他们的官方documentation?您正在寻找的是 Getting Started 部分 .

相关问题