1 import { Migration } from "@medusajs/framework/mikro-orm/migrations"
2
3 export class Migration20240307161216 extends Migration {
4 async up(): Promise<void> {
5 this.addSql(
6 'create table if not exists "stock_location_address" ("id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, "address_1" text not null, "address_2" text null, "company" text null, "city" text null, "country_code" text not null, "phone" text null, "province" text null, "postal_code" text null, "metadata" jsonb null, constraint "stock_location_address_pkey" primary key ("id"));'
7 )
8 this.addSql(
9 'CREATE INDEX IF NOT EXISTS "IDX_stock_location_address_deleted_at" ON "stock_location_address" (deleted_at) WHERE deleted_at IS NOT NULL;'
10 )
11
12 this.addSql(
13 'create table if not exists "stock_location" ("id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, "name" text not null, "address_id" text null, "metadata" jsonb null, constraint "stock_location_pkey" primary key ("id"));'
14 )
15 this.addSql(
16 'CREATE INDEX IF NOT EXISTS "IDX_stock_location_deleted_at" ON "stock_location" (deleted_at) WHERE deleted_at IS NOT NULL;'
17 )
18
19 this.addSql(
20 'alter table if exists "stock_location" add constraint "stock_location_address_id_foreign" foreign key ("address_id") references "stock_location_address" ("id") on update cascade on delete set null;'
21 )
22 }
23
24 async down(): Promise<void> {
25 this.addSql(
26 'alter table if exists "stock_location" drop constraint if exists "stock_location_address_id_foreign";'
27 )
28
29 this.addSql('drop table if exists "stock_location_address" cascade;')
30
31 this.addSql('drop table if exists "stock_location" cascade;')
32 }
33 }