|
1
|
import { Migration } from "@medusajs/framework/mikro-orm/migrations"; |
|
2
|
|
|
3
|
export class Migration20260903085616 extends Migration { |
|
4
|
|
|
5
|
override async up(): Promise<void> { |
|
6
|
this.addSql(`create table if not exists "search_index_version" ("id" text not null, "version" integer not null, "provider" text not null, "physical_name" text not null, "definition_hash" text not null, "status" text check ("status" in ('pending', 'building', 'ready', 'error')) not null default 'pending', "search_index_id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "search_index_version_pkey" primary key ("id"));`); |
|
7
|
this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_search_index_version_search_index_id" ON "search_index_version" ("search_index_id") WHERE deleted_at IS NULL;`); |
|
8
|
this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_search_index_version_deleted_at" ON "search_index_version" ("deleted_at") WHERE deleted_at IS NULL;`); |
|
9
|
this.addSql(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_search_index_version_search_index_id_version" ON "search_index_version" ("search_index_id", "version") WHERE deleted_at IS NULL;`); |
|
10
|
|
|
11
|
this.addSql(`alter table if exists "search_index_version" add constraint "search_index_version_search_index_id_foreign" foreign key ("search_index_id") references "search_index" ("id") on update cascade;`); |
|
12
|
|
|
13
|
this.addSql(`alter table if exists "search_index_sync" drop constraint if exists "search_index_sync_search_index_id_foreign";`); |
|
14
|
|
|
15
|
this.addSql(`alter table if exists "search_index" drop column if exists "provider", drop column if exists "status", drop column if exists "definition_hash";`); |
|
16
|
|
|
17
|
this.addSql(`alter table if exists "search_index" add column if not exists "active_version" integer null;`); |
|
18
|
|
|
19
|
this.addSql(`drop index if exists "IDX_search_index_sync_search_index_id";`); |
|
20
|
|
|
21
|
this.addSql(`alter table if exists "search_index_sync" rename column "search_index_id" to "search_index_version_id";`); |
|
22
|
this.addSql(`alter table if exists "search_index_sync" add constraint "search_index_sync_search_index_version_id_foreign" foreign key ("search_index_version_id") references "search_index_version" ("id") on update cascade;`); |
|
23
|
this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_search_index_sync_search_index_version_id" ON "search_index_sync" ("search_index_version_id") WHERE deleted_at IS NULL;`); |
|
24
|
} |
|
25
|
|
|
26
|
override async down(): Promise<void> { |
|
27
|
this.addSql(`alter table if exists "search_index_sync" drop constraint if exists "search_index_sync_search_index_version_id_foreign";`); |
|
28
|
|
|
29
|
this.addSql(`drop table if exists "search_index_version" cascade;`); |
|
30
|
|
|
31
|
this.addSql(`alter table if exists "search_index" drop column if exists "active_version";`); |
|
32
|
|
|
33
|
this.addSql(`alter table if exists "search_index" add column if not exists "provider" text not null, add column if not exists "status" text check ("status" in ('pending', 'building', 'ready', 'error')) not null default 'pending', add column if not exists "definition_hash" text not null;`); |
|
34
|
|
|
35
|
this.addSql(`drop index if exists "IDX_search_index_sync_search_index_version_id";`); |
|
36
|
|
|
37
|
this.addSql(`alter table if exists "search_index_sync" rename column "search_index_version_id" to "search_index_id";`); |
|
38
|
this.addSql(`alter table if exists "search_index_sync" add constraint "search_index_sync_search_index_id_foreign" foreign key ("search_index_id") references "search_index" ("id") on update cascade;`); |
|
39
|
this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_search_index_sync_search_index_id" ON "search_index_sync" ("search_index_id") WHERE deleted_at IS NULL;`); |
|
40
|
} |
|
41
|
|
|
42
|
} |