feat: add project code generation + remove issues/milestones from nav
This commit is contained in:
27
app/main.py
27
app/main.py
@@ -45,11 +45,36 @@ app.include_router(webhooks_router)
|
||||
app.include_router(misc_router)
|
||||
app.include_router(monitor_router)
|
||||
|
||||
|
||||
# Auto schema migration for lightweight deployments
|
||||
def _migrate_schema():
|
||||
from sqlalchemy import text
|
||||
from app.core.config import SessionLocal
|
||||
db = SessionLocal()
|
||||
try:
|
||||
# issues.issue_subtype
|
||||
result = db.execute(text("SHOW COLUMNS FROM issues LIKE 'issue_subtype'")).fetchone()
|
||||
if not result:
|
||||
db.execute(text("ALTER TABLE issues ADD COLUMN issue_subtype VARCHAR(64) NULL"))
|
||||
# issues.issue_type enum -> varchar
|
||||
result = db.execute(text("SHOW COLUMNS FROM issues WHERE Field='issue_type'")).fetchone()
|
||||
if result and 'enum' in result[1].lower():
|
||||
db.execute(text("ALTER TABLE issues MODIFY issue_type VARCHAR(32) DEFAULT 'issue'"))
|
||||
# projects.project_code
|
||||
result = db.execute(text("SHOW COLUMNS FROM projects LIKE 'project_code'")).fetchone()
|
||||
if not result:
|
||||
db.execute(text("ALTER TABLE projects ADD COLUMN project_code VARCHAR(16) NULL"))
|
||||
db.execute(text("CREATE UNIQUE INDEX idx_projects_project_code ON projects (project_code)"))
|
||||
except Exception as e:
|
||||
print(f"Migration warning: {e}")
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
# Run database migration on startup
|
||||
@app.on_event("startup")
|
||||
def startup():
|
||||
from app.core.config import Base, engine, SessionLocal
|
||||
from app.models import webhook, apikey, activity, milestone, notification, worklog, monitor
|
||||
from app.models import models, webhook, apikey, activity, milestone, notification, worklog, monitor
|
||||
Base.metadata.create_all(bind=engine)
|
||||
_migrate_schema()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user