Skip to content

Commit

Permalink
refactor: Add new migrations for SchemaMigrations and Models
Browse files Browse the repository at this point in the history
New migrations have been added to the SchemaMigrations and Models directories. These migrations introduce new changes to the database schema and model definitions. This commit ensures that the codebase is up to date with the latest schema changes and improves the maintainability of the application.
  • Loading branch information
simlarsen committed Jun 11, 2024
1 parent 02046a5 commit 36cfb7e
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class MigrationName1718121103363 implements MigrationInterface {
public name = 'MigrationName1718121103363';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "CopilotService" ("_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, "servicePathInRepository" character varying(500) NOT NULL DEFAULT '/', "limitNumberOfOpenPullRequestsCount" integer DEFAULT '3', "createdByUserId" uuid, "deletedByUserId" uuid, "codeRepositoryId" uuid NOT NULL, "serviceCatalogId" uuid NOT NULL, CONSTRAINT "PK_2d18b7fe97f4bbfcff6b97b914e" PRIMARY KEY ("_id"))`
);
await queryRunner.query(
`CREATE INDEX "IDX_36e92a170d7ec38334ac3ebb90" ON "CopilotService" ("projectId") `
);
await queryRunner.query(
`CREATE INDEX "IDX_52205be2c47a084993710bc415" ON "CopilotService" ("codeRepositoryId") `
);
await queryRunner.query(
`CREATE INDEX "IDX_0473bee1732ba1d182fbcf72ae" ON "CopilotService" ("serviceCatalogId") `
);
await queryRunner.query(
`ALTER TABLE "CopilotEvent" ADD "serviceCatalogId" uuid NOT NULL`
);
await queryRunner.query(
`ALTER TABLE "CopilotEvent" ADD "copilotServiceId" uuid NOT NULL`
);
await queryRunner.query(
`CREATE INDEX "IDX_1ae20e42e24919a32772f11ccc" ON "CopilotEvent" ("serviceCatalogId") `
);
await queryRunner.query(
`CREATE INDEX "IDX_e808df486c4ed604786c1c8f78" ON "CopilotEvent" ("copilotServiceId") `
);
await queryRunner.query(
`ALTER TABLE "CopilotService" ADD CONSTRAINT "FK_36e92a170d7ec38334ac3ebb905" FOREIGN KEY ("projectId") REFERENCES "Project"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`
);
await queryRunner.query(
`ALTER TABLE "CopilotService" ADD CONSTRAINT "FK_582b763b1df79b7fbfc13b4acf5" FOREIGN KEY ("createdByUserId") REFERENCES "User"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`
);
await queryRunner.query(
`ALTER TABLE "CopilotService" ADD CONSTRAINT "FK_7892e66e216040f2bf0b26ce154" FOREIGN KEY ("deletedByUserId") REFERENCES "User"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`
);
await queryRunner.query(
`ALTER TABLE "CopilotService" ADD CONSTRAINT "FK_52205be2c47a084993710bc4157" FOREIGN KEY ("codeRepositoryId") REFERENCES "CodeRepository"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`
);
await queryRunner.query(
`ALTER TABLE "CopilotService" ADD CONSTRAINT "FK_0473bee1732ba1d182fbcf72aec" FOREIGN KEY ("serviceCatalogId") REFERENCES "ServiceCatalog"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`
);
await queryRunner.query(
`ALTER TABLE "CopilotEvent" ADD CONSTRAINT "FK_1ae20e42e24919a32772f11ccc8" FOREIGN KEY ("serviceCatalogId") REFERENCES "ServiceCatalog"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`
);
await queryRunner.query(
`ALTER TABLE "CopilotEvent" ADD CONSTRAINT "FK_e808df486c4ed604786c1c8f783" FOREIGN KEY ("copilotServiceId") REFERENCES "CopilotService"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "CopilotEvent" DROP CONSTRAINT "FK_e808df486c4ed604786c1c8f783"`
);
await queryRunner.query(
`ALTER TABLE "CopilotEvent" DROP CONSTRAINT "FK_1ae20e42e24919a32772f11ccc8"`
);
await queryRunner.query(
`ALTER TABLE "CopilotService" DROP CONSTRAINT "FK_0473bee1732ba1d182fbcf72aec"`
);
await queryRunner.query(
`ALTER TABLE "CopilotService" DROP CONSTRAINT "FK_52205be2c47a084993710bc4157"`
);
await queryRunner.query(
`ALTER TABLE "CopilotService" DROP CONSTRAINT "FK_7892e66e216040f2bf0b26ce154"`
);
await queryRunner.query(
`ALTER TABLE "CopilotService" DROP CONSTRAINT "FK_582b763b1df79b7fbfc13b4acf5"`
);
await queryRunner.query(
`ALTER TABLE "CopilotService" DROP CONSTRAINT "FK_36e92a170d7ec38334ac3ebb905"`
);
await queryRunner.query(
`DROP INDEX "public"."IDX_e808df486c4ed604786c1c8f78"`
);
await queryRunner.query(
`DROP INDEX "public"."IDX_1ae20e42e24919a32772f11ccc"`
);
await queryRunner.query(
`ALTER TABLE "CopilotEvent" DROP COLUMN "copilotServiceId"`
);
await queryRunner.query(
`ALTER TABLE "CopilotEvent" DROP COLUMN "serviceCatalogId"`
);
await queryRunner.query(
`DROP INDEX "public"."IDX_0473bee1732ba1d182fbcf72ae"`
);
await queryRunner.query(
`DROP INDEX "public"."IDX_52205be2c47a084993710bc415"`
);
await queryRunner.query(
`DROP INDEX "public"."IDX_36e92a170d7ec38334ac3ebb90"`
);
await queryRunner.query(`DROP TABLE "CopilotService"`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { MigrationName1718037833516 } from './1718037833516-MigrationName';
import { MigrationName1718100824584 } from './1718100824584-MigrationName';
import { MigrationName1718101665865 } from './1718101665865-MigrationName';
import { MigrationName1718119926223 } from './1718119926223-MigrationName';
import { MigrationName1718121103363 } from './1718121103363-MigrationName';

export default [
InitialMigration,
Expand All @@ -18,4 +19,5 @@ export default [
MigrationName1718100824584,
MigrationName1718101665865,
MigrationName1718119926223,
MigrationName1718121103363,
];
2 changes: 2 additions & 0 deletions Model/Models/Index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import BillingPaymentMethods from './BillingPaymentMethod';
import CallLog from './CallLog';
import CodeRepository from './CodeRepository';
import CopilotEvent from './CopilotEvent';
import CopilotService from './CopilotService';
// Date migration
import DataMigration from './DataMigration';
import Domain from './Domain';
Expand Down Expand Up @@ -266,4 +267,5 @@ export default [

CodeRepository,
CopilotEvent,
CopilotService,
];

0 comments on commit 36cfb7e

Please sign in to comment.