From e52b32d701be1c071a3e7b2b825d8331eb4b6345 Mon Sep 17 00:00:00 2001 From: andrea rota Date: Sun, 10 Mar 2024 11:25:40 +0000 Subject: [PATCH] add stable ids to cost surfaces --- ...710069730000-AddStableIdsToCostSurfaces.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 api/apps/api/src/migrations/api/1710069730000-AddStableIdsToCostSurfaces.ts diff --git a/api/apps/api/src/migrations/api/1710069730000-AddStableIdsToCostSurfaces.ts b/api/apps/api/src/migrations/api/1710069730000-AddStableIdsToCostSurfaces.ts new file mode 100644 index 0000000000..8bd2eff209 --- /dev/null +++ b/api/apps/api/src/migrations/api/1710069730000-AddStableIdsToCostSurfaces.ts @@ -0,0 +1,36 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class AddStableIdsToCostSurfaces1710069730000 + implements MigrationInterface +{ + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` +ALTER TABLE cost_surfaces +ADD COLUMN stable_id uuid; + +CREATE INDEX cost_surfaces_stable_id__idx ON cost_surfaces(stable_id); + +CREATE UNIQUE INDEX cost_surfaces_unique_stable_ids_within_project__idx ON cost_surfaces(project_id, stable_id); + `); + + await queryRunner.query(` +UPDATE cost_surfaces +SET stable_id = id; + `); + + await queryRunner.query(` +ALTER TABLE cost_surfaces +ALTER COLUMN stable_id SET NOT NULL; + +ALTER TABLE cost_surfaces +ALTER COLUMN stable_id SET DEFAULT gen_random_uuid(); + `); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(` +ALTER TABLE cost_surfaces +DROP COLUMN stable_id; + `); + } +}