import { MigrationInterface, QueryRunner } from 'typeorm'; export class F69ConsolidatedDocumentRevisions1790135400000 implements MigrationInterface { name = 'F69ConsolidatedDocumentRevisions1790135400000'; public async up(queryRunner: QueryRunner): Promise { await queryRunner.query(` CREATE TABLE inspection_act_consolidated_pdf_revisions ( act_id uuid NOT NULL REFERENCES inspection_acts(id) ON DELETE CASCADE, template_version smallint NOT NULL CHECK (template_version >= 1), stored_name varchar(255) NOT NULL, original_name varchar(255) NOT NULL, size_bytes integer NOT NULL CHECK (size_bytes > 0), sha256 char(64) NOT NULL CHECK (sha256 ~ '^[0-9a-f]{64}$'), generated_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (act_id,template_version) ) `); await queryRunner.query(` INSERT INTO inspection_act_consolidated_pdf_revisions( act_id,template_version,stored_name,original_name,size_bytes,sha256,generated_at) SELECT act_id,1,stored_name,original_name,size_bytes,sha256,generated_at FROM inspection_act_consolidated_pdf_artifacts `); await queryRunner.query(` CREATE TABLE inspection_report_consolidated_word_revisions ( report_id uuid NOT NULL REFERENCES inspection_reports(id) ON DELETE CASCADE, template_version smallint NOT NULL CHECK (template_version >= 1), stored_name varchar(255) NOT NULL, original_name varchar(255) NOT NULL, size_bytes integer NOT NULL CHECK (size_bytes > 0), sha256 char(64) NOT NULL CHECK (sha256 ~ '^[0-9a-f]{64}$'), generated_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (report_id,template_version) ) `); await queryRunner.query(` INSERT INTO inspection_report_consolidated_word_revisions( report_id,template_version,stored_name,original_name,size_bytes,sha256,generated_at) SELECT report_id,1,stored_name,original_name,size_bytes,sha256,generated_at FROM inspection_report_consolidated_word_artifacts `); } public async down(queryRunner: QueryRunner): Promise { await queryRunner.query('DROP TABLE inspection_report_consolidated_word_revisions'); await queryRunner.query('DROP TABLE inspection_act_consolidated_pdf_revisions'); } }