feat(credential-store-migration): T2 D1 migration 0002_credentials.sql

新增 credentials 目錄表(api_key/name/service/sensitivity/secret_ref/
created_at/last_used_at,PRIMARY KEY(api_key,name) + idx_cred_apikey),
D19:只存目錄不存密文,密文本體改住 CF Workers per-script Secrets(T5)。

deploy.ts 重用既有 applyD1Migration,緊接 0001_base.sql 之後套用同一顆 D1,
機制完全一致(同一支 CF D1 query API)。

驗證:cli tsc --noEmit exit 0;leo21c arcrun-kbdb D1
(1099d0f3-d062-4202-984c-5a57b0a8c031)實際套用,
sqlite_master 確認 table+index 存在,重跑驗證冪等。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018D6QoC5waFkcjc2N7csJBB
This commit is contained in:
Claude
2026-07-03 22:52:09 +00:00
parent abf232327c
commit f9dad311ff
3 changed files with 45 additions and 1 deletions
+16
View File
@@ -264,6 +264,22 @@ export async function downloadAndDeploy(
} else {
failures.push(`D1 migration: 部署物缺 kbdb/migrations/0001_base.sql${migPath}`);
}
// 3.6 credential-primitives-wasm T2credential-store-migration.md §2.2):
// credentials 目錄表(api_key/name/service/sensitivity/secret_ref/created_at/last_used_at)。
// 同一顆 D1(與 KBDB base 共用),冪等 IF NOT EXISTS,套用機制與 0001_base.sql 完全相同
// (同一個 applyD1Migration helper,同一支 CF D1 query API)。D19:這張表不含密文,
// 密文本體住在 Workers per-script Secrets(見 cypher-executor/src/routes/credentials.ts)。
const credMigPath = join(root, 'kbdb', 'migrations', '0002_credentials.sql');
if (existsSync(credMigPath)) {
try {
await applyD1Migration(ctx, readFileSync(credMigPath, 'utf8'));
} catch (e) {
failures.push(`D1 migration 0002_credentials (${ctx.d1DatabaseId}): ${e instanceof Error ? e.message : String(e)}`);
}
} else {
failures.push(`D1 migration: 部署物缺 kbdb/migrations/0002_credentials.sql${credMigPath}`);
}
}
const cypherExecutorUrl = ctx.workerSubdomain