gabriel / musehub public
db.py python
35 lines 1.2 KB
Raw
sha256:20b27796ed512236119feef48b4577a8fd9ded05a15267dd4e6da23604ad1f1a docs: update Suggested Ownership Split table to reflect ful… Sonnet 5 28 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 3 commits
sha256:20b27796ed512236119feef48b4577a8fd9ded05a15267dd4e6da23604ad1f1a docs: update Suggested Ownership Split table to reflect ful… Sonnet 5 28 days ago
sha256:8ea2f75226d5834770ccaddbaa6efda1cc337446fd481bb385de8bec4555ae79 docs: Section 9 CI pipeline — confirm job queue is idempote… Sonnet 5 28 days ago
sha256:80e1a60a39562f6e616aaafbb27487f03abbec7d8ffc6164302b7a0c0bfc63ee docs: check off Section 0 items verified in inventory doc, … Sonnet 5 28 days ago