From ee255eda473ed20121dbaa5ec260fe86620bcf88 Mon Sep 17 00:00:00 2001 From: Vasyl Ivanchuk Date: Tue, 14 Nov 2023 11:58:52 +0200 Subject: [PATCH] fix: add DB migration for empty block transfers --- ...8-SetTransferTypeForEmptyBlockTransfers.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 packages/worker/src/migrations/1699955766418-SetTransferTypeForEmptyBlockTransfers.ts diff --git a/packages/worker/src/migrations/1699955766418-SetTransferTypeForEmptyBlockTransfers.ts b/packages/worker/src/migrations/1699955766418-SetTransferTypeForEmptyBlockTransfers.ts new file mode 100644 index 0000000000..6cd28af03b --- /dev/null +++ b/packages/worker/src/migrations/1699955766418-SetTransferTypeForEmptyBlockTransfers.ts @@ -0,0 +1,22 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class SetTransferTypeForEmptyBlockTransfers1699955766418 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + WITH "updatedTransferNumbers" AS + ( + UPDATE transfers + SET "type" = 'transfer', "isFeeOrRefund" = false, "isInternal" = true, "updatedAt" = CURRENT_TIMESTAMP + WHERE "transactionHash" IS NULL AND "isInternal" = false + RETURNING number + ) + UPDATE "addressTransfers" + SET "isFeeOrRefund" = false, "isInternal" = true, "updatedAt" = CURRENT_TIMESTAMP + FROM "updatedTransferNumbers" + WHERE "transferNumber" = "updatedTransferNumbers"."number" + `); + } + + // eslint-disable-next-line @typescript-eslint/no-empty-function + public async down(): Promise {} +}