|
1
|
import { Migration } from "@medusajs/framework/mikro-orm/migrations" |
|
2
|
|
|
3
|
export class Migration20250515161913 extends Migration { |
|
4
|
override async up(): Promise<void> { |
|
5
|
this.addSql(` |
|
6
|
DO $$ |
|
7
|
DECLARE |
|
8
|
r RECORD; |
|
9
|
protected_tables TEXT[] := ARRAY[ |
|
10
|
'cat_linkproductsaleschannel', |
|
11
|
'cat_linkproductvariantpriceset', |
|
12
|
'cat_price', |
|
13
|
'cat_priceset', |
|
14
|
'cat_product', |
|
15
|
'cat_productvariant', |
|
16
|
'cat_saleschannel', |
|
17
|
'cat_pivot_linkproductsaleschannelsaleschannel', |
|
18
|
'cat_pivot_linkproductvariantpricesetpriceset', |
|
19
|
'cat_pivot_pricesetprice', |
|
20
|
'cat_pivot_productlinkproductsaleschannel', |
|
21
|
'cat_pivot_productproductvariant', |
|
22
|
'cat_pivot_productvariantlinkproductvariantpriceset' |
|
23
|
]; |
|
24
|
BEGIN |
|
25
|
FOR r IN |
|
26
|
SELECT tablename |
|
27
|
FROM pg_tables |
|
28
|
WHERE schemaname = 'public' AND tablename LIKE 'cat\_%' |
|
29
|
LOOP |
|
30
|
IF r.tablename <> ALL (protected_tables) THEN |
|
31
|
EXECUTE format('DROP TABLE IF EXISTS public.%I CASCADE;', r.tablename); |
|
32
|
END IF; |
|
33
|
END LOOP; |
|
34
|
END $$; |
|
35
|
|
|
36
|
UPDATE index_sync SET last_key = NULL WHERE entity NOT IN ( |
|
37
|
'Product', |
|
38
|
'ProductVariant', |
|
39
|
'LinkProductVariantPriceSet', |
|
40
|
'LinkProductSalesChannel', |
|
41
|
'Price', |
|
42
|
'PriceSet', |
|
43
|
'SalesChannel' |
|
44
|
); |
|
45
|
|
|
46
|
UPDATE index_metadata SET status = 'pending' WHERE entity NOT IN ( |
|
47
|
'Product', |
|
48
|
'ProductVariant', |
|
49
|
'LinkProductVariantPriceSet', |
|
50
|
'LinkProductSalesChannel', |
|
51
|
'Price', |
|
52
|
'PriceSet', |
|
53
|
'SalesChannel' |
|
54
|
); |
|
55
|
`) |
|
56
|
} |
|
57
|
|
|
58
|
override async down(): Promise<void> {} |
|
59
|
} |