|
1
|
import { Migration } from "@medusajs/framework/mikro-orm/migrations" |
|
2
|
|
|
3
|
export class Migration20241213063611 extends Migration { |
|
4
|
async up(): Promise<void> { |
|
5
|
this.addSql('drop index if exists "IDX_inventory_item_sku_unique";') |
|
6
|
this.addSql( |
|
7
|
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_inventory_item_sku" ON "inventory_item" (sku) WHERE deleted_at IS NULL;' |
|
8
|
) |
|
9
|
|
|
10
|
this.addSql( |
|
11
|
'alter table if exists "inventory_level" add column if not exists "raw_stocked_quantity" jsonb not null, add column if not exists "raw_reserved_quantity" jsonb not null, add column if not exists "raw_incoming_quantity" jsonb not null;' |
|
12
|
) |
|
13
|
this.addSql( |
|
14
|
'alter table if exists "inventory_level" alter column "stocked_quantity" type numeric using ("stocked_quantity"::numeric);' |
|
15
|
) |
|
16
|
this.addSql( |
|
17
|
'alter table if exists "inventory_level" alter column "reserved_quantity" type numeric using ("reserved_quantity"::numeric);' |
|
18
|
) |
|
19
|
this.addSql( |
|
20
|
'alter table if exists "inventory_level" alter column "incoming_quantity" type numeric using ("incoming_quantity"::numeric);' |
|
21
|
) |
|
22
|
this.addSql( |
|
23
|
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_inventory_level_location_id_inventory_item_id" ON "inventory_level" (inventory_item_id, location_id) WHERE deleted_at IS NULL;' |
|
24
|
) |
|
25
|
|
|
26
|
this.addSql( |
|
27
|
'alter table if exists "reservation_item" add column if not exists "allow_backorder" boolean not null default false, add column if not exists "raw_quantity" jsonb not null;' |
|
28
|
) |
|
29
|
this.addSql( |
|
30
|
'alter table if exists "reservation_item" alter column "quantity" type numeric using ("quantity"::numeric);' |
|
31
|
) |
|
32
|
} |
|
33
|
|
|
34
|
async down(): Promise<void> { |
|
35
|
this.addSql('drop index if exists "IDX_inventory_item_sku";') |
|
36
|
this.addSql( |
|
37
|
'CREATE UNIQUE INDEX IF NOT EXISTS "IDX_inventory_item_sku_unique" ON "inventory_item" (sku);' |
|
38
|
) |
|
39
|
|
|
40
|
this.addSql( |
|
41
|
'alter table if exists "inventory_level" alter column "stocked_quantity" type int using ("stocked_quantity"::int);' |
|
42
|
) |
|
43
|
this.addSql( |
|
44
|
'alter table if exists "inventory_level" alter column "reserved_quantity" type int using ("reserved_quantity"::int);' |
|
45
|
) |
|
46
|
this.addSql( |
|
47
|
'alter table if exists "inventory_level" alter column "incoming_quantity" type int using ("incoming_quantity"::int);' |
|
48
|
) |
|
49
|
this.addSql( |
|
50
|
'drop index if exists "IDX_inventory_level_location_id_inventory_item_id";' |
|
51
|
) |
|
52
|
this.addSql( |
|
53
|
'alter table if exists "inventory_level" drop column if exists "raw_stocked_quantity";' |
|
54
|
) |
|
55
|
this.addSql( |
|
56
|
'alter table if exists "inventory_level" drop column if exists "raw_reserved_quantity";' |
|
57
|
) |
|
58
|
this.addSql( |
|
59
|
'alter table if exists "inventory_level" drop column if exists "raw_incoming_quantity";' |
|
60
|
) |
|
61
|
|
|
62
|
this.addSql( |
|
63
|
'alter table if exists "reservation_item" alter column "quantity" type integer using ("quantity"::integer);' |
|
64
|
) |
|
65
|
this.addSql( |
|
66
|
'alter table if exists "reservation_item" drop column if exists "allow_backorder";' |
|
67
|
) |
|
68
|
this.addSql( |
|
69
|
'alter table if exists "reservation_item" drop column if exists "raw_quantity";' |
|
70
|
) |
|
71
|
} |
|
72
|
} |