Skip to content

library-manager: no Alembic-managed schema migrations #434

Description

@NoveliaYuki

Problem

The Library Manager (library-manager/, port 9091) manages its database schema with Base.metadata.create_all plus a hand-rolled _apply_lightweight_migrations() shim (backend/database/connection.py). create_all creates missing tables but never alters existing ones; the shim works around that with ad-hoc ALTER TABLE ... ADD COLUMN guarded by PRAGMA table_info. This is brittle and only supports additive column changes — it cannot handle column rebuilds, constraint changes, or anything SQLite needs batch mode for. The shim itself documents the gap:

create_all creates missing tables but never adds new columns to existing ones.

Expected

Adopt Alembic for the Library Manager:

  • A baseline migration capturing the current schema (organizations, libraries, content_folders, content_items, content_images, import_jobs and their indexes / FK cascades).
  • Migrations run automatically to head at startup; SQLite batch mode enabled for future column rebuilds.
  • The _apply_lightweight_migrations() shim is retired (its one delta, content_items.folder_id, folds into the baseline).
  • Databases created before Alembic adoption (tables present, no alembic_version) are stamped to the baseline before upgrading, so existing dev data is preserved.

Scope

library-manager/ only. The new KB Server is tracked separately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesttechnical-debtCode or process improvements needed to reduce long-term maintenance burden

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions