|
1
|
import { Migration } from "@medusajs/framework/mikro-orm/migrations" |
|
2
|
|
|
3
|
export class Migration20251208124155 extends Migration { |
|
4
|
override async up(): Promise<void> { |
|
5
|
this.addSql( |
|
6
|
`alter table if exists "translation" drop constraint if exists "translation_reference_id_locale_code_unique";` |
|
7
|
) |
|
8
|
this.addSql( |
|
9
|
`alter table if exists "locale" drop constraint if exists "locale_code_unique";` |
|
10
|
) |
|
11
|
this.addSql( |
|
12
|
`create table if not exists "locale" ("id" text not null, "code" text not null, "name" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "locale_pkey" primary key ("id"));` |
|
13
|
) |
|
14
|
this.addSql( |
|
15
|
`CREATE INDEX IF NOT EXISTS "IDX_locale_deleted_at" ON "locale" ("deleted_at") WHERE deleted_at IS NULL;` |
|
16
|
) |
|
17
|
this.addSql( |
|
18
|
`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_locale_code_unique" ON "locale" ("code") WHERE deleted_at IS NULL;` |
|
19
|
) |
|
20
|
|
|
21
|
this.addSql( |
|
22
|
`create table if not exists "translation" ("id" text not null, "reference_id" text not null, "reference" text not null, "locale_code" text not null, "translations" jsonb not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "translation_pkey" primary key ("id"));` |
|
23
|
) |
|
24
|
this.addSql( |
|
25
|
`CREATE INDEX IF NOT EXISTS "IDX_translation_deleted_at" ON "translation" ("deleted_at") WHERE deleted_at IS NULL;` |
|
26
|
) |
|
27
|
this.addSql( |
|
28
|
`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_translation_reference_id_locale_code_unique" ON "translation" ("reference_id", "locale_code") WHERE deleted_at IS NULL;` |
|
29
|
) |
|
30
|
this.addSql( |
|
31
|
`CREATE INDEX IF NOT EXISTS "IDX_translation_reference_id_reference_locale_code" ON "translation" ("reference_id", "reference", "locale_code") WHERE deleted_at IS NULL;` |
|
32
|
) |
|
33
|
this.addSql( |
|
34
|
`CREATE INDEX IF NOT EXISTS "IDX_translation_reference_locale_code" ON "translation" ("reference", "locale_code") WHERE deleted_at IS NULL;` |
|
35
|
) |
|
36
|
this.addSql( |
|
37
|
`CREATE INDEX IF NOT EXISTS "IDX_translation_reference_id_reference" ON "translation" ("reference_id", "reference") WHERE deleted_at IS NULL;` |
|
38
|
) |
|
39
|
this.addSql( |
|
40
|
`CREATE INDEX IF NOT EXISTS "IDX_translation_locale_code" ON "translation" ("locale_code") WHERE deleted_at IS NULL;` |
|
41
|
) |
|
42
|
} |
|
43
|
|
|
44
|
override async down(): Promise<void> { |
|
45
|
this.addSql(`drop table if exists "locale" cascade;`) |
|
46
|
|
|
47
|
this.addSql(`drop table if exists "translation" cascade;`) |
|
48
|
} |
|
49
|
} |