42 lines
1.7 KiB
TypeScript
42 lines
1.7 KiB
TypeScript
import { Migration } from '@mikro-orm/migrations';
|
|
|
|
export class Migration20260704100000_addCampaignsTable extends Migration {
|
|
|
|
override async up(): Promise<void> {
|
|
this.addSql(`
|
|
create table "campaigns" (
|
|
"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,
|
|
"title" varchar(255) not null,
|
|
"groups" jsonb not null default '[]',
|
|
"sent_type" text check ("sent_type" in ('push', 'sms')) not null,
|
|
"discount_code" varchar(255) not null,
|
|
"total_count" int not null default 0,
|
|
"total_cost" int not null default 0,
|
|
"refunded" int not null default 0,
|
|
"sent_count" int not null default 0,
|
|
"failed_count" int not null default 0,
|
|
"status" text check ("status" in ('sending', 'completed')) not null default 'sending',
|
|
constraint "campaigns_pkey" primary key ("id")
|
|
);
|
|
`);
|
|
this.addSql(`create index "campaigns_created_at_index" on "campaigns" ("created_at");`);
|
|
this.addSql(`create index "campaigns_deleted_at_index" on "campaigns" ("deleted_at");`);
|
|
this.addSql(`create index "campaigns_restaurant_id_index" on "campaigns" ("restaurant_id");`);
|
|
this.addSql(`
|
|
alter table "campaigns"
|
|
add constraint "campaigns_restaurant_id_foreign"
|
|
foreign key ("restaurant_id") references "restaurants" ("id") on update cascade;
|
|
`);
|
|
}
|
|
|
|
override async down(): Promise<void> {
|
|
this.addSql(`alter table "campaigns" drop constraint if exists "campaigns_restaurant_id_foreign";`);
|
|
this.addSql(`drop table if exists "campaigns" cascade;`);
|
|
}
|
|
|
|
}
|