diff options
author | Frederick Muriuki Muriithi | 2023-07-26 07:53:55 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-07-26 15:46:34 +0300 |
commit | 495e581754acd2692e3db08cb1760f75b050d1d0 (patch) | |
tree | fbe59454606a4c8d91d76f0b63c7bfe059c70d26 /gn3 | |
parent | 9ce0eb0982dd2e92e15a87b124e77a6e954869a3 (diff) | |
download | genenetwork3-495e581754acd2692e3db08cb1760f75b050d1d0.tar.gz |
Function to create a metadata audit trail.
Diffstat (limited to 'gn3')
-rw-r--r-- | gn3/db/metadata_audit.py | 12 |
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 |