37 lines
850 B
Python
37 lines
850 B
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
import importlib
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
|
if str(PROJECT_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(PROJECT_ROOT))
|
|
|
|
_core = importlib.import_module("agent_call.core")
|
|
Store = _core.Store
|
|
|
|
|
|
def migrate(path: str) -> int:
|
|
store = Store(path)
|
|
try:
|
|
row = store.one("SELECT MAX(version) AS version FROM schema_migrations")
|
|
print(f"schema_version={row['version']}")
|
|
return 0
|
|
finally:
|
|
store.close()
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(
|
|
description="apply idempotent agent-call SQLite migrations"
|
|
)
|
|
parser.add_argument("database")
|
|
args = parser.parse_args()
|
|
return migrate(args.database)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|