MCPcopy Create free account
hub / github.com/MetapriseAI/OrgKernel / init_db

Function init_db

src/orgkernel/database.py:76–96  ·  view source on GitHub ↗

Create all OrgKernel tables in the database. Call this once at application startup (after setting the engine URL). Args: engine: AsyncEngine to use. Defaults to the global async_engine. Note: On PostgreSQL, run ``CREATE EXTENSION IF NOT EXISTS pgcrypto;``

(engine: AsyncEngine | None = None)

Source from the content-addressed store, hash-verified

74
75
76async def init_db(engine: AsyncEngine | None = None) -> None:
77 """
78 Create all OrgKernel tables in the database.
79
80 Call this once at application startup (after setting the engine URL).
81
82 Args:
83 engine: AsyncEngine to use. Defaults to the global async_engine.
84
85 Note:
86 On PostgreSQL, run ``CREATE EXTENSION IF NOT EXISTS pgcrypto;`` first
87 to enable SHA-256 hashing functions.
88 """
89 global async_engine
90 target_engine = engine or async_engine
91 if target_engine is None:
92 raise RuntimeError(
93 "No engine set. Pass an engine argument or set orgkernel.database.async_engine.url first."
94 )
95 async with target_engine.begin() as conn:
96 await conn.run_sync(BaseModel.metadata.create_all)
97
98
99async def close_db() -> None:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected