1 import { Migration } from "@medusajs/framework/mikro-orm/migrations"
2
3 export class Migration20240509083918_InitialSetupMigration extends Migration {
4 async up(): Promise<void> {
5 this.addSql("drop table if exists notification")
6 this.addSql("drop table if exists notification_provider")
7
8 this.addSql(
9 'create table if not exists "notification_provider" ("id" text not null, "handle" text not null, "name" text not null, "is_enabled" boolean not null default true, "channels" text[] not null, constraint "notification_provider_pkey" primary key ("id"));'
10 )
11
12 this.addSql(
13 'create table if not exists "notification" ("id" text not null, "to" text not null, "channel" text not null, "template" text not null, "data" jsonb null, "trigger_type" text null, "resource_id" text null, "resource_type" text null, "receiver_id" text null, "original_notification_id" text null, "idempotency_key" text null, "external_id" text null, "provider_id" text null, "created_at" timestamptz not null default now(), constraint "notification_pkey" primary key ("id"));'
14 )
15 this.addSql(
16 'CREATE INDEX IF NOT EXISTS "IDX_notification_provider_id" ON "notification" (provider_id);'
17 )
18 this.addSql(
19 'CREATE INDEX IF NOT EXISTS "IDX_notification_idempotency_key" ON "notification" (idempotency_key);'
20 )
21 this.addSql(
22 'CREATE INDEX IF NOT EXISTS "IDX_notification_receiver_id" ON "notification" (receiver_id);'
23 )
24
25 this.addSql(
26 'alter table if exists "notification" add constraint "notification_provider_id_foreign" foreign key ("provider_id") references "notification_provider" ("id") on update cascade on delete set null;'
27 )
28 }
29 }