-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
api/apps/api/src/migrations/api/1710069730000-AddStableIdsToCostSurfaces.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class AddStableIdsToCostSurfaces1710069730000 | ||
implements MigrationInterface | ||
{ | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
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<void> { | ||
await queryRunner.query(` | ||
ALTER TABLE cost_surfaces | ||
DROP COLUMN stable_id; | ||
`); | ||
} | ||
} |