21 lines
1.4 KiB
TypeScript
21 lines
1.4 KiB
TypeScript
import { Migration } from '@mikro-orm/migrations';
|
|
|
|
export class Migration20260628130000_AddUserShops extends Migration {
|
|
|
|
override async up(): Promise<void> {
|
|
this.addSql(`create table "user_shops" ("id" char(26) not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, "order_count" int not null default 0, "total_order_amount" int not null default 0, "user_id" char(26) not null, "shop_id" char(26) not null, constraint "user_shops_pkey" primary key ("id"));`);
|
|
this.addSql(`create index "user_shops_created_at_index" on "user_shops" ("created_at");`);
|
|
this.addSql(`create index "user_shops_deleted_at_index" on "user_shops" ("deleted_at");`);
|
|
this.addSql(`create index "user_shops_user_id_shop_id_index" on "user_shops" ("user_id", "shop_id");`);
|
|
this.addSql(`alter table "user_shops" add constraint "user_shops_user_id_shop_id_unique" unique ("user_id", "shop_id");`);
|
|
|
|
this.addSql(`alter table "user_shops" add constraint "user_shops_user_id_foreign" foreign key ("user_id") references "users" ("id") on update cascade on delete cascade;`);
|
|
this.addSql(`alter table "user_shops" add constraint "user_shops_shop_id_foreign" foreign key ("shop_id") references "shops" ("id") on update cascade on delete cascade;`);
|
|
}
|
|
|
|
override async down(): Promise<void> {
|
|
this.addSql(`drop table if exists "user_shops" cascade;`);
|
|
}
|
|
|
|
}
|