From 74827ac9addcf1dced6a490ce771b659b12a15c6 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Sat, 14 Mar 2020 15:12:56 -0400 Subject: [PATCH] sqlExport: Fix missing transactions by making whole row unique This is probably not a good way to fix this, but it does work. Fixes #2 --- sqlExport.py | 4 +++- tableMapping.yaml | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sqlExport.py b/sqlExport.py index 9f294fb..82c74ff 100644 --- a/sqlExport.py +++ b/sqlExport.py @@ -72,7 +72,9 @@ try: c.execute("CREATE TABLE IF NOT EXISTS transactions (" + createDefinitionsFromTableMap(tableMapping['transactions']) + - ", CONSTRAINT `fk_member_uid` FOREIGN KEY (uid) REFERENCES members(uid));") + ", UNIQUE (" + + ','.join(f'`{k}`' for k in tableMapping['transactions'].keys()) + + "), FOREIGN KEY (uid) REFERENCES members(uid));") #-- FOREIGN KEY event_id REFERENCES event eid c.execute("""CREATE TABLE IF NOT EXISTS labels ( diff --git a/tableMapping.yaml b/tableMapping.yaml index 0ad28c9..8e26562 100644 --- a/tableMapping.yaml +++ b/tableMapping.yaml @@ -78,9 +78,8 @@ members: transactions: 'sid': {type: CHAR(27)} 'uid': {type: CHAR(24)} - # TODO: this is a terrible PK - 'timestamp': {type: 'INT(11) PRIMARY KEY', source: '_dp'} # TODO: should be a real timestamp? - 'type': {source: 'Transaction Type'} + 'timestamp': {type: 'INT(11)', source: '_dp'} # TODO: should be a real timestamp? + 'type': {type: 'VARCHAR(24)', source: 'Transaction Type'} 'sum': {type: 'DECIMAL(13,4)'} 'fee': {type: 'DECIMAL(13,4)'} 'event_id': {source: 'eid'}