Skip to content

Add actionable guidance for orphaned SeaORM migration errors #1156

@geoffjay

Description

@geoffjay

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:

  1. Catch the "migration file is missing" error specifically
  2. Query seaql_migrations to list the orphaned entries
  3. 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.
  1. This logic could live in agentd-common as a shared migration helper since all services use the same pattern.

Acceptance Criteria

  • Orphaned migration errors are detected and produce actionable output
  • The output includes the exact sqlite3 command to fix the issue
  • The database path is included in the output
  • Implemented as a shared helper in agentd-common for all services

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions