openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
5 lines • 2.3 kB
JavaScript
import{c as quoteSqliteIdentifier}from"./sqlite-schema-sql-D2HdV_QG.js";
//!src/infra/database-engine/registry.ts
const stores=[{id:`state`,label:`Shared state`,postgres:true},{id:`agent`,label:`Agent data`,postgres:true},{id:`workboard`,label:`Workboard`,postgres:true},{id:`logbook`,label:`Logbook`,postgres:true},{id:`team-reports`,label:`Team Reports`,postgres:true},{id:`quarantine`,label:`Database quarantine`},{id:`managed-update`,label:`Managed update handoffs`},{id:`package-activation`,label:`Package activation journal`}];function listDatabaseEngineStores(){return stores}
//!src/infra/database-engine/postgres-store-metadata.ts
var DatabasePortDataError=class extends Error{};async function withPostgresConnection(e,t,n){const{Client:r}=await import(`pg`);const 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(e,t){const n=await e.query(`SELECT store, store_id, version FROM ${quoteSqliteIdentifier(t.namespace)}.openclaw_schema_meta`).then(e=>e.rows,async()=>{await assertDatabasePortNamespaceOwner(e,t.namespace);throw new DatabasePortDataError(`Cannot resolve PostgreSQL anchor family; use a compatible binary or restore its matched backup.`)});const r=n[0];if(n.length!==1||!r||r.store_id!==t.storeId)throw new DatabasePortDataError(`PostgreSQL anchor does not match its store metadata`);const i=Number(r.version);if(!/^\d+$/u.test(r.version)||!Number.isSafeInteger(i))throw new DatabasePortDataError(`PostgreSQL store metadata has an invalid schema version`);if(!listDatabaseEngineStores().some(e=>e.postgres&&e.id===r.store))throw new DatabasePortDataError(`Unknown PostgreSQL anchor family; use a compatible binary.`);return{store:r.store,version:i}}function withPostgresStoreMetadata(e,t,n){return withPostgresConnection(e,async e=>n(e,await readPostgresStoreMetadata(e,t)))}export{withPostgresStoreMetadata};