hub-core/docs/metadata-isolation.md
tegwick 118d4fdcfe
Some checks failed
CI Smoke / host-smoke (push) Successful in 1s
CI Smoke / pytest-smoke (push) Failing after 2s
feat(ecosystem): hub-core library lane for three-repo stack (HUB-WP-0003)
Add slugify_or_default for core-hub parity, bump to 0.2.0, document ecosystem
position in INTENT/SCOPE/README, wire capability relations to state-hub and
core-hub, and extend utils tests. Part of CUST-WP-0057 consolidation.
2026-07-11 01:26:47 +02:00

38 lines
No EOL
1.1 KiB
Markdown

# SQLAlchemy Metadata Isolation
**Updated:** 2026-07-09
**Workplan:** `HUB-WP-0003-T03`
---
## Rule
`hub_core.models.base.Base` owns metadata for **shared primitive tables only**
(domains, managed_repos, agent_messages, progress_events, capability_*, tpsc_*).
Each host runtime keeps its own declarative base for host-specific tables:
| Host | Base module | Session style |
| --- | --- | --- |
| `state-hub` | `api.models.base.Base` | Sync |
| `core-hub` | `core_hub.db.Base` | Async |
Router factories never import host models from hub-core. Hosts inject models at
mount time:
```python
from hub_core.routers.domains import create_domains_router
app.include_router(create_domains_router(get_session, domain_model=Domain, ...))
```
---
## Why separate metadata
- Migration ownership stays with the host that runs the database.
- core-hub framework tables (`hubs`, `widgets`, …) must not appear in hub-core.
- state-hub dev-hub tables (workplans, tasks, …) must not appear in hub-core.
- Async and sync engines can coexist without forcing one base class.
See `the-custodian/docs/hub-ecosystem-architecture.md` for the full stack model.