Complete the Alembic migration infrastructure by adding CLI commands,
improving stamp logic, and adding comprehensive lifecycle tests.
Key changes:
- Added agents db CLI command group (db.py) with 5 subcommands:
migrate (autogenerate), upgrade, downgrade, current, history.
All delegate to MigrationRunner which wraps Alembic command API.
- Registered the db command group in main.py CLI registration.
- Fixed legacy database stamp logic in MigrationRunner to stamp at
"head" instead of "001_initial_schema" when pre-Alembic tables are
detected. This avoids migration failures when create_all-produced
tables already exist (migrations would try to CREATE TABLE and fail
with "table already exists").
- Added commit() after stamp to ensure alembic_version is persisted
before subsequent operations on the same in-memory database.
- Added FakeConnection.commit() method to the mock test infrastructure
to support the new commit call in the stamp path.
- Added Behave feature (db_migration_lifecycle.feature) with 8
scenarios covering: forward migration, rollback, round-trip,
CLI upgrade/current/downgrade, legacy stamp logic, and
init_database schema validation.
- Added vulture whitelist entries for new CLI commands.
Note: init_database() still uses Base.metadata.create_all() as the
primary schema creation path. Full migration to Alembic-only init is
deferred until ORM model constraints are reconciled with migration
scripts (action_arguments UniqueConstraint mismatch).
ISSUES CLOSED: #941