From cbab83993587c7c2978b60e13f5685160a40e888 Mon Sep 17 00:00:00 2001 From: enlineawork Date: Mon, 7 Sep 2026 19:39:43 -0300 Subject: [PATCH] =?UTF-8?q?F4.0=20foundation=20=C2=B7=20urgencia,=20GEDO?= =?UTF-8?q?=20y=20seguimiento?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entities/inspection-act.entity.ts | 51 ++++ .../inspection-deadline-policy.entity.ts | 25 ++ .../entities/inspection-finding.entity.ts | 7 + .../inspection-non-working-day.entity.ts | 20 ++ ...inspection-report-follow-up-file.entity.ts | 30 ++ .../inspection-report-follow-up.entity.ts | 36 +++ .../entities/inspection-report.entity.ts | 52 ++++ ...00000-phase-f4-document-flow-foundation.ts | 263 ++++++++++++++++++ 8 files changed, 484 insertions(+) create mode 100644 api-v3/src/database/entities/inspection-deadline-policy.entity.ts create mode 100644 api-v3/src/database/entities/inspection-non-working-day.entity.ts create mode 100644 api-v3/src/database/entities/inspection-report-follow-up-file.entity.ts create mode 100644 api-v3/src/database/entities/inspection-report-follow-up.entity.ts create mode 100644 api-v3/src/database/migrations/1790035200000-phase-f4-document-flow-foundation.ts diff --git a/api-v3/src/database/entities/inspection-act.entity.ts b/api-v3/src/database/entities/inspection-act.entity.ts index d7e57be..189c90b 100644 --- a/api-v3/src/database/entities/inspection-act.entity.ts +++ b/api-v3/src/database/entities/inspection-act.entity.ts @@ -9,6 +9,21 @@ export enum InspectionActStatus { RECTIFIED = 'RECTIFIED', } +export enum InspectionActUrgency { + URGENT = 'URGENT', + NON_URGENT = 'NON_URGENT', +} + +export enum InspectionDeadlineDayType { + BUSINESS = 'BUSINESS', + CALENDAR = 'CALENDAR', +} + +export enum InspectionDeadlineBasis { + ACT_DATE = 'ACT_DATE', + GEDO_LOAD_DATE = 'GEDO_LOAD_DATE', +} + @Entity({ name: 'inspection_acts' }) @Index('uq_inspection_acts_one_draft_per_visit', ['visitId'], { unique: true, where: "status = 'DRAFT'" }) @Index('uq_inspection_acts_year_number', ['actYear', 'actNumber'], { unique: true }) @@ -47,6 +62,42 @@ export class InspectionAct extends TimestampedEntity { @Column({ type: 'text', nullable: true }) observations!: string | null; + @Column({ type: 'varchar', length: 20, nullable: true }) + urgency!: InspectionActUrgency | null; + + @Column({ name: 'deadline_days', type: 'integer', nullable: true }) + deadlineDays!: number | null; + + @Column({ name: 'deadline_day_type', type: 'varchar', length: 20, nullable: true }) + deadlineDayType!: InspectionDeadlineDayType | null; + + @Column({ name: 'deadline_basis', type: 'varchar', length: 24, nullable: true }) + deadlineBasis!: InspectionDeadlineBasis | null; + + @Column({ name: 'deadline_base_on', type: 'date', nullable: true }) + deadlineBaseOn!: string | null; + + @Column({ name: 'deadline_due_on', type: 'date', nullable: true }) + deadlineDueOn!: string | null; + + @Column({ name: 'deadline_policy_snapshot', type: 'jsonb', nullable: true }) + deadlinePolicySnapshot!: Record | null; + + @Column({ name: 'locked_at', type: 'timestamptz', nullable: true }) + lockedAt!: Date | null; + + @Column({ name: 'locked_by', type: 'uuid', nullable: true }) + lockedBy!: string | null; + + @Column({ name: 'locked_sha256', type: 'char', length: 64, nullable: true }) + lockedSha256!: string | null; + + @Column({ name: 'sealed_at', type: 'timestamptz', nullable: true }) + sealedAt!: Date | null; + + @Column({ name: 'sealed_by', type: 'uuid', nullable: true }) + sealedBy!: string | null; + @Column({ name: 'current_version', type: 'integer', default: 0 }) currentVersion!: number; diff --git a/api-v3/src/database/entities/inspection-deadline-policy.entity.ts b/api-v3/src/database/entities/inspection-deadline-policy.entity.ts new file mode 100644 index 0000000..5b55001 --- /dev/null +++ b/api-v3/src/database/entities/inspection-deadline-policy.entity.ts @@ -0,0 +1,25 @@ +import { Column, Entity, PrimaryColumn } from 'typeorm'; +import { TimestampedEntity } from './timestamped.entity'; +import { + InspectionActUrgency, + InspectionDeadlineBasis, + InspectionDeadlineDayType, +} from './inspection-act.entity'; + +@Entity({ name: 'inspection_deadline_policies' }) +export class InspectionDeadlinePolicy extends TimestampedEntity { + @PrimaryColumn({ type: 'varchar', length: 20 }) + urgency!: InspectionActUrgency; + + @Column({ type: 'integer' }) + days!: number; + + @Column({ name: 'day_type', type: 'varchar', length: 20 }) + dayType!: InspectionDeadlineDayType; + + @Column({ type: 'varchar', length: 24 }) + basis!: InspectionDeadlineBasis; + + @Column({ name: 'updated_by', type: 'uuid', nullable: true }) + updatedBy!: string | null; +} diff --git a/api-v3/src/database/entities/inspection-finding.entity.ts b/api-v3/src/database/entities/inspection-finding.entity.ts index e1f5a69..f9f5cb8 100644 --- a/api-v3/src/database/entities/inspection-finding.entity.ts +++ b/api-v3/src/database/entities/inspection-finding.entity.ts @@ -18,6 +18,7 @@ export enum InspectionFindingStatus { @Index('idx_inspection_findings_status_control', ['status', 'nextControlOn']) @Index('idx_inspection_findings_asset_status', ['assetId', 'status']) @Index('idx_inspection_findings_catalog_item', ['catalogItemId']) +@Index('idx_inspection_findings_antecedent', ['antecedentFindingId']) export class InspectionFinding extends TimestampedEntity { @PrimaryGeneratedColumn('uuid') id!: string; @@ -61,6 +62,12 @@ export class InspectionFinding extends TimestampedEntity { @Column({ type: 'smallint', nullable: true }) severity!: number | null; + @Column({ name: 'is_recurrence', type: 'boolean', default: false }) + isRecurrence!: boolean; + + @Column({ name: 'antecedent_finding_id', type: 'uuid', nullable: true }) + antecedentFindingId!: string | null; + @Column({ name: 'correction_due_on', type: 'date', nullable: true }) correctionDueOn!: string | null; diff --git a/api-v3/src/database/entities/inspection-non-working-day.entity.ts b/api-v3/src/database/entities/inspection-non-working-day.entity.ts new file mode 100644 index 0000000..e992fb8 --- /dev/null +++ b/api-v3/src/database/entities/inspection-non-working-day.entity.ts @@ -0,0 +1,20 @@ +import { Column, Entity, PrimaryColumn } from 'typeorm'; +import { TimestampedEntity } from './timestamped.entity'; + +@Entity({ name: 'inspection_non_working_days' }) +export class InspectionNonWorkingDay extends TimestampedEntity { + @PrimaryColumn({ type: 'date' }) + day!: string; + + @Column({ type: 'varchar', length: 200 }) + label!: string; + + @Column({ type: 'boolean', default: true }) + enabled!: boolean; + + @Column({ name: 'created_by', type: 'uuid', nullable: true }) + createdBy!: string | null; + + @Column({ name: 'updated_by', type: 'uuid', nullable: true }) + updatedBy!: string | null; +} diff --git a/api-v3/src/database/entities/inspection-report-follow-up-file.entity.ts b/api-v3/src/database/entities/inspection-report-follow-up-file.entity.ts new file mode 100644 index 0000000..397721d --- /dev/null +++ b/api-v3/src/database/entities/inspection-report-follow-up-file.entity.ts @@ -0,0 +1,30 @@ +import { Column, Entity, Index, PrimaryGeneratedColumn } from 'typeorm'; +import { TimestampedEntity } from './timestamped.entity'; + +@Entity({ name: 'inspection_report_follow_up_files' }) +@Index('idx_inspection_report_follow_up_files_follow_up', ['followUpId']) +export class InspectionReportFollowUpFile extends TimestampedEntity { + @PrimaryGeneratedColumn('uuid') + id!: string; + + @Column({ name: 'follow_up_id', type: 'uuid' }) + followUpId!: string; + + @Column({ name: 'original_name', type: 'varchar', length: 255 }) + originalName!: string; + + @Column({ name: 'stored_name', type: 'varchar', length: 255 }) + storedName!: string; + + @Column({ name: 'mime_type', type: 'varchar', length: 120 }) + mimeType!: string; + + @Column({ name: 'size_bytes', type: 'integer' }) + sizeBytes!: number; + + @Column({ type: 'char', length: 64 }) + sha256!: string; + + @Column({ name: 'created_by', type: 'uuid', nullable: true }) + createdBy!: string | null; +} diff --git a/api-v3/src/database/entities/inspection-report-follow-up.entity.ts b/api-v3/src/database/entities/inspection-report-follow-up.entity.ts new file mode 100644 index 0000000..6f7996d --- /dev/null +++ b/api-v3/src/database/entities/inspection-report-follow-up.entity.ts @@ -0,0 +1,36 @@ +import { Column, Entity, Index, PrimaryGeneratedColumn } from 'typeorm'; +import { TimestampedEntity } from './timestamped.entity'; + +export enum InspectionReportFollowUpType { + COMPANY_NOTE = 'COMPANY_NOTE', + COMPANY_DOCUMENT = 'COMPANY_DOCUMENT', + INTERNAL_NOTE = 'INTERNAL_NOTE', + VERIFICATION = 'VERIFICATION', + OTHER = 'OTHER', +} + +@Entity({ name: 'inspection_report_follow_ups' }) +@Index('idx_inspection_report_follow_ups_report_occurred', ['reportId', 'occurredOn']) +@Index('idx_inspection_report_follow_ups_type', ['eventType']) +export class InspectionReportFollowUp extends TimestampedEntity { + @PrimaryGeneratedColumn('uuid') + id!: string; + + @Column({ name: 'report_id', type: 'uuid' }) + reportId!: string; + + @Column({ name: 'event_type', type: 'varchar', length: 32 }) + eventType!: InspectionReportFollowUpType; + + @Column({ name: 'reference_number', type: 'varchar', length: 255, nullable: true }) + referenceNumber!: string | null; + + @Column({ name: 'occurred_on', type: 'date' }) + occurredOn!: string; + + @Column({ type: 'text', nullable: true }) + description!: string | null; + + @Column({ name: 'created_by', type: 'uuid', nullable: true }) + createdBy!: string | null; +} diff --git a/api-v3/src/database/entities/inspection-report.entity.ts b/api-v3/src/database/entities/inspection-report.entity.ts index 77c4291..3e1d6b6 100644 --- a/api-v3/src/database/entities/inspection-report.entity.ts +++ b/api-v3/src/database/entities/inspection-report.entity.ts @@ -31,6 +31,7 @@ export enum InspectionReportReviewStatus { @Index('uq_inspection_reports_code', ['code'], { unique: true }) @Index('idx_inspection_reports_generated_at', ['generatedAt']) @Index('idx_inspection_reports_status', ['status', 'pdfStatus']) +@Index('idx_inspection_reports_gedo_if_identifier', ['gedoIfIdentifier']) export class InspectionReport extends TimestampedEntity { @PrimaryGeneratedColumn('uuid') id!: string; @@ -80,6 +81,57 @@ export class InspectionReport extends TimestampedEntity { @Column({ name: 'word_error', type: 'varchar', length: 500, nullable: true }) wordError!: string | null; + @Column({ name: 'reference_text', type: 'text', nullable: true }) + referenceText!: string | null; + + @Column({ name: 'general_objective', type: 'text', nullable: true }) + generalObjective!: string | null; + + @Column({ name: 'specific_objective', type: 'text', nullable: true }) + specificObjective!: string | null; + + @Column({ type: 'text', nullable: true }) + background!: string | null; + + @Column({ name: 'legal_framework', type: 'text', nullable: true }) + legalFramework!: string | null; + + @Column({ name: 'executive_summary', type: 'text', nullable: true }) + executiveSummary!: string | null; + + @Column({ type: 'text', nullable: true }) + description!: string | null; + + @Column({ type: 'text', nullable: true }) + conclusion!: string | null; + + @Column({ name: 'gedo_if_identifier', type: 'varchar', length: 255, nullable: true }) + gedoIfIdentifier!: string | null; + + @Column({ name: 'gedo_officialized_on', type: 'date', nullable: true }) + gedoOfficializedOn!: string | null; + + @Column({ name: 'gedo_pdf_original_name', type: 'varchar', length: 255, nullable: true }) + gedoPdfOriginalName!: string | null; + + @Column({ name: 'gedo_pdf_stored_name', type: 'varchar', length: 255, nullable: true }) + gedoPdfStoredName!: string | null; + + @Column({ name: 'gedo_pdf_mime_type', type: 'varchar', length: 120, nullable: true }) + gedoPdfMimeType!: string | null; + + @Column({ name: 'gedo_pdf_size_bytes', type: 'integer', nullable: true }) + gedoPdfSizeBytes!: number | null; + + @Column({ name: 'gedo_pdf_sha256', type: 'char', length: 64, nullable: true }) + gedoPdfSha256!: string | null; + + @Column({ name: 'gedo_pdf_uploaded_at', type: 'timestamptz', nullable: true }) + gedoPdfUploadedAt!: Date | null; + + @Column({ name: 'gedo_pdf_uploaded_by', type: 'uuid', nullable: true }) + gedoPdfUploadedBy!: string | null; + @Column({ name: 'review_status', type: 'varchar', length: 32, default: InspectionReportReviewStatus.PENDING_REVIEW }) reviewStatus!: InspectionReportReviewStatus; diff --git a/api-v3/src/database/migrations/1790035200000-phase-f4-document-flow-foundation.ts b/api-v3/src/database/migrations/1790035200000-phase-f4-document-flow-foundation.ts new file mode 100644 index 0000000..729a3ba --- /dev/null +++ b/api-v3/src/database/migrations/1790035200000-phase-f4-document-flow-foundation.ts @@ -0,0 +1,263 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class PhaseF4DocumentFlowFoundation1790035200000 implements MigrationInterface { + name = 'PhaseF4DocumentFlowFoundation1790035200000'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + ALTER TABLE inspection_acts + ADD COLUMN urgency varchar(20), + ADD COLUMN deadline_days integer, + ADD COLUMN deadline_day_type varchar(20), + ADD COLUMN deadline_basis varchar(24), + ADD COLUMN deadline_base_on date, + ADD COLUMN deadline_due_on date, + ADD COLUMN deadline_policy_snapshot jsonb, + ADD COLUMN locked_at timestamptz, + ADD COLUMN locked_by uuid, + ADD COLUMN locked_sha256 char(64), + ADD COLUMN sealed_at timestamptz, + ADD COLUMN sealed_by uuid + `); + await queryRunner.query(` + ALTER TABLE inspection_acts + ADD CONSTRAINT chk_inspection_acts_urgency + CHECK (urgency IS NULL OR urgency IN ('URGENT','NON_URGENT')), + ADD CONSTRAINT chk_inspection_acts_deadline_days + CHECK (deadline_days IS NULL OR deadline_days > 0), + ADD CONSTRAINT chk_inspection_acts_deadline_day_type + CHECK (deadline_day_type IS NULL OR deadline_day_type IN ('BUSINESS','CALENDAR')), + ADD CONSTRAINT chk_inspection_acts_deadline_basis + CHECK (deadline_basis IS NULL OR deadline_basis IN ('ACT_DATE','GEDO_LOAD_DATE')), + ADD CONSTRAINT fk_inspection_acts_locked_by + FOREIGN KEY (locked_by) REFERENCES users(id) ON DELETE SET NULL, + ADD CONSTRAINT fk_inspection_acts_sealed_by + FOREIGN KEY (sealed_by) REFERENCES users(id) ON DELETE SET NULL + `); + await queryRunner.query(` + CREATE INDEX idx_inspection_acts_deadline_due_on + ON inspection_acts(deadline_due_on) + WHERE deadline_due_on IS NOT NULL + `); + + await queryRunner.query(` + CREATE TABLE inspection_deadline_policies ( + urgency varchar(20) PRIMARY KEY, + days integer NOT NULL, + day_type varchar(20) NOT NULL, + basis varchar(24) NOT NULL, + updated_by uuid, + created_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT chk_inspection_deadline_policies_urgency + CHECK (urgency IN ('URGENT','NON_URGENT')), + CONSTRAINT chk_inspection_deadline_policies_days + CHECK (days > 0), + CONSTRAINT chk_inspection_deadline_policies_day_type + CHECK (day_type IN ('BUSINESS','CALENDAR')), + CONSTRAINT chk_inspection_deadline_policies_basis + CHECK (basis IN ('ACT_DATE','GEDO_LOAD_DATE')), + CONSTRAINT fk_inspection_deadline_policies_updated_by + FOREIGN KEY (updated_by) REFERENCES users(id) ON DELETE SET NULL + ) + `); + await queryRunner.query(` + INSERT INTO inspection_deadline_policies (urgency, days, day_type, basis) + VALUES + ('URGENT', 5, 'BUSINESS', 'ACT_DATE'), + ('NON_URGENT', 10, 'BUSINESS', 'GEDO_LOAD_DATE') + `); + + await queryRunner.query(` + CREATE TABLE inspection_non_working_days ( + day date PRIMARY KEY, + label varchar(200) NOT NULL, + enabled boolean NOT NULL DEFAULT true, + created_by uuid, + updated_by uuid, + created_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT chk_inspection_non_working_days_label + CHECK (LENGTH(TRIM(label)) > 0), + CONSTRAINT fk_inspection_non_working_days_created_by + FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL, + CONSTRAINT fk_inspection_non_working_days_updated_by + FOREIGN KEY (updated_by) REFERENCES users(id) ON DELETE SET NULL + ) + `); + + await queryRunner.query(` + ALTER TABLE inspection_findings + ADD COLUMN is_recurrence boolean NOT NULL DEFAULT false, + ADD COLUMN antecedent_finding_id uuid + `); + await queryRunner.query(` + ALTER TABLE inspection_findings + ADD CONSTRAINT fk_inspection_findings_antecedent + FOREIGN KEY (antecedent_finding_id) REFERENCES inspection_findings(id) ON DELETE RESTRICT, + ADD CONSTRAINT chk_inspection_findings_recurrence_link + CHECK ( + (is_recurrence = false AND antecedent_finding_id IS NULL) + OR (is_recurrence = true AND antecedent_finding_id IS NOT NULL) + ), + ADD CONSTRAINT chk_inspection_findings_not_self_antecedent + CHECK (antecedent_finding_id IS NULL OR antecedent_finding_id <> id) + `); + await queryRunner.query(` + CREATE INDEX idx_inspection_findings_antecedent + ON inspection_findings(antecedent_finding_id) + WHERE antecedent_finding_id IS NOT NULL + `); + + await queryRunner.query(` + ALTER TABLE inspection_reports + ADD COLUMN reference_text text, + ADD COLUMN general_objective text, + ADD COLUMN specific_objective text, + ADD COLUMN background text, + ADD COLUMN legal_framework text, + ADD COLUMN executive_summary text, + ADD COLUMN description text, + ADD COLUMN conclusion text, + ADD COLUMN gedo_if_identifier varchar(255), + ADD COLUMN gedo_officialized_on date, + ADD COLUMN gedo_pdf_original_name varchar(255), + ADD COLUMN gedo_pdf_stored_name varchar(255), + ADD COLUMN gedo_pdf_mime_type varchar(120), + ADD COLUMN gedo_pdf_size_bytes integer, + ADD COLUMN gedo_pdf_sha256 char(64), + ADD COLUMN gedo_pdf_uploaded_at timestamptz, + ADD COLUMN gedo_pdf_uploaded_by uuid + `); + await queryRunner.query(` + ALTER TABLE inspection_reports + ADD CONSTRAINT chk_inspection_reports_gedo_pdf_size + CHECK (gedo_pdf_size_bytes IS NULL OR gedo_pdf_size_bytes >= 0), + ADD CONSTRAINT fk_inspection_reports_gedo_pdf_uploaded_by + FOREIGN KEY (gedo_pdf_uploaded_by) REFERENCES users(id) ON DELETE SET NULL + `); + await queryRunner.query(` + CREATE INDEX idx_inspection_reports_gedo_if_identifier + ON inspection_reports(gedo_if_identifier) + WHERE gedo_if_identifier IS NOT NULL + `); + + await queryRunner.query(` + CREATE TABLE inspection_report_follow_ups ( + id uuid PRIMARY KEY DEFAULT gen_random_uuid(), + report_id uuid NOT NULL, + event_type varchar(32) NOT NULL, + reference_number varchar(255), + occurred_on date NOT NULL, + description text, + created_by uuid, + created_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT chk_inspection_report_follow_ups_type + CHECK (event_type IN ('COMPANY_NOTE','COMPANY_DOCUMENT','INTERNAL_NOTE','VERIFICATION','OTHER')), + CONSTRAINT fk_inspection_report_follow_ups_report + FOREIGN KEY (report_id) REFERENCES inspection_reports(id) ON DELETE RESTRICT, + CONSTRAINT fk_inspection_report_follow_ups_created_by + FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL + ) + `); + await queryRunner.query(` + CREATE INDEX idx_inspection_report_follow_ups_report_occurred + ON inspection_report_follow_ups(report_id, occurred_on, created_at) + `); + await queryRunner.query(` + CREATE INDEX idx_inspection_report_follow_ups_type + ON inspection_report_follow_ups(event_type) + `); + + await queryRunner.query(` + CREATE TABLE inspection_report_follow_up_files ( + id uuid PRIMARY KEY DEFAULT gen_random_uuid(), + follow_up_id uuid NOT NULL, + original_name varchar(255) NOT NULL, + stored_name varchar(255) NOT NULL, + mime_type varchar(120) NOT NULL, + size_bytes integer NOT NULL, + sha256 char(64) NOT NULL, + created_by uuid, + created_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT chk_inspection_report_follow_up_files_size + CHECK (size_bytes >= 0), + CONSTRAINT fk_inspection_report_follow_up_files_follow_up + FOREIGN KEY (follow_up_id) REFERENCES inspection_report_follow_ups(id) ON DELETE RESTRICT, + CONSTRAINT fk_inspection_report_follow_up_files_created_by + FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL + ) + `); + await queryRunner.query(` + CREATE INDEX idx_inspection_report_follow_up_files_follow_up + ON inspection_report_follow_up_files(follow_up_id) + `); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE IF EXISTS inspection_report_follow_up_files`); + await queryRunner.query(`DROP TABLE IF EXISTS inspection_report_follow_ups`); + + await queryRunner.query(`DROP INDEX IF EXISTS idx_inspection_reports_gedo_if_identifier`); + await queryRunner.query(` + ALTER TABLE inspection_reports + DROP CONSTRAINT IF EXISTS fk_inspection_reports_gedo_pdf_uploaded_by, + DROP CONSTRAINT IF EXISTS chk_inspection_reports_gedo_pdf_size, + DROP COLUMN IF EXISTS gedo_pdf_uploaded_by, + DROP COLUMN IF EXISTS gedo_pdf_uploaded_at, + DROP COLUMN IF EXISTS gedo_pdf_sha256, + DROP COLUMN IF EXISTS gedo_pdf_size_bytes, + DROP COLUMN IF EXISTS gedo_pdf_mime_type, + DROP COLUMN IF EXISTS gedo_pdf_stored_name, + DROP COLUMN IF EXISTS gedo_pdf_original_name, + DROP COLUMN IF EXISTS gedo_officialized_on, + DROP COLUMN IF EXISTS gedo_if_identifier, + DROP COLUMN IF EXISTS conclusion, + DROP COLUMN IF EXISTS description, + DROP COLUMN IF EXISTS executive_summary, + DROP COLUMN IF EXISTS legal_framework, + DROP COLUMN IF EXISTS background, + DROP COLUMN IF EXISTS specific_objective, + DROP COLUMN IF EXISTS general_objective, + DROP COLUMN IF EXISTS reference_text + `); + + await queryRunner.query(`DROP INDEX IF EXISTS idx_inspection_findings_antecedent`); + await queryRunner.query(` + ALTER TABLE inspection_findings + DROP CONSTRAINT IF EXISTS chk_inspection_findings_not_self_antecedent, + DROP CONSTRAINT IF EXISTS chk_inspection_findings_recurrence_link, + DROP CONSTRAINT IF EXISTS fk_inspection_findings_antecedent, + DROP COLUMN IF EXISTS antecedent_finding_id, + DROP COLUMN IF EXISTS is_recurrence + `); + + await queryRunner.query(`DROP TABLE IF EXISTS inspection_non_working_days`); + await queryRunner.query(`DROP TABLE IF EXISTS inspection_deadline_policies`); + + await queryRunner.query(`DROP INDEX IF EXISTS idx_inspection_acts_deadline_due_on`); + await queryRunner.query(` + ALTER TABLE inspection_acts + DROP CONSTRAINT IF EXISTS fk_inspection_acts_sealed_by, + DROP CONSTRAINT IF EXISTS fk_inspection_acts_locked_by, + DROP CONSTRAINT IF EXISTS chk_inspection_acts_deadline_basis, + DROP CONSTRAINT IF EXISTS chk_inspection_acts_deadline_day_type, + DROP CONSTRAINT IF EXISTS chk_inspection_acts_deadline_days, + DROP CONSTRAINT IF EXISTS chk_inspection_acts_urgency, + DROP COLUMN IF EXISTS sealed_by, + DROP COLUMN IF EXISTS sealed_at, + DROP COLUMN IF EXISTS locked_sha256, + DROP COLUMN IF EXISTS locked_by, + DROP COLUMN IF EXISTS locked_at, + DROP COLUMN IF EXISTS deadline_policy_snapshot, + DROP COLUMN IF EXISTS deadline_due_on, + DROP COLUMN IF EXISTS deadline_base_on, + DROP COLUMN IF EXISTS deadline_basis, + DROP COLUMN IF EXISTS deadline_day_type, + DROP COLUMN IF EXISTS deadline_days, + DROP COLUMN IF EXISTS urgency + `); + } +}