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:
23
app/main.py
23
app/main.py
@@ -259,6 +259,27 @@ def _migrate_schema():
|
||||
if _has_table(db, "server_states") and not _has_column(db, "server_states", "nginx_sites_json"):
|
||||
db.execute(text("ALTER TABLE server_states ADD COLUMN nginx_sites_json TEXT NULL"))
|
||||
|
||||
# --- essentials table (BE-PR-003) ---
|
||||
if not _has_table(db, "essentials"):
|
||||
db.execute(text("""
|
||||
CREATE TABLE essentials (
|
||||
id INTEGER NOT NULL AUTO_INCREMENT,
|
||||
essential_code VARCHAR(64) NOT NULL,
|
||||
proposal_id INTEGER NOT NULL,
|
||||
type ENUM('feature','improvement','refactor') NOT NULL,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
description TEXT NULL,
|
||||
created_by_id INTEGER NULL,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NULL ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE INDEX idx_essentials_code (essential_code),
|
||||
INDEX idx_essentials_proposal_id (proposal_id),
|
||||
CONSTRAINT fk_essentials_proposal_id FOREIGN KEY (proposal_id) REFERENCES proposes(id),
|
||||
CONSTRAINT fk_essentials_created_by_id FOREIGN KEY (created_by_id) REFERENCES users(id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
|
||||
"""))
|
||||
|
||||
db.commit()
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
@@ -293,7 +314,7 @@ def _sync_default_user_roles(db):
|
||||
@app.on_event("startup")
|
||||
def startup():
|
||||
from app.core.config import Base, engine, SessionLocal
|
||||
from app.models import models, webhook, apikey, activity, milestone, notification, worklog, monitor, role_permission, task, support, meeting, proposal, propose
|
||||
from app.models import models, webhook, apikey, activity, milestone, notification, worklog, monitor, role_permission, task, support, meeting, proposal, propose, essential
|
||||
Base.metadata.create_all(bind=engine)
|
||||
_migrate_schema()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user