openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.14 kB
JavaScript
import{c as e}from"./sqlite-readonly-sqlite-schema-sql-BnVx4b5A.mjs";const t=[{id:`state`,label:`Shared state`,postgres:!0},{id:`agent`,label:`Agent data`,postgres:!0},{id:`workboard`,label:`Workboard`,postgres:!0},{id:`logbook`,label:`Logbook`,postgres:!0},{id:`team-reports`,label:`Team Reports`,postgres:!0},{id:`quarantine`,label:`Database quarantine`},{id:`managed-update`,label:`Managed update handoffs`},{id:`package-activation`,label:`Package activation journal`}];function listDatabaseEngineStores(){return t}var DatabasePortDataError=class extends Error{};async function withPostgresConnection(e,t,n){let{Client:r}=await import(`pg`),i=new r({connectionString:e.connection,...n});i.on(`error`,()=>void 0),await i.connect();try{return await t(i)}finally{await i.end()}}async function assertDatabasePortNamespaceOwner(e,t){if(!(await e.query(`SELECT nspowner = (SELECT oid FROM pg_roles WHERE rolname = current_user) AS owned FROM pg_namespace WHERE nspname = $1`,[t])).rows[0]?.owned)throw new DatabasePortDataError(`observed missing namespace or different owner; required namespace owned by the configured role`)}async function readPostgresStoreMetadata(t,n){let r=await t.query(`SELECT store, store_id, version FROM ${e(n.namespace)}.openclaw_schema_meta`).then(e=>e.rows,async()=>{throw await assertDatabasePortNamespaceOwner(t,n.namespace),new DatabasePortDataError(`Cannot resolve PostgreSQL anchor family; use a compatible binary or restore its matched backup.`)}),i=r[0];if(r.length!==1||!i||i.store_id!==n.storeId)throw new DatabasePortDataError(`PostgreSQL anchor does not match its store metadata`);let a=Number(i.version);if(!/^\d+$/u.test(i.version)||!Number.isSafeInteger(a))throw new DatabasePortDataError(`PostgreSQL store metadata has an invalid schema version`);if(!listDatabaseEngineStores().some(e=>e.postgres&&e.id===i.store))throw new DatabasePortDataError(`Unknown PostgreSQL anchor family; use a compatible binary.`);return{store:i.store,version:a}}function withPostgresStoreMetadata(e,t,n){return withPostgresConnection(e,async e=>n(e,await readPostgresStoreMetadata(e,t)))}export{withPostgresStoreMetadata};