chore: PostgreSQL migration compatibility and infrastructure improvements
Database & Migrations: - Update all Alembic migrations for PostgreSQL compatibility - Remove SQLite-specific syntax (AUTOINCREMENT, etc.) - Add database utility helpers for PostgreSQL operations - Fix services to use PostgreSQL-compatible queries Documentation: - Add comprehensive Docker deployment guide - Add production deployment documentation - Add infrastructure architecture documentation - Update database setup guide for PostgreSQL-only - Expand troubleshooting guide Architecture & Validation: - Add migration.yaml rules for SQL compatibility checking - Enhance validate_architecture.py with migration validation - Update architecture rules to validate Alembic migrations Development: - Fix duplicate install-all target in Makefile - Add Celery/Redis validation to install.py script - Add docker-compose.test.yml for CI testing - Add squash_migrations.py utility script - Update tests for PostgreSQL compatibility - Improve test fixtures in conftest.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -54,6 +54,100 @@ make backup-db
|
||||
make verify-setup
|
||||
```
|
||||
|
||||
## Alembic Commands Explained
|
||||
|
||||
Understanding what each Alembic command does is essential for managing database migrations effectively.
|
||||
|
||||
### Core Commands Reference
|
||||
|
||||
| Command | Description |
|
||||
|---------|-------------|
|
||||
| `alembic upgrade head` | Apply **all** pending migrations to get to the latest version |
|
||||
| `alembic upgrade +1` | Apply only the **next** single migration (one step forward) |
|
||||
| `alembic downgrade -1` | Roll back the **last** applied migration (one step back) |
|
||||
| `alembic downgrade base` | Roll back **all** migrations (returns to empty schema) |
|
||||
| `alembic current` | Show which migration the database is currently at |
|
||||
| `alembic history` | List all migrations in the chain |
|
||||
| `alembic heads` | Show the latest migration revision(s) |
|
||||
|
||||
### Visual Example
|
||||
|
||||
```
|
||||
Migration Chain: [base] → [A] → [B] → [C] → [D] (head)
|
||||
↑
|
||||
└── current database state (at revision B)
|
||||
|
||||
Command Result
|
||||
─────────────────────────────────────────────────────────
|
||||
alembic upgrade head → Database moves to [D]
|
||||
alembic upgrade +1 → Database moves to [C]
|
||||
alembic downgrade -1 → Database moves to [A]
|
||||
alembic downgrade base → Database returns to [base] (empty schema)
|
||||
alembic current → Shows "B" (current revision)
|
||||
```
|
||||
|
||||
### Makefile Shortcuts
|
||||
|
||||
| Make Command | Alembic Equivalent | Description |
|
||||
|--------------|-------------------|-------------|
|
||||
| `make migrate-up` | `alembic upgrade head` | Apply all pending migrations |
|
||||
| `make migrate-down` | `alembic downgrade -1` | Roll back last migration |
|
||||
| `make migrate-status` | `alembic current` + `alembic history` | Show current state and history |
|
||||
|
||||
### Additional Useful Commands
|
||||
|
||||
```bash
|
||||
# Show detailed migration history
|
||||
alembic history --verbose
|
||||
|
||||
# Upgrade/downgrade to a specific revision
|
||||
alembic upgrade abc123def456
|
||||
alembic downgrade abc123def456
|
||||
|
||||
# Show what SQL would be generated (without executing)
|
||||
alembic upgrade head --sql
|
||||
|
||||
# Mark database as being at a specific revision (without running migrations)
|
||||
alembic stamp head
|
||||
alembic stamp abc123def456
|
||||
|
||||
# Show the current revision ID only
|
||||
alembic current --verbose
|
||||
```
|
||||
|
||||
### Database Initialization Workflow
|
||||
|
||||
For setting up a new database:
|
||||
|
||||
```bash
|
||||
# Option 1: Empty schema only (just tables, no data)
|
||||
make migrate-up
|
||||
|
||||
# Option 2: Schema + production essentials (admin user, settings, CMS, email templates)
|
||||
make init-prod
|
||||
|
||||
# Option 3: Full development setup (schema + production data + demo data)
|
||||
make db-setup
|
||||
# Or step by step:
|
||||
make init-prod
|
||||
make seed-demo
|
||||
```
|
||||
|
||||
### Reset Workflow
|
||||
|
||||
For completely resetting the database:
|
||||
|
||||
```bash
|
||||
# Nuclear reset: deletes database file, recreates schema, seeds all data
|
||||
make db-reset
|
||||
```
|
||||
|
||||
> **Note**: `make db-reset` rolls back all migrations and recreates the schema from scratch.
|
||||
|
||||
!!! note "PostgreSQL Required"
|
||||
This project uses PostgreSQL exclusively. SQLite is not supported.
|
||||
Start the development database with: `make docker-up`
|
||||
|
||||
## Development Workflows
|
||||
|
||||
### Adding New Database Fields
|
||||
|
||||
Reference in New Issue
Block a user