#!/usr/bin/env python3
"""Copies the synthetic database with SQLite backup, without changing rows.
Usage: copy-upgrade-database.py LEGACY_HOME BASE_HOME HEAD_HOME
Stop the legacy server after deleting its parent thread in the UI first.
Start each tested checkout on its own destination with T3CODE_DEV_SEED=0.
Each destination must be a fresh directory. No settings or secrets are copied.
"""
import sqlite3,pathlib,sys
source=pathlib.Path(sys.argv[1])/'userdata/statev2.sqlite'
for destination in sys.argv[2:]:
 target=pathlib.Path(destination)/'userdata'
 target.mkdir(parents=True)
 with sqlite3.connect(f'file:{source}?mode=ro',uri=True) as src, sqlite3.connect(target/'statev2.sqlite') as dst:
  src.backup(dst)
