Bugfix exportdb migration 794 (#795)

* Fixed migration for already migrated database, #794

* Version bump
This commit is contained in:
Rhet Turnbull
2022-09-25 07:55:15 -07:00
committed by GitHub
parent eedc2f0b05
commit 191a2cd618
4 changed files with 39 additions and 6 deletions

View File

@@ -1,3 +1,3 @@
""" version info """
__version__ = "0.51.7"
__version__ = "0.51.8"

View File

@@ -740,10 +740,16 @@ class ExportDB:
def _migrate_7_0_to_7_1(self, conn):
c = conn.cursor()
c.execute("""ALTER TABLE export_data ADD COLUMN timestamp DATETIME;""")
# timestamp column should not exist but this prevents error if migration is run on an already migrated database
# reference #794
results = c.execute(
"SELECT COUNT(*) FROM pragma_table_info('export_data') WHERE name='timestamp';"
).fetchone()
if results[0] == 0:
c.execute("""ALTER TABLE export_data ADD COLUMN timestamp DATETIME;""")
c.execute(
"""
CREATE TRIGGER insert_timestamp_trigger
CREATE TRIGGER IF NOT EXISTS insert_timestamp_trigger
AFTER INSERT ON export_data
BEGIN
UPDATE export_data SET timestamp = STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW') WHERE id = NEW.id;
@@ -752,7 +758,7 @@ class ExportDB:
)
c.execute(
"""
CREATE TRIGGER update_timestamp_trigger
CREATE TRIGGER IF NOT EXISTS update_timestamp_trigger
AFTER UPDATE On export_data
BEGIN
UPDATE export_data SET timestamp = STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW') WHERE id = NEW.id;