Include CommitHash in database

This commit is contained in:
Xevion
2022-06-18 19:10:07 -05:00
parent 373d4412b9
commit 527ec25c20

View File

@@ -30,11 +30,14 @@ class Database:
cur.execute("""CREATE TABLE IF NOT EXISTS commits ( cur.execute("""CREATE TABLE IF NOT EXISTS commits (
Id text primary key not null, Id text primary key not null,
Source text not null, Source text not null,
CommitHash text not null,
CommitTimestamp text not null, CommitTimestamp text not null,
SeenTimestamp text not null, SeenTimestamp text not null,
Iteration integer not null, Iteration integer not null,
ProjectId integer not null);""") ProjectId integer not null);""")
self.conn.commit()
def open(self) -> None: def open(self) -> None:
"""Opens a connection to the database file.""" """Opens a connection to the database file."""
if self.__is_closed: if self.__is_closed:
@@ -52,13 +55,14 @@ class Database:
self.conn = None self.conn = None
self.__is_closed = True self.__is_closed = True
def add_commit(self, commit: Commit) -> None: def add_commit(self, commit: Commit, commit_hash: str) -> None:
"""Inserts a commit into the database""" """Inserts a commit into the database"""
cur = self.conn.cursor() cur = self.conn.cursor()
cur.execute("""INSERT INTO commits (Id, Source, ProjectId, Iteration, CommitTimestamp, SeenTimestamp) VALUES (?, ?, ?, ?, ?, ?)""", cur.execute("""INSERT INTO commits (Id, Source, ProjectId, CommitHash, Iteration, CommitTimestamp, SeenTimestamp) VALUES (?, ?, ?, ?, ?, ?, ?)""",
(commit.id, commit.source, commit.project_id, commit.iteration, (commit.id, commit.source, commit.project_id, commit_hash, commit.iteration,
commit.timestamp.isoformat(), commit.seen_timestamp.isoformat())) commit.timestamp.isoformat(), commit.seen_timestamp.isoformat()))
self.conn.commit()
def check_exists(self, id: str, source: Optional[str] = None) -> bool: def check_exists(self, id: str, source: Optional[str] = None) -> bool:
"""Returns true if the commit in question exists.""" """Returns true if the commit in question exists."""