1 import { Migration } from "@medusajs/framework/mikro-orm/migrations"
2
3 export class Migration20241211061114 extends Migration {
4 async up(): Promise<void> {
5 this.addSql(
6 'alter table if exists "promotion_campaign_budget" drop constraint if exists "promotion_campaign_budget_campaign_id_foreign";'
7 )
8
9 this.addSql(
10 'CREATE INDEX IF NOT EXISTS "IDX_promotion_campaign_deleted_at" ON "promotion_campaign" (deleted_at) WHERE deleted_at IS NULL;'
11 )
12
13 this.addSql(
14 'alter table if exists "promotion_campaign_budget" add constraint "promotion_campaign_budget_campaign_id_foreign" foreign key ("campaign_id") references "promotion_campaign" ("id") on update cascade on delete cascade;'
15 )
16 this.addSql(
17 'CREATE INDEX IF NOT EXISTS "IDX_promotion_campaign_budget_campaign_id" ON "promotion_campaign_budget" (campaign_id) WHERE deleted_at IS NULL;'
18 )
19 this.addSql(
20 'CREATE INDEX IF NOT EXISTS "IDX_promotion_campaign_budget_deleted_at" ON "promotion_campaign_budget" (deleted_at) WHERE deleted_at IS NULL;'
21 )
22
23 this.addSql(
24 'CREATE INDEX IF NOT EXISTS "IDX_promotion_campaign_id" ON "promotion" (campaign_id) WHERE deleted_at IS NULL;'
25 )
26 this.addSql(
27 'CREATE INDEX IF NOT EXISTS "IDX_promotion_deleted_at" ON "promotion" (deleted_at) WHERE deleted_at IS NULL;'
28 )
29
30 this.addSql(
31 'alter table if exists "promotion_application_method" alter column "value" type numeric using ("value"::numeric);'
32 )
33 this.addSql(
34 'alter table if exists "promotion_application_method" alter column "value" drop not null;'
35 )
36 this.addSql(
37 'alter table if exists "promotion_application_method" alter column "raw_value" type jsonb using ("raw_value"::jsonb);'
38 )
39 this.addSql(
40 'alter table if exists "promotion_application_method" alter column "raw_value" drop not null;'
41 )
42 this.addSql(
43 'alter table if exists "promotion_application_method" alter column "max_quantity" type integer using ("max_quantity"::integer);'
44 )
45 this.addSql(
46 'alter table if exists "promotion_application_method" alter column "apply_to_quantity" type integer using ("apply_to_quantity"::integer);'
47 )
48 this.addSql(
49 'alter table if exists "promotion_application_method" alter column "buy_rules_min_quantity" type integer using ("buy_rules_min_quantity"::integer);'
50 )
51 this.addSql(
52 'CREATE INDEX IF NOT EXISTS "IDX_promotion_application_method_promotion_id" ON "promotion_application_method" (promotion_id) WHERE deleted_at IS NULL;'
53 )
54 this.addSql(
55 'CREATE INDEX IF NOT EXISTS "IDX_promotion_application_method_deleted_at" ON "promotion_application_method" (deleted_at) WHERE deleted_at IS NULL;'
56 )
57
58 this.addSql(
59 'CREATE INDEX IF NOT EXISTS "IDX_promotion_rule_deleted_at" ON "promotion_rule" (deleted_at) WHERE deleted_at IS NULL;'
60 )
61
62 this.addSql(
63 'drop index if exists "IDX_promotion_rule_promotion_rule_value_id";'
64 )
65 this.addSql(
66 'CREATE INDEX IF NOT EXISTS "IDX_promotion_rule_value_promotion_rule_id" ON "promotion_rule_value" (promotion_rule_id) WHERE deleted_at IS NULL;'
67 )
68 this.addSql(
69 'CREATE INDEX IF NOT EXISTS "IDX_promotion_rule_value_deleted_at" ON "promotion_rule_value" (deleted_at) WHERE deleted_at IS NULL;'
70 )
71 }
72
73 async down(): Promise<void> {
74 this.addSql(
75 'alter table if exists "promotion_campaign_budget" drop constraint if exists "promotion_campaign_budget_campaign_id_foreign";'
76 )
77
78 this.addSql('drop index if exists "IDX_promotion_campaign_deleted_at";')
79
80 this.addSql(
81 'drop index if exists "IDX_promotion_campaign_budget_campaign_id";'
82 )
83 this.addSql(
84 'drop index if exists "IDX_promotion_campaign_budget_deleted_at";'
85 )
86 this.addSql(
87 'alter table if exists "promotion_campaign_budget" add constraint "promotion_campaign_budget_campaign_id_foreign" foreign key ("campaign_id") references "promotion_campaign" ("id") on update cascade;'
88 )
89
90 this.addSql('drop index if exists "IDX_promotion_campaign_id";')
91 this.addSql('drop index if exists "IDX_promotion_deleted_at";')
92
93 this.addSql(
94 'alter table if exists "promotion_application_method" alter column "value" type numeric using ("value"::numeric);'
95 )
96 this.addSql(
97 'alter table if exists "promotion_application_method" alter column "value" set not null;'
98 )
99 this.addSql(
100 'alter table if exists "promotion_application_method" alter column "max_quantity" type numeric using ("max_quantity"::numeric);'
101 )
102 this.addSql(
103 'alter table if exists "promotion_application_method" alter column "apply_to_quantity" type numeric using ("apply_to_quantity"::numeric);'
104 )
105 this.addSql(
106 'alter table if exists "promotion_application_method" alter column "buy_rules_min_quantity" type numeric using ("buy_rules_min_quantity"::numeric);'
107 )
108 this.addSql(
109 'alter table if exists "promotion_application_method" alter column "raw_value" type jsonb using ("raw_value"::jsonb);'
110 )
111 this.addSql(
112 'alter table if exists "promotion_application_method" alter column "raw_value" set not null;'
113 )
114 this.addSql(
115 'drop index if exists "IDX_promotion_application_method_promotion_id";'
116 )
117 this.addSql(
118 'drop index if exists "IDX_promotion_application_method_deleted_at";'
119 )
120
121 this.addSql('drop index if exists "IDX_promotion_rule_deleted_at";')
122
123 this.addSql(
124 'drop index if exists "IDX_promotion_rule_value_promotion_rule_id";'
125 )
126 this.addSql('drop index if exists "IDX_promotion_rule_value_deleted_at";')
127 this.addSql(
128 'create index if not exists "IDX_promotion_rule_promotion_rule_value_id" on "promotion_rule_value" ("promotion_rule_id");'
129 )
130 }
131 }