38 lines
1.5 KiB
TypeScript
38 lines
1.5 KiB
TypeScript
import { Migration } from '@mikro-orm/migrations';
|
|
|
|
export class Migration20260701130000_addSlidersTable extends Migration {
|
|
|
|
override async up(): Promise<void> {
|
|
this.addSql(`
|
|
create table "sliders" (
|
|
"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,
|
|
"image_url" varchar(255) not null,
|
|
"title" varchar(255) null,
|
|
"link" varchar(255) null,
|
|
"order" int not null default 0,
|
|
"is_active" boolean not null default true,
|
|
constraint "sliders_pkey" primary key ("id")
|
|
);
|
|
`);
|
|
this.addSql(`create index "sliders_created_at_index" on "sliders" ("created_at");`);
|
|
this.addSql(`create index "sliders_deleted_at_index" on "sliders" ("deleted_at");`);
|
|
this.addSql(`create index "sliders_restaurant_id_index" on "sliders" ("restaurant_id");`);
|
|
this.addSql(`create index "sliders_restaurant_id_is_active_index" on "sliders" ("restaurant_id", "is_active");`);
|
|
this.addSql(`
|
|
alter table "sliders"
|
|
add constraint "sliders_restaurant_id_foreign"
|
|
foreign key ("restaurant_id") references "restaurants" ("id") on update cascade;
|
|
`);
|
|
}
|
|
|
|
override async down(): Promise<void> {
|
|
this.addSql(`alter table "sliders" drop constraint if exists "sliders_restaurant_id_foreign";`);
|
|
this.addSql(`drop table if exists "sliders" cascade;`);
|
|
}
|
|
|
|
}
|