aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-07-26 07:53:55 +0300
committerFrederick Muriuki Muriithi2023-07-26 15:46:34 +0300
commit495e581754acd2692e3db08cb1760f75b050d1d0 (patch)
treefbe59454606a4c8d91d76f0b63c7bfe059c70d26 /gn3
parent9ce0eb0982dd2e92e15a87b124e77a6e954869a3 (diff)
downloadgenenetwork3-495e581754acd2692e3db08cb1760f75b050d1d0.tar.gz
Function to create a metadata audit trail.
Diffstat (limited to 'gn3')
-rw-r--r--gn3/db/metadata_audit.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/gn3/db/metadata_audit.py b/gn3/db/metadata_audit.py
index 9c4474d..707892b 100644
--- a/gn3/db/metadata_audit.py
+++ b/gn3/db/metadata_audit.py
@@ -3,9 +3,10 @@
table from the db
"""
-from dataclasses import dataclass
from typing import Optional
+from dataclasses import dataclass
+from MySQLdb.cursors import DictCursor
@dataclass(frozen=True)
class MetadataAudit:
@@ -26,3 +27,12 @@ metadata_audit_mapping = {
"json_data": "json_diff_data",
"time_stamp": "time_stamp",
}
+
+def create_metadata_audit(conn, metadata: dict) -> int:
+ """Create a new metadata audit trail."""
+ with conn.cursor(cursorclass=DictCursor) as cursor:
+ cursor.execute(
+ "INSERT INTO metadata_audit (dataset_id, editor, json_diff_data) "
+ "VALUES (%(dataset_id)s, %(editor)s, %(json_data)s)",
+ metadata)
+ return cursor.rowcount