node.js - 类型ORM : "No migrations pending" on windows 11

标签 node.js postgresql nestjs windows-11 nestjs-typeorm

我有一个 nestjs 应用程序,其中使用 typeormPostgreSQL 。这个应用程序在 Linux/Mac 操作系统上运行良好。但是在Windows 11中,在迁移表上找不到数据,这就是为什么在PostgreSQL数据库上没有创建表的原因。当我运行 npm run start:dev 时,它在终端上显示以下消息:

$ npm run start:dev
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3d4e584f4b545e587d0c130d130d" rel="noreferrer noopener nofollow">[email protected]</a> start:dev
> nest start --watch --preserveWatchOutput

[2:00:24 PM] Starting compilation in watch mode...

[2:01:01 PM] Found 0 errors. Watching for file changes.

.......................................................................................
.......................................................................................

{"level":30,"ctx":"InstanceLoader","msg":"AppModule dependencies initialized"}
{"level":30,"ctx":"DBLogger","query":"SELECT * FROM current_schema()"}
{"level":30,"ctx":"DBLogger","msg":"No classes were found using the provided glob pattern:  \"dist/src/server/migration/*{.ts,.js}\""}
{"level":30,"ctx":"DBLogger","query":"CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\""}
{"level":30,"ctx":"DBLogger","query":"SELECT version();"}
{"level":30,"ctx":"DBLogger","query":"SELECT * FROM \"information_schema\".\"tables\" WHERE \"table_schema\" = 'public' AND \"table_name\" = 'migrations'"}
{"level":30,"ctx":"DBLogger","query":"SELECT * FROM \"migrations\" \"migrations\" ORDER BY \"id\" DESC","parameters":[]}
{"level":30,"ctx":"DBLogger","msg":"No migrations are pending"}
{"level":30,"ctx":"InstanceLoader","msg":"TypeOrmCoreModule dependencies initialized"}

.......................................................................................
.......................................................................................

{"level":30,"ctx":"NestApplication","msg":"Nest application successfully started"}

我通过运行npm run build进行构建。然后运行npm run typeorm --migration:run

npm run typeorm -- migration:run
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c2b1a7b0b4aba1a782f3ecf2ecf2" rel="noreferrer noopener nofollow">[email protected]</a> typeorm
> typeorm-ts-node-esm -d ./ormconfig.ts "migration:run"

query: SELECT * FROM current_schema()
query: SELECT version();
query: SELECT * FROM "information_schema"."tables" WHERE "table_schema" = 'public' AND "table_name" = 'migrations'
query: SELECT * FROM "migrations" "migrations" ORDER BY "id" DESC
No migrations are pending

ormconfig.ts代码:

import * as dotenv from 'dotenv';
import { DataSource } from 'typeorm';

dotenv.config();

const connection = new DataSource({
  type: 'postgres' as const,
  host: 'localhost',
  port: 5432,
  username: 'postgres',
  password: 'mango',
  database: 'loyalty',
  entities: ['src/server/entity/*.{ts,js}'],
  migrations: ['src/server/migration/*.{ts,js}'],
  extra: {
    ssl: false,
  },
});

export default connection;

app.module.ts

@Module({
    imports: [
        TypeOrmModule.forRootAsync({
          imports: [ConfigModule],
          inject: [ConfigService],
          useFactory: (configService: ConfigService) => {
            return {
              type: 'postgres',
              entities: [],
              synchronize: false,
              migrations: ['dist/src/server/migration/*{.ts,.js}'],
              migrationsTableName: 'migrations',
              migrationsRun: true,
            };
          },
        }),
    ],
    controllers: [],
    providers: [],
})
export class AppModule {
    constructor(private connection: Connection) {}
}

文件结构:

project
|--------> dist
              |--------> src
                         |--------> server
                                         |---------> migration
|--------> src
     |--------> server
                     |---------> migration

任何建议都将受到高度赞赏。提前致谢。

更新:我也在 Docker 容器内运行这个项目,但仍然存在同样的问题。

最佳答案

解决方案:https://github.com/typeorm/typeorm/issues/9766

看来glob来自<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e6929f968389948ba6d6c8d5c8d7d4" rel="noreferrer noopener nofollow">[email protected]</a>的依赖无法在 Windows 上正常工作。

关于node.js - 类型ORM : "No migrations pending" on windows 11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75542306/

相关文章:

postgresql - 在 PostgreSQL 中使用 "Cursors"进行分页

mysql - NestJs TypeORM 无法连接到 mysql

javascript - 使用工厂创建 Controller

node.js - 在 "everything has been done"之后退出 node.js 脚本的好方法是什么

node.js - 我正在尝试将 phoenix 应用程序部署到 heroku 但出现 NPM 错误

php - pg_execute 和 pg_query 之间的区别

node.js - NodeJs 构建 Excel 文件并导出为 PDF

django - docker 中主机的 localhost 和 postgres 之间的区别

typescript - 我的类验证器如何验证联合字符串 |数字?

typescript - NestJs CQRS - 与现有的 TypeORM 实体聚合设置