Summary
When a service fails at startup due to orphaned migration records in the database (migration was applied but the corresponding Rust migration file no longer exists), the error message is cryptic and provides no guidance on how to fix it. Wrap the migrator to detect this specific failure mode and print actionable recovery steps.
Problem
Switching between branches that have different migrations applied to the same database leaves orphaned entries in the seaql_migrations table. On next startup, SeaORM prints:
Error: Custom Error: Migration file of version 'm20260329_000012_create_projects_table' is missing,
this migration has been applied but its file is missing
This is a common development scenario (branch switching, rebasing) but the error gives no hint about how to recover. The service enters a crash loop with KeepAlive restarts.
Proposed Solution
Wrap the Migrator::up() call in each service's startup with error detection:
- Catch the "migration file is missing" error specifically
- Query
seaql_migrations to list the orphaned entries
- Print actionable guidance:
ERROR: Orphaned migration records found in database.
The following migrations are recorded as applied but have no corresponding
migration file in the current build. This typically happens after switching
branches.
Orphaned entries:
- m20260329_000012_create_projects_table
- m20260409_000013_add_project_id_to_agents_workflows
To fix, remove the orphaned records:
sqlite3 "<db_path>" "REMOVE FROM seaql_migrations WHERE version IN (
'm20260329_000012_create_projects_table',
'm20260409_000013_add_project_id_to_agents_workflows'
);"
Then restart the service.
- This logic could live in
agentd-common as a shared migration helper since all services use the same pattern.
Acceptance Criteria
Summary
When a service fails at startup due to orphaned migration records in the database (migration was applied but the corresponding Rust migration file no longer exists), the error message is cryptic and provides no guidance on how to fix it. Wrap the migrator to detect this specific failure mode and print actionable recovery steps.
Problem
Switching between branches that have different migrations applied to the same database leaves orphaned entries in the
seaql_migrationstable. On next startup, SeaORM prints:This is a common development scenario (branch switching, rebasing) but the error gives no hint about how to recover. The service enters a crash loop with
KeepAliverestarts.Proposed Solution
Wrap the
Migrator::up()call in each service's startup with error detection:seaql_migrationsto list the orphaned entriesagentd-commonas a shared migration helper since all services use the same pattern.Acceptance Criteria
sqlite3command to fix the issueagentd-commonfor all services