1 import { Migration } from "@medusajs/framework/mikro-orm/migrations";
2
3 export class Migration20241212052837 extends Migration {
4
5 async up(): Promise<void> {
6 this.addSql('alter table if exists "tax_provider" add column if not exists "created_at" timestamptz not null default now(), add column if not exists "updated_at" timestamptz not null default now(), add column if not exists "deleted_at" timestamptz null;');
7 this.addSql('CREATE INDEX IF NOT EXISTS "IDX_tax_provider_deleted_at" ON "tax_provider" (deleted_at) WHERE deleted_at IS NULL;');
8
9 this.addSql('CREATE INDEX IF NOT EXISTS "IDX_tax_region_provider_id" ON "tax_region" (provider_id) WHERE deleted_at IS NULL;');
10
11 this.addSql('alter table if exists "tax_rate" alter column "rate" type real using ("rate"::real);');
12 this.addSql('alter table if exists "tax_rate" alter column "rate" drop not null;');
13 }
14
15 async down(): Promise<void> {
16 this.addSql('drop index if exists "IDX_tax_provider_deleted_at";');
17 this.addSql('alter table if exists "tax_provider" drop column if exists "created_at";');
18 this.addSql('alter table if exists "tax_provider" drop column if exists "updated_at";');
19 this.addSql('alter table if exists "tax_provider" drop column if exists "deleted_at";');
20
21 this.addSql('drop index if exists "IDX_tax_region_provider_id";');
22
23 this.addSql('alter table if exists "tax_rate" alter column "rate" type real using ("rate"::real);');
24 this.addSql('alter table if exists "tax_rate" alter column "rate" set not null;');
25 }
26
27 }