diff options
| author | Joe Carstairs <me@joeac.net> | 2024-10-22 07:46:43 +0100 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2024-10-22 07:46:43 +0100 |
| commit | 5824c353f978a5b9ab9696451ee3014c6a614ffc (patch) | |
| tree | bc39754ca417e84eb00b0aa9a1ae2330da0bf282 /backend/core/migrations | |
| parent | 7adaace61a4fe983eba5ded3aaaf624ce6fb9014 (diff) | |
Refactors importer to use core stuff
Diffstat (limited to 'backend/core/migrations')
| -rw-r--r-- | backend/core/migrations/2024-08-31-084439_initial_setup/down.sql | 6 | ||||
| -rw-r--r-- | backend/core/migrations/2024-08-31-084439_initial_setup/up.sql | 70 |
2 files changed, 76 insertions, 0 deletions
diff --git a/backend/core/migrations/2024-08-31-084439_initial_setup/down.sql b/backend/core/migrations/2024-08-31-084439_initial_setup/down.sql new file mode 100644 index 0000000..8cf4b1e --- /dev/null +++ b/backend/core/migrations/2024-08-31-084439_initial_setup/down.sql @@ -0,0 +1,6 @@ +DROP TABLE accounts; +DROP TABLE budget_updates; +DROP TABLE categories; +DROP TABLE transaction_categorisations; +DROP TABLE category_transfers; +DROP TABLE transactions; diff --git a/backend/core/migrations/2024-08-31-084439_initial_setup/up.sql b/backend/core/migrations/2024-08-31-084439_initial_setup/up.sql new file mode 100644 index 0000000..3584ae7 --- /dev/null +++ b/backend/core/migrations/2024-08-31-084439_initial_setup/up.sql @@ -0,0 +1,70 @@ +PRAGMA foreign_keys = ON; + +CREATE TABLE accounts( + id INTEGER NOT NULL PRIMARY KEY, + name TEXT NOT NULL, + opening_balance INTEGER NOT NULL, + opening_date TEXT NOT NULL +); + +CREATE TABLE budget_updates( + id INTEGER NOT NULL PRIMARY KEY, + category_id INTEGER NOT NULL, + date TEXT NOT NULL, + new_budget INTEGER NOT NULL, + new_period INTEGER NOT NULL, + FOREIGN KEY (category_id) + REFERENCES categories (id) + ON UPDATE CASCADE + ON DELETE RESTRICT +); + +CREATE TABLE categories( + id INTEGER NOT NULL PRIMARY KEY, + name TEXT NOT NULL +); + +CREATE TABLE category_transfers( + id INTEGER NOT NULL PRIMARY KEY, + description TEXT NOT NULL, + quantity INTEGER NOT NULL, + from_category_id INTEGER NOT NULL, + to_category_id INTEGER NOT NULL, + FOREIGN KEY (from_category_id) + REFERENCES categories (id) + ON UPDATE CASCADE + ON DELETE RESTRICT, + FOREIGN KEY (to_category_id) + REFERENCES categories (id) + ON UPDATE CASCADE + ON DELETE RESTRICT +); + +CREATE TABLE transactions( + id INTEGER NOT NULL PRIMARY KEY, + description TEXT NOT NULL, + payee TEXT NOT NULL, + quantity INTEGER NOT NULL, + date TEXT NOT NULL, + account_id INTEGER NOT NULL, + FOREIGN KEY (account_id) + REFERENCES accounts (id) + ON UPDATE CASCADE + ON DELETE RESTRICT +); + +CREATE TABLE transaction_categorisations( + id INTEGER NOT NULL PRIMARY KEY, + description TEXT NOT NULL, + quantity INTEGER NOT NULL, + transaction_id INTEGER NOT NULL, + category_id INTEGER NOT NULL, + FOREIGN KEY (transaction_id) + REFERENCES transactions (id) + ON UPDATE CASCADE + ON DELETE RESTRICT, + FOREIGN KEY (category_id) + REFERENCES categories (id) + ON UPDATE CASCADE + ON DELETE RESTRICT +); |
