-
Notifications
You must be signed in to change notification settings - Fork 61
Description
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.argvwith migration parameters - Calls
run_all_mod.main()which uses argparse - Restores original
sys.argvin 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
- PR: adding database migrators to the cli #196
- Discussion: adding database migrators to the cli #196 (comment)
- Requested by: @ParticularlyPythonicBS