import type { Kysely } from "kysely"; import { dropTables, execDdl } from "../src/migration-helpers.ts"; // C2-A 缓存:移植 MP app/runtime/cache.py 的 TTLCache(cachetools TLRUCache:按 region 分区、每个 key 独立 TTL、 // maxsize 超限先删过期再删最久未用),存储从进程内存换成 PG UNLOGGED 表(不写 WAL,崩溃后清空,正合缓存语义),三进程共享。 // expires_at 过期即视为未命中;accessed_at 为最近读写时间(LRU 依据);定时任务 cache.sweep 每 10 分钟删过期行。 // biome-ignore lint/suspicious/noExplicitAny: 迁移不依赖应用表类型 export async function up(db: Kysely): Promise { await execDdl( db, ` create unlogged table kv_cache ( region text not null, key text not null, value jsonb not null, expires_at timestamptz not null, updated_at timestamptz not null default now(), accessed_at timestamptz not null default now(), primary key (region, key) ); create index kv_cache_expires_idx on kv_cache (expires_at); `, ); } // biome-ignore lint/suspicious/noExplicitAny: 同上 export async function down(db: Kysely): Promise { await execDdl(db, dropTables(["kv_cache"])); }