From b0f398a314a6ab74c38e0dfee6c5378b7e10c31d Mon Sep 17 00:00:00 2001 From: Morgan Ludtke Date: Thu, 19 Oct 2023 10:42:37 -0500 Subject: [PATCH] fix: add migration to add listing approval permissions --- .../1697654611220-turn-on-listing-approval.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 backend/core/src/migration/1697654611220-turn-on-listing-approval.ts diff --git a/backend/core/src/migration/1697654611220-turn-on-listing-approval.ts b/backend/core/src/migration/1697654611220-turn-on-listing-approval.ts new file mode 100644 index 0000000000..3eda9139f6 --- /dev/null +++ b/backend/core/src/migration/1697654611220-turn-on-listing-approval.ts @@ -0,0 +1,29 @@ +import { MigrationInterface, QueryRunner } from "typeorm" +import { EnumJurisdictionListingApprovalPermissions } from "../../types" + +export class turnOnListingApproval1697654611220 implements MigrationInterface { + name = "turnOnListingApproval1697654611220" + + public async up(queryRunner: QueryRunner): Promise { + const jurisdictions: { id: string }[] = await queryRunner.query(` + SELECT id + FROM jurisdictions + `) + + const approvalPermissions = [ + EnumJurisdictionListingApprovalPermissions.admin, + ].map((permission) => `'${permission}'::jurisdictions_listing_approval_permissions_enum`) + + jurisdictions.forEach(async (jurisdictionId) => { + await queryRunner.query(` + UPDATE jurisdictions + SET listing_approval_permissions = ARRAY [${approvalPermissions}] + WHERE id = '${jurisdictionId.id}' + `) + }) + } + + public async down(queryRunner: QueryRunner): Promise { + // no down migration + } +}