Skip to content

Commit

Permalink
Rough draft of a db upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
dsblank committed Oct 10, 2024
1 parent f3a7510 commit e1cab51
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions scripts/unpickle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os
os.environ["GRAMPS_RESOURCES"] = "/home/dsblank/gramps/gramps"

from gramps.gen.db.utils import open_database
import pickle
import json

db = open_database("Example")

###########################################################################
try:
db.dbapi.execute("ALTER TABLE family ADD COLUMN unblob TEXT;")
db.dbapi.commit()
except Exception:
pass

db.dbapi.execute("SELECT handle from family;")
handles = [x[0] for x in db.dbapi.fetchall()]

for handle in handles:
db.dbapi.execute("SELECT blob_data FROM family WHERE handle = ? limit 1;", [handle])
row = db.dbapi.fetchone()
unblob = json.dumps(pickle.loads(row[0]))
db.dbapi.execute("UPDATE family SET unblob = ? where handle = ?;", [unblob, handle])
db.dbapi.commit()
###########################################################################
try:
db.dbapi.execute("ALTER TABLE person ADD COLUMN unblob TEXT;")
except Exception:
pass

db.dbapi.execute("SELECT handle from person;")
handles = [x[0] for x in db.dbapi.fetchall()]

for handle in handles:
db.dbapi.execute("SELECT blob_data FROM person WHERE handle = ? limit 1;", [handle])
row = db.dbapi.fetchone()
unblob = json.dumps(pickle.loads(row[0]))
db.dbapi.execute("UPDATE person SET unblob = ? where handle = ?;", [unblob, handle])
db.dbapi.commit()
db.close()

0 comments on commit e1cab51

Please sign in to comment.