diff --git a/finnow-api/sql/schema.sql b/finnow-api/sql/schema.sql index 3846c8a..6cd6c3a 100644 --- a/finnow-api/sql/schema.sql +++ b/finnow-api/sql/schema.sql @@ -148,8 +148,8 @@ CREATE TABLE account_value_record ( ); CREATE TABLE account_value_record_attachment ( - value_record_id BIGINT NOT NULL, - attachment_id BIGINT NOT NULL, + value_record_id INTEGER NOT NULL, + attachment_id INTEGER NOT NULL, PRIMARY KEY (value_record_id, attachment_id), CONSTRAINT fk_account_value_record_attachment_value_record FOREIGN KEY (value_record_id) REFERENCES account_value_record(id) @@ -161,20 +161,24 @@ CREATE TABLE account_value_record_attachment ( -- History Entities -CREATE TABLE history ( - id INTEGER PRIMARY KEY -); - CREATE TABLE history_item ( id INTEGER PRIMARY KEY, - history_id INTEGER NOT NULL, - timestamp TEXT NOT NULL, - type TEXT NOT NULL, - CONSTRAINT fk_history_item_history - FOREIGN KEY (history_id) REFERENCES history(id) + timestamp TEXT NOT NULL +); + +CREATE TABLE account_history_item ( + account_id INTEGER NOT NULL, + history_item_id INTEGER NOT NULL, + PRIMARY KEY (account_id, history_item_id), + CONSTRAINT fk_account_history_item_account + FOREIGN KEY (account_id) REFERENCES account(id) + ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT fk_account_history_item_history_item + FOREIGN KEY (history_item_id) REFERENCES history_item(id) ON UPDATE CASCADE ON DELETE CASCADE ); +-- Zero or more plain text messages may be logged for any history item. CREATE TABLE history_item_text ( item_id INTEGER PRIMARY KEY, content TEXT NOT NULL, @@ -183,26 +187,40 @@ CREATE TABLE history_item_text ( ON UPDATE CASCADE ON DELETE CASCADE ); -CREATE TABLE account_history ( - account_id INTEGER NOT NULL UNIQUE, - history_id INTEGER NOT NULL, - PRIMARY KEY (account_id, history_id), - CONSTRAINT fk_account_history_account - FOREIGN KEY (account_id) REFERENCES account(id) - ON UPDATE CASCADE ON DELETE CASCADE, - CONSTRAINT fk_account_history_history - FOREIGN KEY (history_id) REFERENCES history(id) +-- Zero or more property changes may be logged for any history item. +CREATE TABLE history_item_property_change ( + item_id INTEGER NOT NULL, + property_name TEXT NOT NULL, + old_value TEXT, + new_value TEXT, + PRIMARY KEY (item_id, property_name), + CONSTRAINT fk_history_item_property_change_item + FOREIGN KEY (item_id) REFERENCES history_item(id) ON UPDATE CASCADE ON DELETE CASCADE ); -CREATE TABLE transaction_history ( - transaction_id INTEGER NOT NULL UNIQUE, - history_id INTEGER NOT NULL, - PRIMARY KEY (transaction_id, history_id), - CONSTRAINT fk_history_transaction_transaction - FOREIGN KEY (transaction_id) REFERENCES "transaction"(id) +-- Links a value record to a history item, used to include value records in an account's history. +CREATE TABLE history_item_linked_value_record ( + item_id INTEGER NOT NULL, + value_record_id INTEGER NOT NULL, + PRIMARY KEY (item_id, value_record_id), + CONSTRAINT fk_history_item_linked_value_record_item + FOREIGN KEY (item_id) REFERENCES history_item(id) ON UPDATE CASCADE ON DELETE CASCADE, - CONSTRAINT fk_history_transaction_history - FOREIGN KEY (history_id) REFERENCES history(id) + CONSTRAINT fk_history_item_linked_value_record_value_record + FOREIGN KEY (value_record_id) REFERENCES account_value_record(id) + ON UPDATE CASCADE ON DELETE CASCADE +); + +-- Links a journal entry to a history item, used to include journal entries in an account's history. +CREATE TABLE history_item_linked_journal_entry ( + item_id INTEGER NOT NULL, + journal_entry_id INTEGER NOT NULL, + PRIMARY KEY (item_id, journal_entry_id), + CONSTRAINT fk_history_item_linked_journal_entry_item + FOREIGN KEY (item_id) REFERENCES history_item(id) + ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT fk_history_item_linked_journal_entry_journal_entry + FOREIGN KEY (journal_entry_id) REFERENCES account_journal_entry(id) ON UPDATE CASCADE ON DELETE CASCADE ); diff --git a/web-app/src/components/CategoryLabel.vue b/web-app/src/components/CategoryLabel.vue index ddde284..aaa9f54 100644 --- a/web-app/src/components/CategoryLabel.vue +++ b/web-app/src/components/CategoryLabel.vue @@ -1,10 +1,20 @@