temoa icon indicating copy to clipboard operation
temoa copied to clipboard

Refactor migration command to avoid sys.argv manipulation

Open coderabbitai[bot] opened this issue 2 months ago • 0 comments

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

  • PR: https://github.com/TemoaProject/temoa/pull/196
  • Discussion: https://github.com/TemoaProject/temoa/pull/196#discussion_r2524640877
  • Requested by: @ParticularlyPythonicBS

coderabbitai[bot] avatar Nov 13 '25 19:11 coderabbitai[bot]