UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

84 lines (83 loc) • 3.73 kB
import { t as _usingCtx } from "../usingCtx-rhpPzaNq.mjs"; import { o as getAdmittedSqliteSchemaFacts, w as getPostgresPhysicalFacts } from "../sqlite-schema-facts-B1bVE8IB.mjs"; import { n as openNodeSqliteDatabase } from "../node-sqlite-CU4puofF.mjs"; import { l as prepareSqliteReadOnlyLocationSyncInProcess } from "../sqlite-readonly-location-BMysMNE5.mjs"; import { n as getDatabaseEngineSelection } from "../context-DE59wyBs.mjs"; import { r as runEngineStoreReadSnapshot } from "../adapters-D8O-uubH.mjs"; import { s as openExistingStatePostgresConnectionFromAnchor } from "../openclaw-state-db-engine-sM0tpxNy.mjs"; import { o as readStateSchemaContentVersion } from "../openclaw-state-db-schema-version-uNbDFl6T.mjs"; import { l as isNativeClientCredentialBootstrap } from "../client-credential-store-rd7DZXgD.mjs"; import { t as readBackupEngine } from "../physical-store-BRXG56Jw.mjs"; import { a as withPostgresStoreMetadata } from "../postgres-store-metadata-CcC14HrG.mjs"; import { n as serveWorkerTasks } from "../worker-task-server-J1vG-XRl.mjs"; import { t as collectRegisteredPaths } from "../update-candidate-state.shared-DZplVITw.mjs"; import { i as readUpdateCandidatePluginIndex } from "../update-candidate-plugins-BEGL3jNW.mjs"; import { t as readUpdateHeldAgentPaths } from "../update-candidate-state.retained-t5hcZxpV.mjs"; import path from "node:path"; //#region src/infra/update-candidate-state.postgres.worker.ts serveWorkerTasks(async ({ input: e, files: t, sourcePath: n }) => { if (n) { const e = readBackupEngine(n); if (e.engine !== "postgres") throw new Error("PostgreSQL update inspection requires a PostgreSQL anchor."); const r = getDatabaseEngineSelection()?.postgres; if (!r) throw new Error("PostgreSQL update inspection requires the captured connection."); return withPostgresStoreMetadata(r, e, async (e, n) => ({ files: t, version: { userVersion: n.version } })); } const r = path.resolve(e.stateDir, "state", "openclaw.sqlite"); if (readBackupEngine(r).engine !== "postgres") { const e = prepareSqliteReadOnlyLocationSyncInProcess(r); try { try { var i = _usingCtx(); const n = i.u(openNodeSqliteDatabase(e.location, { readOnly: true })); const r = isNativeClientCredentialBootstrap(n); const a = getAdmittedSqliteSchemaFacts(n); const o = a.userVersion === 0 && !a.tables.size && !a.indexes.size && !a.views.size && !a.triggers.size; if (r) throw new Error("Native credential bootstrap cannot become a PostgreSQL anchor. Start the Gateway once on SQLite and run openclaw doctor --fix, then use openclaw database port before selecting PostgreSQL."); if (!o) throw new Error("PostgreSQL update preflight requires the matching state anchor."); return { files: t, version: { userVersion: 0, contentVersion: 0 }, pluginIndex: { value: { index: { installRecords: {} } }, records: {} } }; } catch (e) { i.e = e; } finally { i.d(); } } finally { e.cleanup(); } } const a = openExistingStatePostgresConnectionFromAnchor(openNodeSqliteDatabase(r, { readOnly: true }), r); const { db: o } = a.database; try { return runEngineStoreReadSnapshot(o, () => { const n = new Map(t); const i = collectRegisteredPaths(o, r, n); const a = e.includeRetainedAgentPaths ? readUpdateHeldAgentPaths(o, r, n.values(), i, e) : []; return { version: { userVersion: getPostgresPhysicalFacts(o).version, contentVersion: readStateSchemaContentVersion(o), ...a.length ? { retainedAgentPaths: a } : {} }, pluginIndex: readUpdateCandidatePluginIndex(o), files: [...n] }; }); } finally { a.close(); } }); //#endregion export {};