Cadangan otomatis DB berskema lama tepat sebelum migrasi go-live
init_db menyalin /data/app.db → /data/app.db.sebelum-golive-<waktu> (sqlite backup API, konsisten) hanya bila skema masih OBE-Mapping (peran dosen_rps_mk) — sekali, di volume persisten. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
2bab18fdf3
commit
99a1655f56
@@ -22,9 +22,19 @@ krs0 = sorted(tuple(r) for r in src.execute("SELECT nim, nama, mk_kode, kelas, t
|
||||
tugas0 = [dict(r) for r in src.execute("SELECT p.user_id, p.mk_kode, p.kelas, u.role FROM penugasan p JOIN pengguna u ON u.id=p.user_id")]
|
||||
token = src.execute("SELECT s.token, s.user_id FROM sesi s ORDER BY s.rowid DESC LIMIT 1").fetchone()
|
||||
|
||||
import glob
|
||||
for f in glob.glob(SALIN + ".sebelum-golive-*"):
|
||||
os.remove(f)
|
||||
from app import db
|
||||
db.init_db(); db.init_db() # dua kali: idempoten
|
||||
cek(True, "init_db berjalan (2×) tanpa galat")
|
||||
cad = glob.glob(SALIN + ".sebelum-golive-*")
|
||||
cek(len(cad) == 1, f"cadangan otomatis sebelum migrasi dibuat tepat sekali ({len(cad)})")
|
||||
if cad:
|
||||
cc = sqlite3.connect(cad[0])
|
||||
cek("dosen_rps_mk" in cc.execute("SELECT sql FROM sqlite_master WHERE name='pengguna'").fetchone()[0]
|
||||
and cc.execute("SELECT COUNT(*) FROM rps").fetchone()[0] == len(rps0), "cadangan berisi skema & data lama utuh")
|
||||
cc.close()
|
||||
c = db.get_conn()
|
||||
akun1 = {r["id"]: dict(r) for r in c.execute("SELECT * FROM pengguna")}
|
||||
cek(set(akun1) == set(akun0), f"{len(akun1)} akun, ID sama")
|
||||
|
||||
Reference in New Issue
Block a user