summaryrefslogtreecommitdiff
path: root/rust/schist_models/migrations
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2024-11-17 12:16:19 +0000
committerJoe Carstairs <me@joeac.net>2024-11-17 12:20:48 +0000
commit99fa72e2b9d572e00cd232bd55a3fa24722c3134 (patch)
tree6b50ce600fffa07a0c21b7f14d2447fe5ac3c2ed /rust/schist_models/migrations
parent10f071447594f2bdcec84a461df9ad648f71f44b (diff)
Refactors workspace
Diffstat (limited to 'rust/schist_models/migrations')
-rw-r--r--rust/schist_models/migrations/2024-08-31-084439_initial_setup/down.sql6
-rw-r--r--rust/schist_models/migrations/2024-08-31-084439_initial_setup/up.sql71
2 files changed, 77 insertions, 0 deletions
diff --git a/rust/schist_models/migrations/2024-08-31-084439_initial_setup/down.sql b/rust/schist_models/migrations/2024-08-31-084439_initial_setup/down.sql
new file mode 100644
index 0000000..8cf4b1e
--- /dev/null
+++ b/rust/schist_models/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/rust/schist_models/migrations/2024-08-31-084439_initial_setup/up.sql b/rust/schist_models/migrations/2024-08-31-084439_initial_setup/up.sql
new file mode 100644
index 0000000..9038b54
--- /dev/null
+++ b/rust/schist_models/migrations/2024-08-31-084439_initial_setup/up.sql
@@ -0,0 +1,71 @@
+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,
+ UNIQUE (category_id, date),
+ 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
+);