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.
Problem
The Library Manager (
library-manager/, port 9091) manages its database schema withBase.metadata.create_allplus a hand-rolled_apply_lightweight_migrations()shim (backend/database/connection.py).create_allcreates missing tables but never alters existing ones; the shim works around that with ad-hocALTER TABLE ... ADD COLUMNguarded byPRAGMA 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:Expected
Adopt Alembic for the Library Manager:
organizations,libraries,content_folders,content_items,content_images,import_jobsand their indexes / FK cascades).headat startup; SQLite batch mode enabled for future column rebuilds._apply_lightweight_migrations()shim is retired (its one delta,content_items.folder_id, folds into the baseline).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.