Move alembic configuration and migration files from repository root into the
Python package structure to ensure they are included in the wheel distribution.
This fix resolves the FileNotFoundError when running `agents init` in Docker
containers or any environment using the built wheel distribution.
Changes:
- Move alembic/ directory from repo root to
src/cleveragents/infrastructure/database/migrations/
- Move alembic.ini to the same new location and update script_location setting
- Update MigrationRunner._find_alembic_ini() to search from the new canonical
location within the package
- Update create_template_db.py to point to the new alembic.ini location
- Update documentation references to reflect new migration file locations
- Create __init__.py for migrations package
- The env.py file is imported when running tests that verify all modules can be
imported without errors. However, context.config is only available when alembic
is actually running migrations, not during normal module imports. This caused
an AttributeError when the test tried to import the migrations.env module.
- Fix by using getattr() with a default value to safely access context.config,
and guard all code that uses config with None checks. This allows the module
to be safely imported while still functioning correctly during migrations.
Testing:
- Verified MigrationRunner can locate alembic.ini in new location
- Tested agents init succeeds in creating project with database
- Template database creation works correctly
- All migration tests should pass without changes
Alembic files now follow standard Python packaging conventions, making them
automatically included in wheel distributions without special configuration.
ISSUES CLOSED: #4180
Add Alembic migration m4_002_skill_flattened_tools to extend the skills
table with five new columns: flattened_tools_json, includes_json,
capability_summary_json, yaml_text, and flattening_hash (SHA-256). A
defence-in-depth uniqueness constraint (uq_skills_name) is also added.
Update SkillModel with the new column definitions and extend
SkillRepository with update_flattened_tools(), get_flattened_tools(),
needs_refresh(), recompute_flattening_hash(), and
invalidate_cached_summaries() methods. The existing update() method
now nulls all cached fields on mutation (hash-based invalidation).
All new repository methods follow the session-factory pattern with
@database_retry and flush-but-don-t-commit semantics. Structured
logging via structlog records cache updates and invalidations.
Database schema docs updated with the new skills table columns and a
persistence-field-to-domain-model mapping table.
Tests:
- 6 Behave scenarios covering create, invalidation, hash staleness,
refresh recomputation, uniqueness constraint, and namespace filtering
- 2 Robot Framework smoke tests (round-trip and invalidation)
- 3 ASV benchmarks (persist, refresh check, namespace list)
ISSUES CLOSED: #166
Add decision persistence layer with DecisionRepository, DecisionModel,
and Alembic migration. Includes tree queries (BFS traversal via deque,
path-to-root), superseded lookup, ordered decision path retrieval,
concrete Decision type annotations (via TYPE_CHECKING), and comprehensive
test coverage (Behave BDD, Robot Framework, ASV benchmarks). Updated
database_schema.md, CHANGELOG.md, and CONTRIBUTORS.md.
ISSUES CLOSED: #171