Skip to content

Refactor migration command to avoid sys.argv manipulation #197

@coderabbitai

Description

@coderabbitai

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions