mirror of
https://github.com/escalante29/WealthySmart.git
synced 2026-07-17 10:08:46 +02:00
Adopt Alembic: autogenerated baseline, stamp-or-upgrade startup
The baseline (c3da001a0eb3) was autogenerated against an empty Postgres and schema-diffed against the live dev schema until column-identical (two model fixes fell out: deferred_to_next_cycle now declares its server_default, usersettings.data is JSONB on Postgres to match the live type). Startup replaces init_db/run_migrations with run_alembic_upgrade(): pre-Alembic databases that already match the baseline are adopted via stamp; fresh databases build from the migration. The section is serialized with a pg advisory lock because prod uvicorn runs 2 workers, each executing the lifespan. Verified: adoption + idempotent re-run on the dev DB, fresh 13-table build on an empty DB, full container boot, 55/55 tests. (ARCH-02, BE-19) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
21
CLAUDE.md
21
CLAUDE.md
@@ -17,6 +17,27 @@ The backend refuses to boot without `SECRET_KEY`, `ADMIN_USERNAME`, and
|
||||
`ADMIN_PASSWORD` (no insecure defaults). Copy `.env.example` to `.env` and fill
|
||||
it in; the dev docker-compose reads it.
|
||||
|
||||
## Database Migrations
|
||||
|
||||
Schema changes go through Alembic — never edit the schema by hand and never
|
||||
reset the prod DB. Workflow:
|
||||
|
||||
```bash
|
||||
cd backend
|
||||
# 1. Edit app/models/models.py
|
||||
# 2. Autogenerate against the dev DB, then REVIEW the generated file
|
||||
DATABASE_URL='postgresql://wealthy_user:wealthy_pass@localhost:5433/wealthysmart' \
|
||||
.venv/bin/alembic revision --autogenerate -m "describe the change"
|
||||
# 3. Migrations apply automatically at app startup (run_alembic_upgrade)
|
||||
```
|
||||
|
||||
## Tests
|
||||
|
||||
```bash
|
||||
cd backend && .venv/bin/python -m pytest tests/ -q # backend (55+ tests)
|
||||
cd frontend && pnpm typecheck # frontend
|
||||
```
|
||||
|
||||
## Local Docker
|
||||
|
||||
```bash
|
||||
|
||||
Reference in New Issue
Block a user