Add or change a SQLite schema migration. Use when bumping SCHEMA_VERSION, editing db/migrations.rs, or writing a migration test.
Instal·la
npx skillscat add alondero/buildmesh/db-migration Instal·la des del registre de SkillsCat.
SKILL.md
Change the database schema
SCHEMA_VERSION lives in src-tauri/src/db/migrations.rs. src-tauri/src/db/mod.rs owns the connection pool and init only. Do not declare a second version constant.
- Bump
SCHEMA_VERSIONand add the step insrc-tauri/src/db/migrations.rs. Pass the&Connectionyou were given into an_innerhelper. Do not callread_conn()orwrite_conn()from code that already holds a connection. - Do not do filesystem, git, or process work while that connection or the writer mutex is held. Prepare under the lock, do the I/O after releasing it, then write back under the lock.
- New columns need a default or must be nullable, so existing rows still read. Match the steps already in
src-tauri/src/db/migrations.rs. Do not add a second migrator. - Add a test in
src-tauri/src/db/migration_tests.rsthat runs the production initialiser on a fresh in-memory database and on a legacy schema that already has rows. Assert the preserved rows, the new columns or indexes, and that a second initialisation changes nothing. A test that usesdb::get()installs its database withdb::test_support::isolated()and holds the guard for the whole body. - Update
src-tauri/src/db/schema_dump.txtin the same change.init_schema_dump_matches_committed_snapshotinsrc-tauri/src/db/seam_tests.rsfails when the fresh schema drifts from that file.
From src-tauri/:
cargo test --lib migration_tests
cargo test --lib init_schema_dump_matches_committed_snapshot