gabriel / musehub public
db.py python
35 lines 1.2 KB
Raw
sha256:f65847c6a4ae29872f3ccbc2420f91a8948949b84a06320bdaf2ac281c89ff8a docs(F7b): governance sync — BUILT awaiting Gabriel; carry … Human patch 29 days ago
1 """DB helpers for MuseHub test fixtures.
2
3 Provides insert_commit and upsert_snapshot for populating the
4 muse_commits table in tests.
5 """
6
7 import logging
8
9 from muse.core.types import short_id
10 from sqlalchemy.ext.asyncio import AsyncSession
11
12 from musehub.db.muse_cli_models import MuseCliCommit, MuseCliSnapshot
13 from musehub.types.json_types import StrDict
14
15 logger = logging.getLogger(__name__)
16
17
18 async def upsert_snapshot(
19 session: AsyncSession, manifest: StrDict, snapshot_id: str
20 ) -> MuseCliSnapshot:
21 """Insert a MuseCliSnapshot row, ignoring duplicates."""
22 existing = await session.get(MuseCliSnapshot, snapshot_id)
23 if existing is not None:
24 logger.debug("⚠️ Snapshot %s already exists — skipped", short_id(snapshot_id))
25 return existing
26 snap = MuseCliSnapshot(snapshot_id=snapshot_id, manifest=manifest)
27 session.add(snap)
28 logger.debug("✅ New snapshot %s (%d files)", short_id(snapshot_id), len(manifest))
29 return snap
30
31
32 async def insert_commit(session: AsyncSession, commit: MuseCliCommit) -> None:
33 """Insert a new MuseCliCommit row."""
34 session.add(commit)
35 logger.debug("✅ New commit %s branch=%r", short_id(commit.commit_id), commit.branch)
File History 2 commits
sha256:f65847c6a4ae29872f3ccbc2420f91a8948949b84a06320bdaf2ac281c89ff8a docs(F7b): governance sync — BUILT awaiting Gabriel; carry … Human patch 29 days ago
sha256:417c976b0b9320bb758749eb014d9087354fa3186e2abd2fc949e74a670237e7 merge(F7b B1): carry overseer provenance onto dev; resolve … Human minor 29 days ago