Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blob columns for bsddb upgrade #1969

Open
wants to merge 3 commits into
base: maintenance/gramps60
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions gramps/plugins/db/bsddb/bsddb.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,11 @@ def load(
username=username,
password=password,
)
# Default new DBAPI uses "json" serializer
# So, we force read/write in blobs:
self.set_serializer("blob")

# now read in the bsddb and copy to dbapi
schema_vers = None
total = 0
# Because this is an old version of a gramps database
# we need to make sure it goes into blobs. So we make
# a blob_data column for all of the tables:

tables = (
("person", "person"),
("family", "family"),
Expand All @@ -130,6 +128,27 @@ def load(
("meta_data", "metadata"),
)

self.dbapi.begin()
for old_name, table_name in tables:
if not self.dbapi.column_exists(table_name, "blob_data"):
if table_name == "metadata":
self.dbapi.execute(
f"ALTER TABLE {table_name} ADD COLUMN value BLOB;"
)
else:
self.dbapi.execute(
f"ALTER TABLE {table_name} ADD COLUMN blob_data BLOB;"
)
self.dbapi.commit()

# Default new DBAPI uses "json" serializer
# So, we force read/write in blobs:
self.set_serializer("blob")

# now read in the bsddb and copy to dbapi
schema_vers = None
total = 0

# open each dbmap, and get its length for the total
file_name = os.path.join(dirname, "name_group.db")
if os.path.isfile(file_name):
Expand Down Expand Up @@ -217,7 +236,8 @@ def load(
# These are list, but need to be set
data = set(data)

self._set_metadata(key.decode("utf-8"), data)
if data is not None:
self._set_metadata(key.decode("utf-8"), data)
else:
# Not metadata, but gramps object
self._txn_begin()
Expand Down