Skip to content
This repository was archived by the owner on Dec 6, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/config_files/logging_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ formatters:
handlers:
stderr:
class: logging.StreamHandler
level: DEBUG
level: INFO
formatter: nodate
stream: ext://sys.stdout
file:
Expand Down
16 changes: 8 additions & 8 deletions src/config_files/verity_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ tables:
- column_name: user_id
is_pk: False
datatype: INTEGER
is_fk: user.id
is_fk: user
nullable: False
- column_name: type_id
is_pk: False
datatype: INTEGER
is_fk: account_type.id
is_fk: account_type
nullable: False
- column_name: name
is_pk: False
Expand Down Expand Up @@ -75,7 +75,7 @@ tables:
- column_name: user_id
is_pk: False
datatype: INTEGER
is_fk: user.id
is_fk: user
nullable: False
- column_name: name
is_pk: False
Expand All @@ -88,7 +88,7 @@ tables:
- column_name: parent_id
is_pk: False
datatype: INTEGER
is_fk: category.id
is_fk: category
nullable: True

- table_name: transaction_log
Expand All @@ -100,22 +100,22 @@ tables:
- column_name: account_id
is_pk: False
datatype: INTEGER
is_fk: account.id
is_fk: account
nullable: False
- column_name: party_id
is_pk: False
datatype: INTEGER
is_fk: party.id
is_fk: party
nullable: True
- column_name: type_id
is_pk: False
datatype: INTEGER
is_fk: transaction_type.id
is_fk: transaction_type
nullable: False
- column_name: category_id
is_pk: False
datatype: INTEGER
is_fk: category.id
is_fk: category
nullable: True
- column_name: amount
is_pk: False
Expand Down
16 changes: 6 additions & 10 deletions src/data_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,23 @@ def read_database(self, sql_statement: str):

@staticmethod
def _build_column(column: dict) -> str:
logging.debug(
f"building column {column}"
)
name = column["column_name"]
is_pk = column["is_pk"]
is_fk = column.get("is_fk")
datatype = column["datatype"]
nullable = column["nullable"]
column_string = f"{name} {datatype}"
if is_pk:
column_string += " PRIMARY KEY AUTOINCREMENT"
if is_fk:
column_string += f" REFERENCES {column['is_fk']} "
if not nullable:
column_string += " NOT NULL"
return column_string

@staticmethod
def _build_foreign_key(key: dict) -> str:
column = key["column"]
ref_table = key["references"]
ref_column = key["reference_column"]
return f"FOREIGN KEY ({column}) REFERENCES {ref_table} ({ref_column})"

def _add_table_to_db(self, table: dict) -> bool:
"Creates the table in the verity database, based on the schema yaml"
Expand All @@ -87,10 +87,6 @@ def _add_table_to_db(self, table: dict) -> bool:
for column in table["table_columns"]:
columns.append(self._build_column(column))
sql += ",\n".join(columns)
if table.get("table_foreign_keys", None):
sql += ",\n"
for key in table["table_foreign_keys"]:
sql += f"{self._build_foreign_key(key)}"
sql += "\n);"
success_status = False
try:
Expand Down