migrations Directory¶
Purpose¶
This directory contains Django database migration files for the parodynews application. These migrations define database schema changes, table creation, field modifications, and data transformations that evolve the database structure over time while maintaining data integrity.
Contents¶
__init__.py: Python package initialization file making this directory a Python package- Migration files (generated by Django): Python files that define database schema changes and data migrations
Notable migrations¶
0002_provider_agnostic_ai: The v0.6.0 refactor. RenamesOpenAIModeltoAIModeland adds itsproviderfield, gives threads and messages locally minted ids, tags legacy assistant replies by the OpenAIrun_idthey carry, createsAIProviderConfig, and copies the stored OpenAI credentials out ofAppConfigbefore dropping those columns.0003_drop_nullable_text_columns: Backfills NULLs inAssistant.name,Assistant.descriptionandMessage.run_id, then makes the columnsNOT NULLwith a default.
Usage¶
Django migrations are managed through Django's migration framework:
# Create new migrations after model changes
python manage.py makemigrations parodynews
# Apply migrations to database
python manage.py migrate
# Show migration status
python manage.py showmigrations
# Reverse migrations (if needed)
python manage.py migrate parodynews <migration_number>
# Create empty migration for custom operations
python manage.py makemigrations --empty parodynews
Reversibility is not automatic¶
Both v0.6.0 migrations were written to reverse cleanly, and neither did so on the first attempt. Two traps worth knowing, because Django will not warn you:
- Reversing a
RemoveFieldre-adds the column with no default. If the column wasNOT NULL, the reverse fails on any populated table before your restore step can run.0002fixes this by altering the threeAppConfigcolumns toblank=True, default=""before removing them, so the reverseAddFieldsucceeds and the restore then repopulates them. null=TruetoNOT NULLfails while NULLs remain. Postgres refusesSET NOT NULLoutright.0003backfills first in aRunPythonstep.
Test the whole cycle, not just forward, against a database with realistic rows:
python manage.py migrate parodynews 0001 # reverse
python manage.py migrate parodynews # forward again
Migration workflow:
1. Model Changes: Modify Django models in models.py
2. Generate Migrations: Run makemigrations to create migration files
3. Review: Check generated migration files for correctness
4. Apply: Run migrate to apply changes to database
5. Version Control: Commit migration files with model changes
Container Configuration¶
Migrations are executed within the Django application environment: - Applied automatically during container startup in production - Can be run manually in development containers - Database connection configured through Django settings - PostgreSQL-only (this project does not support SQLite)
Related Paths¶
- Incoming: Generated from Django model definitions and schema changes
- Outgoing: Applied to database to create/modify tables and data structures