Created
November 22, 2021 17:12
-
-
Save evenfrost/e358b60ea001feae7eed3860eccb6ab8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Migration } from '@mikro-orm/migrations'; | |
export class Migration20211022164646 extends Migration { | |
async up(): Promise<void> { | |
this.addSql('alter table "Brands" drop constraint "Brands_clientId_fkey"'); | |
this.addSql('alter table "Brands" add constraint "Brands_clientId_fkey" foreign key ("clientId") references "clients" ("id") on update cascade on delete cascade;'); | |
this.addSql('delete from "Brands" where "clientId" is null'); | |
this.addSql('alter table "DynamicContentItems" drop constraint "DynamicContentItems_clientId_fkey"'); | |
this.addSql('alter table "DynamicContentItems" add constraint "DynamicContentItems_clientId_fkey" foreign key ("clientId") references "clients" ("id") on update cascade on delete cascade;'); | |
this.addSql('delete from "DynamicContentItems" where "clientId" is null'); | |
this.addSql('alter table "Groups" drop constraint "Groups_clientId_fkey"'); | |
this.addSql('alter table "Groups" add constraint "Groups_clientId_fkey" foreign key ("clientId") references "clients" ("id") on update cascade on delete cascade;'); | |
this.addSql('delete from "Groups" where "clientId" is null'); | |
this.addSql('alter table "Users" drop constraint "Users_clientId_fkey"'); | |
this.addSql('alter table "Users" add constraint "Users_clientId_fkey" foreign key ("clientId") references "clients" ("id") on update cascade on delete cascade;'); | |
this.addSql('delete from "Users" where "clientId" is null'); | |
} | |
async down(): Promise<void> { | |
this.addSql('alter table "Brands" drop constraint "Brands_clientId_fkey"'); | |
this.addSql('alter table "Brands" add constraint "Brands_clientId_fkey" foreign key ("clientId") references "clients" ("id") on update cascade on delete set null;'); | |
this.addSql('alter table "DynamicContentItems" drop constraint "DynamicContentItems_clientId_fkey"'); | |
this.addSql('alter table "DynamicContentItems" add constraint "DynamicContentItems_clientId_fkey" foreign key ("clientId") references "clients" ("id") on update cascade on delete set null;'); | |
this.addSql('alter table "Groups" drop constraint "Groups_clientId_fkey"'); | |
this.addSql('alter table "Groups" add constraint "Groups_clientId_fkey" foreign key ("clientId") references "clients" ("id") on update cascade on delete set null;'); | |
this.addSql('alter table "Users" drop constraint "Users_clientId_fkey"'); | |
this.addSql('alter table "Users" add constraint "Users_clientId_fkey" foreign key ("clientId") references "clients" ("id") on update cascade on delete set null;'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment