Context
In PR #196, the migrate command was added to the CLI to support database migrations from v3.1 to v4. The current implementation for batch directory migrations manipulates sys.argv to invoke run_all_v4_migrations.main(), which is fragile and non-thread-safe.
Current approach (lines 331-340 in temoa/cli.py):
- Temporarily replaces
sys.argv with migration parameters
- Calls
run_all_mod.main() which uses argparse
- Restores original
sys.argv in finally block
Future Work
There is a plan for a future master migration script that will smartly handle both db and sql migrations from broader versioning than 3.1 to 4. As part of that work, the migration utilities should be refactored to accept parameters directly (either as function arguments or a config object) rather than relying on sys.argv manipulation.
Recommended Approach
Refactor run_all_v4_migrations.main() to expose a function that accepts parameters directly:
def run_migrations(input_dir: Path, migration_script: Path, schema_path: Path) -> None:
# existing logic without argparse
...
Then the CLI can call it cleanly without sys.argv manipulation.
References
Context
In PR #196, the
migratecommand was added to the CLI to support database migrations from v3.1 to v4. The current implementation for batch directory migrations manipulatessys.argvto invokerun_all_v4_migrations.main(), which is fragile and non-thread-safe.Current approach (lines 331-340 in temoa/cli.py):
sys.argvwith migration parametersrun_all_mod.main()which uses argparsesys.argvin finally blockFuture Work
There is a plan for a future master migration script that will smartly handle both db and sql migrations from broader versioning than 3.1 to 4. As part of that work, the migration utilities should be refactored to accept parameters directly (either as function arguments or a config object) rather than relying on
sys.argvmanipulation.Recommended Approach
Refactor
run_all_v4_migrations.main()to expose a function that accepts parameters directly:Then the CLI can call it cleanly without sys.argv manipulation.
References