mirror of
https://github.com/photoprism/photoprism.git
synced 2026-07-18 00:59:38 +00:00
Record that album_path is now a byte-exact VARBINARY column (alongside album_slug, album_filter, photo_path) and that folder albums dedupe by album_filter, in internal/entity/README.md. Add an Index Prefix Limits note to the migrate README and AGENTS: InnoDB caps key prefixes at 767 bytes on COMPACT/REDUNDANT row formats, so VARBINARY prefix indexes use 512 by convention.
2.9 KiB
2.9 KiB
Migration Package Guidelines
Last Updated: June 1, 2026
This file applies to internal/entity/migrate/. Read README.md here for the runtime flow, retry behavior, and CLI troubleshooting commands.
Editing Migrations
- Add or change SQL in
mysql/andsqlite3/; do not hand-edit the generateddialect_mysql.goordialect_sqlite3.gofiles. - Reuse the same timestamp-based migration ID across dialects for the same logical change.
- Use
.pre.sqlonly when the SQL must run before GORMAutoMigrate(...), typically for renames or shape changes that the ORM must see afterward. - Keep migrations idempotent when possible with
IF EXISTS,IF NOT EXISTS, or safe update conditions. Failed migrations are recorded once and then skipped on normal startup, so noisy or brittle SQL creates persistent operator friction until someone retries it manually. - When (re-)creating a prefix index on a
VARBINARYcolumn, keep the prefix at ≤ 767 bytes (the convention is512). InnoDB caps key prefixes at 767 bytes onCOMPACT/REDUNDANTrow formats, andVARBINARYprefixes are counted in bytes, so a longer prefix fails on older or non-DYNAMICinstalls. SeeREADME.md→ "Index Prefix Limits". - If a migration requires custom Go logic instead of plain SQL, keep the reason narrow and obvious. Package-local helpers should still preserve the same retry semantics described in
README.md.
Generation & Verification
- After changing migration SQL, run
go generate ./internal/entity/migrate. - After Go edits in this package, run
go fmt ./internal/entity/migrate. - Verify the package with
go test ./internal/entity/migrate -count=1. - When a change affects operator workflows, also verify the CLI help and status paths with
./photoprism migrations --help,./photoprism migrations ls --help, and./photoprism migrations run --help.
Test Fixtures
- Keep
testdata/migrate_sqlite3andtestdata/migrate_mysql.sqlaligned with the pre-migration schema shape expected by the regression tests. TestDialectSQLite3runs against a copied SQLite fixture.TestDialectMysqlexpects a MariaDB service reachable asmariadb:${MARIADB_PORT:-4001}with themigratedatabase and user fromtestdata/migrate_mysql.sql.
Runtime Model
- The
versionstable gates the once-per-release schema initialization path. - The
migrationstable stores per-migrationstarted_at,finished_at, anderrorstate. - Normal startup does not rerun rows that already failed. Retrying failed rows requires
photoprism migrations run --failedor explicitly naming migration IDs. - Unfinished rows without an error are treated as stale and repeatable only after 60 minutes. More recent unfinished rows are assumed to still be running.