pgsqlite uses an internal migration system to manage its metadata tables (__pgsqlite_*). This ensures smooth upgrades as the project evolves.
- In-memory databases: Migrations run automatically on startup (always start fresh)
- New file databases: Migrations run automatically when creating a new database
- Existing file databases: Schema version is checked on startup
- If outdated, pgsqlite exits with an error
- You must explicitly run migrations with
--migrate
# Check if migrations are needed (will error if outdated)
pgsqlite --database mydb.db
# Example error message:
# Error: Failed to create database handler: Database schema is outdated.
# Current version: 2, Required version: 4. Please run with --migrate to update the schema.
# Run pending migrations and exit
pgsqlite --database mydb.db --migrate
# After migration, run normally
pgsqlite --database mydb.db- All migrations run in transactions
- Automatic rollback on failure
- SHA256 checksums verify migration integrity
- Concurrent migrations prevented via locking
- Migration history tracked in
__pgsqlite_migrations
When modifying pgsqlite's internal tables, you must create a migration:
- Add to
src/migration/registry.rs - Define migration with up/down SQL
- Update CLAUDE.md with new migration info
- Test with both new and existing databases
See the development guide for detailed instructions.
