Skip to content

symfonic.platform.working_pg_owner

working_pg_owner

Explicit, installer-owned PostgreSQL authority for opt-in Working sessions.

The HTTP session string is a lookup key, never proof of ownership. Installer provisioning is separate from the nonowner Working host's graph transaction.

PostgresWorkingOwner

PostgresWorkingOwner(pool, guard)
Source code in src/symfonic/platform/working_pg_owner.py
def __init__(self, pool, guard):
    if guard.pool is not pool:
        raise TypeError("Working owner and graph guard require one exact pool")
    self.pool, self.guard = pool, guard
    self.schema = guard.quoted_schema

install async

install(installer_pool)

Offline opt-in only; never called by graph ensure_schema or a request.

Source code in src/symfonic/platform/working_pg_owner.py
async def install(self, installer_pool):
    """Offline opt-in only; never called by graph ensure_schema or a request."""
    conn = await installer_pool.acquire()
    try:
        async with conn.transaction():
            await conn.execute("SET TRANSACTION ISOLATION LEVEL READ COMMITTED")
            await conn.execute("SET LOCAL lock_timeout = '5s'")
            await conn.execute(
                "SELECT pg_advisory_xact_lock("
                "hashtextextended('symfonic-working-owner-install',0))"
            )
            await self._installer(conn)
            exists = await conn.fetchval("SELECT to_regclass($1) IS NOT NULL", self.table)
            if not exists:
                await conn.execute(
                    f"CREATE TABLE {self.table} ("
                    'tenant_id text COLLATE "C" NOT NULL, '
                    'scope_path text COLLATE "C" NOT NULL, '
                    'session_id text COLLATE "C" NOT NULL, '
                    'principal_id text COLLATE "C" NOT NULL, '
                    "active boolean NOT NULL, "
                    "PRIMARY KEY (tenant_id, scope_path, session_id))"
                )
                await conn.execute(f"REVOKE ALL ON {self.table} FROM PUBLIC")
                await conn.execute(
                    f"GRANT SELECT ON {self.table} "
                    f'TO "{self.guard.working_host_role}"'
                )
                await conn.execute(
                    f"COMMENT ON TABLE {self.table} IS '{_MARKER}'"
                )
            await self._attest(conn)
    finally:
        await installer_pool.release(conn)