gabriel / musehub public
musehub_label_models.py python
86 lines 3.1 KB
Raw
sha256:fc04e4cae9e1774d6a21b65c45daeed0e6787eb581d13aa1b03bfe9384a34226 Merge branch 'fix/two-column-scroll-layout' into dev Human 8 days ago
1 """SQLAlchemy ORM models for MuseHub label tables.
2
3 Tables:
4 - musehub_labels: Coloured label definitions scoped to a repo
5 - musehub_proposal_labels: Many-to-many join between proposals and labels
6
7 Note: issues store labels as a denormalized ARRAY(Text) on musehub_issues.labels —
8 there is no issue-label junction table. Proposals use the junction table because
9 the assignment flow goes through label_id FKs; issues use the ARRAY because
10 the assignment flow stores names directly.
11 """
12
13 from datetime import datetime, timezone
14
15 from sqlalchemy import DateTime, ForeignKey, Index, String, UniqueConstraint
16 from sqlalchemy.orm import Mapped, MappedAsDataclass, mapped_column, relationship
17
18 from musehub.db.database import Base
19
20 def _utc_now() -> datetime:
21 return datetime.now(tz=timezone.utc)
22
23 class MusehubLabel(MappedAsDataclass, Base):
24 """A coloured label tag that can be applied to issues and proposals.
25
26 Labels are scoped to a repo — the same name may exist across repos with
27 different colours. The UNIQUE(repo_id, name) constraint enforces uniqueness
28 within a repo. ``color`` stores a hex string like ``#d73a4a``.
29
30 ``label_id`` is genesis-addressed: sha256(repo_id NUL name NUL created_at_iso).
31 """
32
33 __tablename__ = "musehub_labels"
34 __table_args__ = (
35 UniqueConstraint("repo_id", "name", name="uq_musehub_labels_repo_name"),
36 Index("ix_musehub_labels_repo_id", "repo_id"),
37 )
38
39 # --- Required fields ---
40 id: Mapped[str] = mapped_column(String(128), primary_key=True)
41 repo_id: Mapped[str] = mapped_column(
42 String(128),
43 ForeignKey("musehub_repos.repo_id", ondelete="CASCADE"),
44 nullable=False,
45 )
46 name: Mapped[str] = mapped_column(String(50), nullable=False)
47 # Hex colour string, e.g. "#d73a4a"
48 color: Mapped[str] = mapped_column(String(7), nullable=False)
49
50 # --- Optional fields with Python-side defaults ---
51 description: Mapped[str | None] = mapped_column(String(200), nullable=True, default=None)
52 created_at: Mapped[datetime] = mapped_column(
53 DateTime(timezone=True), nullable=False, default_factory=_utc_now
54 )
55
56 proposal_labels: Mapped[list[MusehubProposalLabel]] = relationship(
57 "MusehubProposalLabel", back_populates="label", cascade="all, delete-orphan",
58 init=False, default_factory=list,
59 )
60
61 class MusehubProposalLabel(Base):
62 """Join table linking proposals to labels.
63
64 Composite primary key on (proposal_id, label_id). Both sides cascade-delete
65 so removing a proposal or a label automatically cleans up the association.
66 """
67
68 __tablename__ = "musehub_proposal_labels"
69 __table_args__ = (
70 Index("ix_musehub_proposal_labels_label_id", "label_id"),
71 )
72
73 proposal_id: Mapped[str] = mapped_column(
74 String(128),
75 ForeignKey("musehub_proposals.proposal_id", ondelete="CASCADE"),
76 primary_key=True,
77 )
78 label_id: Mapped[str] = mapped_column(
79 String(128),
80 ForeignKey("musehub_labels.id", ondelete="CASCADE"),
81 primary_key=True,
82 )
83
84 label: Mapped[MusehubLabel] = relationship(
85 "MusehubLabel", back_populates="proposal_labels"
86 )
File History 13 commits
sha256:fc04e4cae9e1774d6a21b65c45daeed0e6787eb581d13aa1b03bfe9384a34226 Merge branch 'fix/two-column-scroll-layout' into dev Human 8 days ago
sha256:408916fc5973ba59c6e4eebaa80ebdcc801c0a63205651e25009d11548f79454 chore: bump version to 0.2.0.dev2 — nightly.2, matching muse Sonnet 4.6 patch 11 days ago
sha256:d035733f21ccff27735fddebfbbe0ed24565a32a22db8de5885402262671ecd2 chore: bump version to 0.2.0rc15 for musehub#113 fix release Sonnet 4.6 patch 14 days ago
sha256:0032d6cfa33bc3c8367436ad768e7dd0e339b4332153160247da8266cb5fa352 Merge branch 'task/version-tags-phase3-server' into dev Human 17 days ago
sha256:4669620efda9ff41c55bdefd1f7bfe1c239d468428744c84ead9957e5a003a53 merge: rescue snapshot-recovery hardening (c00aa21d) into d… Opus 4.8 minor 29 days ago
sha256:a59da49c4611b970fc4b6ae48678ce4943261c213a07ddbd73ce9201df869b4a fix: remove false-positive proposal_comments index drop fro… Sonnet 4.6 patch 33 days ago
sha256:0a240d6dbff234f07d98a28a4a9a68db702f3f9ff9260196f24219bdb1c0b6f3 feat: render markdown mists as HTML with heading anchor links Sonnet 4.6 patch 34 days ago
sha256:24a7d47486ebc4ebd1832830580e177ec6f877b48dced8c000e198cdec4ce9d6 Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump … Human 35 days ago
sha256:b9ff931d147e0114a1f17060f415b89ed551c170a91ff226c70437aa5c85f9ee Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump … Human 35 days ago
sha256:d1122d21e73471879b460037b22c0b50fded7c423444a176f248428f75dac39c Merge 'task/fix-issue-pagination-cursor' into 'dev' — propo… Human 35 days ago
sha256:01e18975e73d2b3cd5b6db7929c895bef9aa6e0d4391dc5b2adfc548b41318dd Merge 'feat/adding-debug-logs-to-staging' into 'dev' — prop… Human 35 days ago
sha256:6b1949fc2797ca4c1936a637a4cbfec828ef56cf52398a2e74ca3c4f494e728f fix: use wire_bytes not mpack_bytes_raw in compute_object_b… Sonnet 4.6 patch 48 days ago
sha256:b99f2455dc346966d040133f5203297e6e3ef5803a93728a2c30568d0a0f7583 rename: delta_add → delta_upsert across wire format, models… Sonnet 4.6 patch 50 days ago