- config.json 改为按项目存储(projects.<id>),上传配置全局共用;旧单项目配置自动迁移为 readoor
- 新增项目管理(管理员):Git 仓库/凭据、源码目录、Xcode 工程、拷贝条目、配置替换方式、自定义字段、替换规则
- 通用配置替换:pbxproj 版本号与签名,patch_rules 支持 define / replace_line 及 ${app.X}、${server.X} 模板
- 请求通过 X-Project 头选择项目;打包任务记录 project_id,历史按项目过滤
- 前端顶部切换项目,App/服务器环境表单按项目显示字段
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
2.0 KiB
Python
65 lines
2.0 KiB
Python
"""数据库配置"""
|
|
from sqlalchemy import create_engine, text
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
from .config import DATABASE_URL
|
|
|
|
engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False})
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
Base = declarative_base()
|
|
|
|
|
|
def get_db():
|
|
"""获取数据库会话"""
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
def _migrate_db():
|
|
"""简单的数据库迁移:为旧表添加缺失的列"""
|
|
migrations = [
|
|
("tasks", "branch", "VARCHAR DEFAULT 'main'"),
|
|
("tasks", "ref_type", "VARCHAR DEFAULT 'branch'"),
|
|
("tasks", "error_category", "VARCHAR"),
|
|
("tasks", "superseded_at", "TIMESTAMP"),
|
|
("tasks", "dsym_url", "VARCHAR"),
|
|
("tasks", "project_id", "VARCHAR DEFAULT 'readoor'"),
|
|
]
|
|
with engine.connect() as conn:
|
|
for table, column, col_type in migrations:
|
|
try:
|
|
conn.execute(text(f"ALTER TABLE {table} ADD COLUMN {column} {col_type}"))
|
|
conn.commit()
|
|
except Exception:
|
|
pass # 列已存在则忽略
|
|
|
|
|
|
def _seed_admin():
|
|
"""初始化管理员账号(从 .env 配置)"""
|
|
from .models import User
|
|
from .config import ADMIN_USERNAME, ADMIN_PASSWORD
|
|
from .security import hash_password
|
|
|
|
db = SessionLocal()
|
|
try:
|
|
if not db.query(User).filter(User.username == ADMIN_USERNAME).first():
|
|
db.add(User(id="admin-001", username=ADMIN_USERNAME,
|
|
password_hash=hash_password(ADMIN_PASSWORD), is_admin=True))
|
|
db.commit()
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
def init_db():
|
|
"""初始化数据库"""
|
|
# Load model declarations before create_all so a standalone startup creates every table.
|
|
from . import models # noqa: F401
|
|
|
|
Base.metadata.create_all(bind=engine)
|
|
_migrate_db()
|
|
_seed_admin()
|