From b7a7474b9f5bbd5ba2c68b56a073866880f58765 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Thu, 13 Feb 2025 12:20:34 -0500 Subject: [PATCH 1/3] Add blob_columns for bsddb upgrade --- gramps/plugins/db/bsddb/bsddb.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/gramps/plugins/db/bsddb/bsddb.py b/gramps/plugins/db/bsddb/bsddb.py index d90737657f..c5804cf69d 100644 --- a/gramps/plugins/db/bsddb/bsddb.py +++ b/gramps/plugins/db/bsddb/bsddb.py @@ -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"), @@ -130,6 +128,22 @@ 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"): + 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): From e455fd055423b1a42bd45aa6e68fe776bff00020 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Fri, 14 Feb 2025 13:41:23 -0500 Subject: [PATCH 2/3] Add correct old-style metadata blob field --- gramps/plugins/db/bsddb/bsddb.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gramps/plugins/db/bsddb/bsddb.py b/gramps/plugins/db/bsddb/bsddb.py index c5804cf69d..6bcd950320 100644 --- a/gramps/plugins/db/bsddb/bsddb.py +++ b/gramps/plugins/db/bsddb/bsddb.py @@ -131,9 +131,14 @@ def load( self.dbapi.begin() for old_name, table_name in tables: if not self.dbapi.column_exists(table_name, "blob_data"): - self.dbapi.execute( - f"ALTER TABLE {table_name} ADD COLUMN blob_data BLOB;" - ) + 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 From fc8466bedf7ec5c31d9d296422d78dd540ff4998 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Fri, 14 Feb 2025 13:42:50 -0500 Subject: [PATCH 3/3] Don't write out null metadata --- gramps/plugins/db/bsddb/bsddb.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gramps/plugins/db/bsddb/bsddb.py b/gramps/plugins/db/bsddb/bsddb.py index 6bcd950320..44c696e862 100644 --- a/gramps/plugins/db/bsddb/bsddb.py +++ b/gramps/plugins/db/bsddb/bsddb.py @@ -236,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()