Skip to content

FEAT: Implement DB schema tracking with alembic#1631

Open
behnam-o wants to merge 28 commits intomicrosoft:mainfrom
behnam-o:dev/db-schema-tracking
Open

FEAT: Implement DB schema tracking with alembic#1631
behnam-o wants to merge 28 commits intomicrosoft:mainfrom
behnam-o:dev/db-schema-tracking

Conversation

@behnam-o
Copy link
Copy Markdown
Contributor

@behnam-o behnam-o commented Apr 17, 2026

Summary

Adds Alembic-based, versioned memory schema migrations so DB schema changes are safe and repeatable across releases.

  • Replaces ad-hoc table lifecycle logic with migration-driven lifecycle (upgrade/reset via revisions).
  • Introduces the main operator/dev entrypoint: memory_migrations.py with:
    • generate: create a migration when memory models change (commit migration with model changes).
    • check: validate migrations resolve to current model schema.
  • Enforces consistency in CI/dev flow via pre-commit check (fails when migrations and models diverge).
  • Automatically applies migrations during memory DB initialization.
  • Handles legacy unversioned DBs cautiously:
    • If existing PyRIT memory schema matches expected schema, it is stamped and continues.
    • If schema drift exists, startup migration fails (manual alignment or table reset required).
  • Uses a namespaced version table (pyrit_memory_alembic_version) to avoid clashing with other Alembic-managed schemas.

@behnam-o behnam-o marked this pull request as ready for review April 20, 2026 17:38
Comment thread pyrit/memory/alembic/versions/e373726d391b_initial_schema.py Outdated
Comment thread pyrit/memory/migration.py Outdated
Comment thread pyrit/memory/memory_interface.py Outdated
Comment thread pyrit/memory/alembic/versions/e373726d391b_initial_schema.py
Comment thread pyrit/memory/azure_sql_memory.py Outdated
Comment thread .pre-commit-config.yaml
Comment thread pyrit/memory/memory_interface.py Outdated
Comment thread pyrit/memory/migration.py Outdated
Copy link
Copy Markdown
Contributor

@hannahwestra25 hannahwestra25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a few small comments!

Comment thread pyrit/memory/alembic/versions/e373726d391b_initial_schema.py
Comment thread pyrit/memory/alembic/env.py Outdated
@hannahwestra25 hannahwestra25 self-assigned this Apr 21, 2026
Behnam Ousat and others added 11 commits April 21, 2026 18:45
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
cc
Co-authored-by: Copilot <copilot@github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants