Skip to content

Instantly share code, notes, and snippets.

@lemissel
Created October 14, 2020 10:58
Show Gist options
  • Save lemissel/cf6642550b5d3b89fe05c721aba50f7d to your computer and use it in GitHub Desktop.
Save lemissel/cf6642550b5d3b89fe05c721aba50f7d to your computer and use it in GitHub Desktop.
Simplest Migration Exemple
import {MigrationInterface, QueryRunner} from "typeorm";
export class ModifySomething implements MigrationInterface {
name = 'ModifySomething987982495702935873450987'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query("ALTER TABLE `syndicate` ADD CONSTRAINT `FK_sd9f8g7s8df6g89f6s87dfg` FOREIGN KEY (`addressId`) REFERENCES `address`(`id`) ON DELETE CASCADE ON UPDATE CASCADE");
await queryRunner.query("ALTER TABLE `address` ADD CONSTRAINT `FK_c76sdf8g6sdf87g6s9g67` FOREIGN KEY (`companyId`) REFERENCES `company`(`id`) ON DELETE CASCADE ON UPDATE CASCADE");
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query("ALTER TABLE `address` DROP FOREIGN KEY `FK_c76sdf8g6sdf87g6s9g67`");
await queryRunner.query("ALTER TABLE `syndicate` DROP FOREIGN KEY `FK_sd9f8g7s8df6g89f6s87dfg`");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment