neosqlite.migration module¶
Auto-vacuum migration utilities for NeoSQLite.
Provides functionality to migrate SQLite databases to different auto_vacuum modes while preserving all data.
- neosqlite.migration.needs_migration(db: Connection, target_autovacuum: int) bool[source]¶
Check if the database needs auto_vacuum migration.
- Parameters:
db – SQLite connection
target_autovacuum – Desired auto_vacuum mode
- Returns:
True if migration is needed, False otherwise
- neosqlite.migration.get_journal_mode(db: Connection) str[source]¶
Get the current journal mode of a database.
- neosqlite.migration.checkpoint_and_prepare_for_migration(db: Connection) list[str][source]¶
Ensure database is ready for migration by checkpointing WAL.
- Parameters:
db – SQLite connection
- Returns:
List of files that need to be backed up (main db + wal/shm if exist)
- neosqlite.migration.migrate_autovacuum(db_path: str, target_autovacuum: int, target_journal_mode: str = 'WAL', extra_conn_kwargs: dict | None = None) bool[source]¶
Migrate a database to a different auto_vacuum mode.
This function: 1. Check if migration is actually needed 2. Checkpoints any WAL data 3. Backs up all database files (main + WAL + SHM) 4. Closes the database 5. Opens backup and VACUUM INTO new file with desired auto_vacuum 6. Replaces original with vacuumed file
- Parameters:
db_path – Path to the database file
target_autovacuum – Desired auto_vacuum mode (0, 1, or 2)
target_journal_mode – Desired journal mode (default: WAL)
extra_conn_kwargs – Extra arguments for sqlite3.connect()
- Returns:
True if migration succeeded, False if skipped (already correct)