From c789438c627f723a0564ddd6092a551d1f3db2c9 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Wed, 2 Oct 2024 19:52:32 +0100 Subject: [PATCH] add migration script for table views --- ...nName.ts => 1727894983857-MigrationName.ts} | 18 +++++++++++++++--- .../Postgres/SchemaMigrations/Index.ts | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) rename Common/Server/Infrastructure/Postgres/SchemaMigrations/{1727877987596-MigrationName.ts => 1727894983857-MigrationName.ts} (60%) diff --git a/Common/Server/Infrastructure/Postgres/SchemaMigrations/1727877987596-MigrationName.ts b/Common/Server/Infrastructure/Postgres/SchemaMigrations/1727894983857-MigrationName.ts similarity index 60% rename from Common/Server/Infrastructure/Postgres/SchemaMigrations/1727877987596-MigrationName.ts rename to Common/Server/Infrastructure/Postgres/SchemaMigrations/1727894983857-MigrationName.ts index f062ce79a8..62e14fa33d 100644 --- a/Common/Server/Infrastructure/Postgres/SchemaMigrations/1727877987596-MigrationName.ts +++ b/Common/Server/Infrastructure/Postgres/SchemaMigrations/1727894983857-MigrationName.ts @@ -1,15 +1,21 @@ import { MigrationInterface, QueryRunner } from "typeorm"; -export class MigrationName1727877987596 implements MigrationInterface { - public name = "MigrationName1727877987596"; +export class MigrationName1727894983857 implements MigrationInterface { + public name = "MigrationName1727894983857"; public async up(queryRunner: QueryRunner): Promise { await queryRunner.query( - `CREATE TABLE "TableView" ("_id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP WITH TIME ZONE, "version" integer NOT NULL, "projectId" uuid NOT NULL, "name" character varying(100) NOT NULL, "tableId" character varying(100) NOT NULL, "description" character varying(500), "createdByUserId" uuid, "deletedByUserId" uuid, "filters" jsonb NOT NULL, "sort" jsonb NOT NULL, "itemsOnPage" integer NOT NULL DEFAULT '10', CONSTRAINT "PK_1e17a8834a65403cc87c4ead0cc" PRIMARY KEY ("_id"))`, + `CREATE TABLE "TableView" ("_id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP WITH TIME ZONE, "version" integer NOT NULL, "projectId" uuid NOT NULL, "name" character varying(100) NOT NULL, "tableId" character varying(100) NOT NULL, "description" character varying(500), "createdByUserId" uuid, "deletedByUserId" uuid, "query" jsonb NOT NULL, "sort" jsonb NOT NULL, "itemsOnPage" integer NOT NULL DEFAULT '10', CONSTRAINT "PK_1e17a8834a65403cc87c4ead0cc" PRIMARY KEY ("_id"))`, ); await queryRunner.query( `CREATE INDEX "IDX_a8691d4e023d907b5c73a43e42" ON "TableView" ("projectId") `, ); + await queryRunner.query( + `ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "rotation" SET DEFAULT '{"_type":"Recurring","value":{"intervalType":"Day","intervalCount":{"_type":"PositiveNumber","value":1}}}'`, + ); + await queryRunner.query( + `ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "restrictionTimes" SET DEFAULT '{"_type":"RestrictionTimes","value":{"restictionType":"None","dayRestrictionTimes":null,"weeklyRestrictionTimes":[]}}'`, + ); await queryRunner.query( `ALTER TABLE "TableView" ADD CONSTRAINT "FK_a8691d4e023d907b5c73a43e424" FOREIGN KEY ("projectId") REFERENCES "Project"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`, ); @@ -31,6 +37,12 @@ export class MigrationName1727877987596 implements MigrationInterface { await queryRunner.query( `ALTER TABLE "TableView" DROP CONSTRAINT "FK_a8691d4e023d907b5c73a43e424"`, ); + await queryRunner.query( + `ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "restrictionTimes" SET DEFAULT '{"_type": "RestrictionTimes", "value": {"restictionType": "None", "dayRestrictionTimes": null, "weeklyRestrictionTimes": []}}'`, + ); + await queryRunner.query( + `ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "rotation" SET DEFAULT '{"_type": "Recurring", "value": {"intervalType": "Day", "intervalCount": {"_type": "PositiveNumber", "value": 1}}}'`, + ); await queryRunner.query( `DROP INDEX "public"."IDX_a8691d4e023d907b5c73a43e42"`, ); diff --git a/Common/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts b/Common/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts index cba03af524..43ca20569b 100644 --- a/Common/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +++ b/Common/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts @@ -71,6 +71,7 @@ import { MigrationName1727193130193 } from "./1727193130193-MigrationName"; import { MigrationName1727193702212 } from "./1727193702212-MigrationName"; import { MigrationName1727194211048 } from "./1727194211048-MigrationName"; import { MigrationName1727194579925 } from "./1727194579925-MigrationName"; +import { MigrationName1727894983857 } from "./1727894983857-MigrationName"; export default [ InitialMigration, @@ -146,4 +147,5 @@ export default [ MigrationName1727193702212, MigrationName1727194211048, MigrationName1727194579925, + MigrationName1727894983857, ];