feat: implement Migration module with controller, service, and entity, including migration creation logic
This commit is contained in:
59
src/migrations/1758912793124-Migrations.ts
Normal file
59
src/migrations/1758912793124-Migrations.ts
Normal file
@ -0,0 +1,59 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class Migrations1758912793124 implements MigrationInterface {
|
||||
name = "Migrations1758912793124";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE \`migration\` (\`id\` varchar(36) NOT NULL, \`name\` varchar(255) NOT NULL, \`appliedAt\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP(), \`isApplied\` tinyint NOT NULL DEFAULT '1', \`isValid\` tinyint NOT NULL DEFAULT '1', \`sql\` varchar(255) NOT NULL, \`data\` json NULL, \`projectToken\` varchar(36) NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE \`query_modules_module\` (\`queryId\` varchar(36) NOT NULL, \`moduleId\` varchar(36) NOT NULL, INDEX \`IDX_12121324c524e12538de4948ce\` (\`queryId\`), INDEX \`IDX_7fb42dbc85874aafbd4bfb1c10\` (\`moduleId\`), PRIMARY KEY (\`queryId\`, \`moduleId\`)) ENGINE=InnoDB`
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE \`module\` DROP COLUMN \`isInjectable\``
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE \`plugin\` ADD \`queryId\` varchar(36) NULL`
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE \`migration\` ADD CONSTRAINT \`FK_d3d093f32ce7c968b02fc6bce65\` FOREIGN KEY (\`projectToken\`) REFERENCES \`project\`(\`token\`) ON DELETE NO ACTION ON UPDATE NO ACTION`
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE \`plugin\` ADD CONSTRAINT \`FK_5162d18c3653d35ff4d104dd940\` FOREIGN KEY (\`queryId\`) REFERENCES \`query\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE \`query_modules_module\` ADD CONSTRAINT \`FK_12121324c524e12538de4948cee\` FOREIGN KEY (\`queryId\`) REFERENCES \`query\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE \`query_modules_module\` ADD CONSTRAINT \`FK_7fb42dbc85874aafbd4bfb1c101\` FOREIGN KEY (\`moduleId\`) REFERENCES \`module\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE \`query_modules_module\` DROP FOREIGN KEY \`FK_7fb42dbc85874aafbd4bfb1c101\``
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE \`query_modules_module\` DROP FOREIGN KEY \`FK_12121324c524e12538de4948cee\``
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE \`plugin\` DROP FOREIGN KEY \`FK_5162d18c3653d35ff4d104dd940\``
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE \`migration\` DROP FOREIGN KEY \`FK_d3d093f32ce7c968b02fc6bce65\``
|
||||
);
|
||||
await queryRunner.query(`ALTER TABLE \`plugin\` DROP COLUMN \`queryId\``);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE \`module\` ADD \`isInjectable\` tinyint NOT NULL DEFAULT 1`
|
||||
);
|
||||
await queryRunner.query(
|
||||
`DROP INDEX \`IDX_7fb42dbc85874aafbd4bfb1c10\` ON \`query_modules_module\``
|
||||
);
|
||||
await queryRunner.query(
|
||||
`DROP INDEX \`IDX_12121324c524e12538de4948ce\` ON \`query_modules_module\``
|
||||
);
|
||||
await queryRunner.query(`DROP TABLE \`query_modules_module\``);
|
||||
await queryRunner.query(`DROP TABLE \`migration\``);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user