31 lines
1.4 KiB
Python
31 lines
1.4 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""Maintenance-only SQLite to clean PostgreSQL database migration."""
|
||
|
|
from __future__ import annotations
|
||
|
|
# Allow direct `python scripts/name.py` from a fresh source checkout.
|
||
|
|
import sys as _sys
|
||
|
|
from pathlib import Path as _Path
|
||
|
|
_sys.path.insert(0, str(_Path(__file__).resolve().parents[1]))
|
||
|
|
import argparse,json,sys
|
||
|
|
from app.sqlite_pg_transfer import migrate
|
||
|
|
from app.pg_disaster_recovery import RecoveryError
|
||
|
|
|
||
|
|
def main(argv=None):
|
||
|
|
ap=argparse.ArgumentParser(description='Offline SQLite -> EMPTY PostgreSQL data migration')
|
||
|
|
ap.add_argument('--source',required=True,help='Existing SQLite file. Never modified.')
|
||
|
|
ap.add_argument('--confirmed-offline',action='store_true')
|
||
|
|
ap.add_argument('--report',help='Output machine-readable verification summary')
|
||
|
|
args=ap.parse_args(argv)
|
||
|
|
try:
|
||
|
|
result=migrate(args.source,confirmed_offline=args.confirmed_offline)
|
||
|
|
summary=json.dumps(result,ensure_ascii=False,indent=2)
|
||
|
|
if args.report:
|
||
|
|
from pathlib import Path
|
||
|
|
out=Path(args.report).resolve()
|
||
|
|
if out.exists():raise RecoveryError('Refuse overwriting prior validation report')
|
||
|
|
out.parent.mkdir(parents=True,exist_ok=True);out.write_text(summary,encoding='utf-8')
|
||
|
|
print(summary);return 0
|
||
|
|
except (RecoveryError,OSError,ValueError) as ex:
|
||
|
|
print('MIGRATION FAILED: '+str(ex),file=sys.stderr);return 1
|
||
|
|
|
||
|
|
if __name__=='__main__':raise SystemExit(main())
|