Skip to content

Commit

Permalink
add stable ids to cost surfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
hotzevzl committed Mar 11, 2024
1 parent fbb9532 commit e52b32d
Showing 1 changed file with 36 additions and 0 deletions.
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;
`);
}
}

0 comments on commit e52b32d

Please sign in to comment.