fix(migrations): enforce schema ownership safety
This commit is contained in:
@@ -58,14 +58,33 @@ pip install -e .[dev]
|
||||
copy ..\\.env.example ..\\.env
|
||||
```
|
||||
|
||||
3. 启动服务
|
||||
3. 使用标准入口启动服务
|
||||
|
||||
```bash
|
||||
uvicorn app.main:app --reload --app-dir src
|
||||
cd ..
|
||||
./start.sh server
|
||||
```
|
||||
|
||||
标准入口在启动新的 FastAPI 进程前会自动执行 `alembic upgrade head`,迁移成功后才会
|
||||
启动 Uvicorn。`./start.sh all` 在需要启动后端时也会复用同一流程。不要把直接运行
|
||||
`uvicorn` 当作标准启动方式;手工调试 Uvicorn 时,需要先自行完成迁移。
|
||||
|
||||
## 迁移
|
||||
|
||||
```bash
|
||||
alembic upgrade head
|
||||
cd server
|
||||
alembic -c alembic.ini upgrade head
|
||||
```
|
||||
|
||||
一次性 PostgreSQL 迁移测试默认跳过,只有显式提供
|
||||
`MIGRATION_TEST_DATABASE_URL` 时才会执行。为避免误操作开发库,测试会同时要求主机名
|
||||
和数据库名使用 `migration-probe` 或 `disposable-probe` 安全前缀,并要求数据库初始为空。
|
||||
|
||||
```bash
|
||||
cd server
|
||||
MIGRATION_TEST_DATABASE_URL='postgresql+psycopg://migration_probe:migration_probe_pw@x-financial-migration-probe-123:5432/migration_probe' \
|
||||
pytest -q tests/test_alembic_migrations.py
|
||||
```
|
||||
|
||||
该测试覆盖首次升级、重复升级、关键表/约束/索引、外键级联、降级到 `base`、无关旧表
|
||||
及哨兵数据保留,以及再次升级。请只把它指向无持久卷的一次性 PostgreSQL 容器。
|
||||
|
||||
Reference in New Issue
Block a user