diff --git a/src/config_files/logging_config.yaml b/src/config_files/logging_config.yaml index 6af3902..3d8b5b4 100644 --- a/src/config_files/logging_config.yaml +++ b/src/config_files/logging_config.yaml @@ -11,7 +11,7 @@ formatters: handlers: stderr: class: logging.StreamHandler - level: DEBUG + level: INFO formatter: nodate stream: ext://sys.stdout file: diff --git a/src/config_files/verity_schema.yaml b/src/config_files/verity_schema.yaml index 3e0d980..a9ab43c 100644 --- a/src/config_files/verity_schema.yaml +++ b/src/config_files/verity_schema.yaml @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/data_handler.py b/src/data_handler.py index 14724f7..1e2448c 100644 --- a/src/data_handler.py +++ b/src/data_handler.py @@ -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" @@ -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: