var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import CaptureSpan from "../../../Utils/Telemetry/CaptureSpan";
export class MigrationName1720785305192 {
    constructor() {
        this.name = "MigrationName1720785305192";
    }
    async up(queryRunner) {
        // delete all data from CopilotAction
        await queryRunner.query(`DELETE FROM "CopilotAction"`);
        await queryRunner.query(`ALTER TABLE "CopilotAction" RENAME COLUMN "pullRequestId" TO "copilotPullRequestId"`);
        await queryRunner.query(`CREATE TABLE "CopilotPullRequest" ("_id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP, "version" integer NOT NULL, "projectId" uuid NOT NULL, "codeRepositoryId" uuid NOT NULL, "createdByUserId" uuid, "deletedByUserId" uuid, "serviceCatalogId" uuid NOT NULL, "serviceRepositoryId" uuid NOT NULL, "pullRequestId" character varying, "copilotPullRequestStatus" character varying NOT NULL, CONSTRAINT "PK_418ada04b02eeba0c196a3f3457" PRIMARY KEY ("_id"))`);
        await queryRunner.query(`CREATE INDEX "IDX_da5384640778014e53c7d87f26" ON "CopilotPullRequest" ("projectId") `);
        await queryRunner.query(`CREATE INDEX "IDX_b32d46897397d2cf93df83922a" ON "CopilotPullRequest" ("codeRepositoryId") `);
        await queryRunner.query(`CREATE INDEX "IDX_81c04dfb087fe1314f9b0bfbd0" ON "CopilotPullRequest" ("serviceCatalogId") `);
        await queryRunner.query(`CREATE INDEX "IDX_8e7cd28e052005c1098553f18d" ON "CopilotPullRequest" ("serviceRepositoryId") `);
        await queryRunner.query(`ALTER TABLE "CopilotCodeRepository" ADD "lastCopilotRunDateTime" TIMESTAMP WITH TIME ZONE`);
        await queryRunner.query(`ALTER TABLE "CopilotAction" DROP COLUMN "copilotPullRequestId"`);
        await queryRunner.query(`ALTER TABLE "CopilotAction" ADD "copilotPullRequestId" uuid NOT NULL`);
        await queryRunner.query(`CREATE INDEX "IDX_c21417d854c9330f4cadc2bc2b" ON "CopilotAction" ("copilotPullRequestId") `);
        await queryRunner.query(`ALTER TABLE "CopilotPullRequest" ADD CONSTRAINT "FK_da5384640778014e53c7d87f269" FOREIGN KEY ("projectId") REFERENCES "Project"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "CopilotPullRequest" ADD CONSTRAINT "FK_b32d46897397d2cf93df83922a0" FOREIGN KEY ("codeRepositoryId") REFERENCES "CopilotCodeRepository"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "CopilotPullRequest" ADD CONSTRAINT "FK_caa750ea8d9fab8b760d207e62a" FOREIGN KEY ("createdByUserId") REFERENCES "User"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "CopilotPullRequest" ADD CONSTRAINT "FK_47c9d3ce65ef12e842fc487e54c" FOREIGN KEY ("deletedByUserId") REFERENCES "User"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "CopilotPullRequest" ADD CONSTRAINT "FK_81c04dfb087fe1314f9b0bfbd0d" FOREIGN KEY ("serviceCatalogId") REFERENCES "ServiceCatalog"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "CopilotPullRequest" ADD CONSTRAINT "FK_8e7cd28e052005c1098553f18df" FOREIGN KEY ("serviceRepositoryId") REFERENCES "ServiceCopilotCodeRepository"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "CopilotAction" ADD CONSTRAINT "FK_c21417d854c9330f4cadc2bc2b0" FOREIGN KEY ("copilotPullRequestId") REFERENCES "CopilotPullRequest"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
    }
    async down(queryRunner) {
        await queryRunner.query(`ALTER TABLE "CopilotAction" DROP CONSTRAINT "FK_c21417d854c9330f4cadc2bc2b0"`);
        await queryRunner.query(`ALTER TABLE "CopilotPullRequest" DROP CONSTRAINT "FK_8e7cd28e052005c1098553f18df"`);
        await queryRunner.query(`ALTER TABLE "CopilotPullRequest" DROP CONSTRAINT "FK_81c04dfb087fe1314f9b0bfbd0d"`);
        await queryRunner.query(`ALTER TABLE "CopilotPullRequest" DROP CONSTRAINT "FK_47c9d3ce65ef12e842fc487e54c"`);
        await queryRunner.query(`ALTER TABLE "CopilotPullRequest" DROP CONSTRAINT "FK_caa750ea8d9fab8b760d207e62a"`);
        await queryRunner.query(`ALTER TABLE "CopilotPullRequest" DROP CONSTRAINT "FK_b32d46897397d2cf93df83922a0"`);
        await queryRunner.query(`ALTER TABLE "CopilotPullRequest" DROP CONSTRAINT "FK_da5384640778014e53c7d87f269"`);
        await queryRunner.query(`DROP INDEX "public"."IDX_c21417d854c9330f4cadc2bc2b"`);
        await queryRunner.query(`ALTER TABLE "CopilotAction" DROP COLUMN "copilotPullRequestId"`);
        await queryRunner.query(`ALTER TABLE "CopilotAction" ADD "copilotPullRequestId" character varying`);
        await queryRunner.query(`ALTER TABLE "CopilotCodeRepository" DROP COLUMN "lastCopilotRunDateTime"`);
        await queryRunner.query(`DROP INDEX "public"."IDX_8e7cd28e052005c1098553f18d"`);
        await queryRunner.query(`DROP INDEX "public"."IDX_81c04dfb087fe1314f9b0bfbd0"`);
        await queryRunner.query(`DROP INDEX "public"."IDX_b32d46897397d2cf93df83922a"`);
        await queryRunner.query(`DROP INDEX "public"."IDX_da5384640778014e53c7d87f26"`);
        await queryRunner.query(`DROP TABLE "CopilotPullRequest"`);
        await queryRunner.query(`ALTER TABLE "CopilotAction" RENAME COLUMN "copilotPullRequestId" TO "pullRequestId"`);
    }
}
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], MigrationName1720785305192.prototype, "up", null);
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], MigrationName1720785305192.prototype, "down", null);
//# sourceMappingURL=1720785305192-MigrationName.js.map