From 1fa152f475340f8b6a3fb717776cb38ab298f15d Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 29 Oct 2022 14:11:29 -0700 Subject: [PATCH] Don't rebuild tables that weren't authored by user. Since generated columsn appear in the output but not the input, it was crashing. The author of the migrate will know what to do. --- utilities/database_upgrader.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/utilities/database_upgrader.py b/utilities/database_upgrader.py index b0b24d2..7dce720 100644 --- a/utilities/database_upgrader.py +++ b/utilities/database_upgrader.py @@ -31,11 +31,9 @@ class Migrator: def __init__(self, photodb): self.photodb = photodb - query = 'SELECT name, sql FROM sqlite_master WHERE type == "table"' - self.tables = { - name: {'create': sql, 'transfer': f'INSERT INTO {name} SELECT * FROM {name}_old'} - for (name, sql) in self.photodb.select(query) - } + query = 'SELECT name FROM sqlite_master WHERE type == "table"' + table_names = list(self.photodb.select(query)) + self.tables = {name: {} for name in table_names} # The user may be adding entirely new tables derived from the data of # old ones. We'll need to skip new tables for the rename and drop_old @@ -56,15 +54,19 @@ class Migrator: for (name, query) in self.indices: self.photodb.execute(f'DROP INDEX {name}') - for (name, table) in self.tables.items(): + self.tables = {name: table for (name, table) in self.tables.items() if len(table) > 0} + + for name in self.tables.keys(): if name not in self.existing_tables: continue self.photodb.execute(f'ALTER TABLE {name} RENAME TO {name}_old') for (name, table) in self.tables.items(): + log.debug(table['create']) self.photodb.execute(table['create']) for (name, table) in self.tables.items(): + log.debug(table['transfer']) self.photodb.execute(table['transfer']) for (name, query) in self.tables.items():