import { Migration } from '@mikro-orm/migrations';

export class Migration20240415211308 extends Migration {

  async up(): Promise<void> {
    this.addSql('create table "user_role" ("id" serial primary key, "created_at" timestamptz not null, "updated_at" timestamptz not null, "name" varchar(255) not null);');

    this.addSql('create table "user_roles" ("user_id" int not null, "user_role_id" int not null, constraint "user_roles_pkey" primary key ("user_id", "user_role_id"));');

    this.addSql('alter table "user_roles" add constraint "user_roles_user_id_foreign" foreign key ("user_id") references "user" ("id") on update cascade on delete cascade;');
    this.addSql('alter table "user_roles" add constraint "user_roles_user_role_id_foreign" foreign key ("user_role_id") references "user_role" ("id") on update cascade on delete cascade;');

    this.addSql('alter table "user" add column "password" varchar(255) not null, add column "email" varchar(255) not null;');
  }

  async down(): Promise<void> {
    this.addSql('alter table "user_roles" drop constraint "user_roles_user_role_id_foreign";');

    this.addSql('drop table if exists "user_role" cascade;');

    this.addSql('drop table if exists "user_roles" cascade;');

    this.addSql('alter table "user" drop column "password", drop column "email";');
  }

}
