This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
export class Migration20260701150000_addUserGroupsTable extends Migration {
|
||||
|
||||
override async up(): Promise<void> {
|
||||
this.addSql(`
|
||||
create table "user_groups" (
|
||||
"id" char(26) not null,
|
||||
"created_at" timestamptz not null default now(),
|
||||
"updated_at" timestamptz not null default now(),
|
||||
"deleted_at" timestamptz null,
|
||||
"restaurant_id" char(26) not null,
|
||||
"name" varchar(255) not null,
|
||||
"count" int not null default 0,
|
||||
constraint "user_groups_pkey" primary key ("id")
|
||||
);
|
||||
`);
|
||||
this.addSql(`create index "user_groups_created_at_index" on "user_groups" ("created_at");`);
|
||||
this.addSql(`create index "user_groups_deleted_at_index" on "user_groups" ("deleted_at");`);
|
||||
this.addSql(`create index "user_groups_restaurant_id_index" on "user_groups" ("restaurant_id");`);
|
||||
this.addSql(`create unique index "user_groups_restaurant_id_name_unique" on "user_groups" ("restaurant_id", "name") where "deleted_at" is null;`);
|
||||
this.addSql(`
|
||||
alter table "user_groups"
|
||||
add constraint "user_groups_restaurant_id_foreign"
|
||||
foreign key ("restaurant_id") references "restaurants" ("id") on update cascade;
|
||||
`);
|
||||
}
|
||||
|
||||
override async down(): Promise<void> {
|
||||
this.addSql(`alter table "user_groups" drop constraint if exists "user_groups_restaurant_id_foreign";`);
|
||||
this.addSql(`drop table if exists "user_groups" cascade;`);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user