ReleasesMigration Infrastructure

Migration Infrastructure

Release Date: January 2026 Branch: ghostmonk/migration-infrastructure Related Issue: #70 - Dynamic Sections

Summary

This release introduces a formal database migration framework using pymongo-migrate. Migrations are now versioned, ordered, and reversible, replacing the previous ad-hoc approach.

Changes

New Features

  • pymongo-migrate integration: Formal migration framework with CLI support
  • Migration commands: make migrate, make migrate-status, make migrate-down
  • Section ID linking: Content models now support section_id for dynamic section association
  • Initial section seeding: Blog, About, Projects, Contact sections created via migration

Backend Changes

FileChange
backend/migrations/0001_create_admin_user.pyCreate admin user from ADMIN_EMAIL
backend/migrations/0002_add_user_id_to_content.pyAssociate content with admin user
backend/migrations/0003_seed_initial_sections.pySeed initial sections
backend/migrations/0004_backfill_section_id.pyLink content to sections
backend/models/story.pyAdded section_id: str | None
backend/models/project.pyAdded section_id: str | None
backend/models/page.pyAdded section_id: str | None
backend/database.pyAdded section_id indexes
backend/requirements.inAdded pymongo-migrate==1.0.0
backend/app.pyRemoved ad-hoc migration calls from startup
MakefileAdded migration targets

Removed

  • backend/handlers/migrations.py - Replaced by formal migration files

Migration Guide

For New Deployments

Migrations run automatically when you execute:

make migrate

For Existing Deployments

  1. Ensure ADMIN_EMAIL is set in .env
  2. Run migrations:
    make migrate
  3. Verify status:
    make migrate-status

Environment Variables Required

VariableDescription
ADMIN_EMAILEmail for the admin user (required)
MONGO_URIMongoDB connection string (required)

Database Schema Changes

New Fields

CollectionFieldTypeDescription
storiessection_idstring | nullReference to sections collection
projectssection_idstring | nullReference to sections collection
pagessection_idstring | nullReference to sections collection

New Indexes

CollectionIndexPurpose
storiessection_idQuery stories by section
projectssection_idQuery projects by section
pagessection_idQuery pages by section

Breaking Changes

None. All changes are additive and backward-compatible.

Known Limitations

  • Migration framework is MongoDB-specific (pymongo-migrate)
  • If switching databases, migrations would need to be rewritten
  • Application code remains database-agnostic through repository pattern