UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 1.72 kB
import{t as e}from"./transcript-registry-D6P1uVts.mjs";import{c as t}from"./transcript-sqlite-schema-sql-BnVx4b5A.mjs";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(n,r){let i=await n.query(`SELECT store, store_id, version FROM ${t(r.namespace)}.openclaw_schema_meta`).then(e=>e.rows,async()=>{throw await assertDatabasePortNamespaceOwner(n,r.namespace),new DatabasePortDataError(`Cannot resolve PostgreSQL anchor family; use a compatible binary or restore its matched backup.`)}),a=i[0];if(i.length!==1||!a||a.store_id!==r.storeId)throw new DatabasePortDataError(`PostgreSQL anchor does not match its store metadata`);let o=Number(a.version);if(!/^\d+$/u.test(a.version)||!Number.isSafeInteger(o))throw new DatabasePortDataError(`PostgreSQL store metadata has an invalid schema version`);if(!e().some(e=>e.postgres&&e.id===a.store))throw new DatabasePortDataError(`Unknown PostgreSQL anchor family; use a compatible binary.`);return{store:a.store,version:o}}function withPostgresStoreMetadata(e,t,n){return withPostgresConnection(e,async e=>n(e,await readPostgresStoreMetadata(e,t)))}export{withPostgresStoreMetadata};