繁体   English   中英

TypeORM 0.3.6 错误在运行迁移时处理原始 SQL

[英]TypeORM 0.3.6 errs processing raw SQL while running migrations

我正在使用下面的代码,它与typeorm 0.2.x一起工作得很好。 我正在尝试将我的软件包升级到0.3.6 问题可能是特定于 Mac 的。 然而,我不确定。

脚本如下:

import { MigrationInterface, QueryRunner } from 'typeorm';
export class CleanSlate1654889719399 implements MigrationInterface {
  name = 'CleanSlate1654889719399';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query('IF EXISTS DROP TABLE "onetime_viewer_token" CASCADE');
    ...
    await queryRunner.query(`CREATE TABLE IF NOT EXISTS "client_society_user" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "email" text NOT NULL, "tokenVersion" integer NOT NULL DEFAULT '0', "created_at" TIMESTAMP NOT NULL DEFAULT now(), "updated_at" TIMESTAMP NOT NULL DEFAULT now(), "role" "public"."client_society_user_role_enum" NOT NULL, "isInternalAdmin" boolean NOT NULL DEFAULT false, "clientId" uuid, CONSTRAINT "PK_599c2dd9d3dc21c54f7df5d9c7e" PRIMARY KEY ("id"))`);
    ...
    await queryRunner.query(`ALTER TABLE "client_user" ADD CONSTRAINT "FK_eb3e491fab0ea63cd9f9ffba47d" FOREIGN KEY ("clientId") REFERENCES "client"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`ALTER TABLE "discord_role" DROP CONSTRAINT "FK_cc3204010e82bba2a8cdafb30fc"`);
    await queryRunner.query(`IF EXISTS DROP TABLE "onetime_transfer_token"`);
    ...
    await queryRunner.query(`IF EXISTS DROP TABLE "temp_token"`);
  }
}

当我尝试使用 typeorm 0.3.x 运行此迁移时,它会导致错误: error: syntax error at or near "IF"

仍然可以将QueryRunner与原始 SQL 一起使用吗? MigrationInterface仅支持QueryRunner ...

请指教。

以下使用typeorm 0.3.6 可以正常工作 [在 Mac 和 Linux 上]:

await queryRunner.manager.query(...)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM