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.
This commit is contained in:
parent
cd8aad63b9
commit
1fa152f475
1 changed files with 8 additions and 6 deletions
|
@ -31,11 +31,9 @@ class Migrator:
|
||||||
def __init__(self, photodb):
|
def __init__(self, photodb):
|
||||||
self.photodb = photodb
|
self.photodb = photodb
|
||||||
|
|
||||||
query = 'SELECT name, sql FROM sqlite_master WHERE type == "table"'
|
query = 'SELECT name FROM sqlite_master WHERE type == "table"'
|
||||||
self.tables = {
|
table_names = list(self.photodb.select(query))
|
||||||
name: {'create': sql, 'transfer': f'INSERT INTO {name} SELECT * FROM {name}_old'}
|
self.tables = {name: {} for name in table_names}
|
||||||
for (name, sql) in self.photodb.select(query)
|
|
||||||
}
|
|
||||||
|
|
||||||
# The user may be adding entirely new tables derived from the data of
|
# 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
|
# 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:
|
for (name, query) in self.indices:
|
||||||
self.photodb.execute(f'DROP INDEX {name}')
|
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:
|
if name not in self.existing_tables:
|
||||||
continue
|
continue
|
||||||
self.photodb.execute(f'ALTER TABLE {name} RENAME TO {name}_old')
|
self.photodb.execute(f'ALTER TABLE {name} RENAME TO {name}_old')
|
||||||
|
|
||||||
for (name, table) in self.tables.items():
|
for (name, table) in self.tables.items():
|
||||||
|
log.debug(table['create'])
|
||||||
self.photodb.execute(table['create'])
|
self.photodb.execute(table['create'])
|
||||||
|
|
||||||
for (name, table) in self.tables.items():
|
for (name, table) in self.tables.items():
|
||||||
|
log.debug(table['transfer'])
|
||||||
self.photodb.execute(table['transfer'])
|
self.photodb.execute(table['transfer'])
|
||||||
|
|
||||||
for (name, query) in self.tables.items():
|
for (name, query) in self.tables.items():
|
||||||
|
|
Loading…
Reference in a new issue