BE-PR-003: Add Essential SQLAlchemy model
- New app/models/essential.py with Essential model and EssentialType enum (feature, improvement, refactor) - Fields: id, essential_code (unique), proposal_id (FK to proposes), type, title, description, created_by_id (FK to users), created_at, updated_at - Added essentials relationship to Proposal model (cascade delete-orphan) - Added essentials table auto-migration in main.py _migrate_schema() - Registered essential module import in startup()
This commit is contained in:
59
app/models/essential.py
Normal file
59
app/models/essential.py
Normal file
@@ -0,0 +1,59 @@
|
||||
"""Essential model — actionable items under a Proposal.
|
||||
|
||||
Each Essential represents one deliverable scope item (feature, improvement,
|
||||
or refactor). When a Proposal is accepted, every Essential is converted into
|
||||
a corresponding ``story/*`` task under the chosen Milestone.
|
||||
|
||||
See: NEXT_WAVE_DEV_DIRECTION.md §8.5
|
||||
"""
|
||||
|
||||
from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey, Enum
|
||||
from sqlalchemy.sql import func
|
||||
from app.core.config import Base
|
||||
import enum
|
||||
|
||||
|
||||
class EssentialType(str, enum.Enum):
|
||||
FEATURE = "feature"
|
||||
IMPROVEMENT = "improvement"
|
||||
REFACTOR = "refactor"
|
||||
|
||||
|
||||
class Essential(Base):
|
||||
__tablename__ = "essentials"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
|
||||
essential_code = Column(
|
||||
String(64),
|
||||
nullable=False,
|
||||
unique=True,
|
||||
index=True,
|
||||
comment="Unique human-readable code, e.g. PROJ:E00001",
|
||||
)
|
||||
|
||||
proposal_id = Column(
|
||||
Integer,
|
||||
ForeignKey("proposes.id"), # FK targets the actual DB table name
|
||||
nullable=False,
|
||||
comment="Owning Proposal",
|
||||
)
|
||||
|
||||
type = Column(
|
||||
Enum(EssentialType, values_callable=lambda x: [e.value for e in x]),
|
||||
nullable=False,
|
||||
comment="Essential type: feature | improvement | refactor",
|
||||
)
|
||||
|
||||
title = Column(String(255), nullable=False, comment="Short title")
|
||||
description = Column(Text, nullable=True, comment="Detailed description")
|
||||
|
||||
created_by_id = Column(
|
||||
Integer,
|
||||
ForeignKey("users.id"),
|
||||
nullable=True,
|
||||
comment="Author of the essential",
|
||||
)
|
||||
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
||||
Reference in New Issue
Block a user