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

export class Migration20260618162454_add_user_restuarant_table extends Migration {

  override async up(): Promise<void> {
    this.addSql(`create table "user_restuarant" ("id" char(26) not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, "user_id" char(26) not null, "restaurant_id" char(26) not null, "order_count" int not null, "total_order_amount" int not null, constraint "user_restuarant_pkey" primary key ("id"));`);
    this.addSql(`create index "user_restuarant_created_at_index" on "user_restuarant" ("created_at");`);
    this.addSql(`create index "user_restuarant_deleted_at_index" on "user_restuarant" ("deleted_at");`);
    this.addSql(`create index "user_restuarant_restaurant_id_index" on "user_restuarant" ("restaurant_id");`);
    this.addSql(`alter table "user_restuarant" add constraint "user_restuarant_user_id_restaurant_id_unique" unique ("user_id", "restaurant_id");`);

    this.addSql(`alter table "user_restuarant" add constraint "user_restuarant_user_id_foreign" foreign key ("user_id") references "users" ("id") on update cascade;`);
    this.addSql(`alter table "user_restuarant" add constraint "user_restuarant_restaurant_id_foreign" foreign key ("restaurant_id") references "restaurants" ("id") on update cascade;`);
  }

  override async down(): Promise<void> {
    this.addSql(`drop table if exists "user_restuarant";`);
  }

}
