from __future__ import annotations

from app.core.mongo_runtime import clear_mongo_runtime, init_mongo_runtime
from app.migrations.definitions import MIGRATIONS
from app.migrations.runner import MigrationRunner


def main() -> int:
    runtime = init_mongo_runtime()
    try:
        runner = MigrationRunner(runtime.sync_database, MIGRATIONS)
        executed = runner.run()
        if executed:
            print("Applied migrations:")
            for version in executed:
                print(f"- {version}")
        else:
            print("No pending migrations.")
        return 0
    finally:
        clear_mongo_runtime(runtime)


if __name__ == "__main__":
    raise SystemExit(main())
