summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2024-11-27 19:47:36 +0000
committerJoe Carstairs <me@joeac.net>2024-11-28 23:10:53 +0000
commitc2e8252f5e963e8c68d7124742f3c1bdf61a083f (patch)
tree0d85e9394d90994f1757b9b1cc23780aef55f8fd /rust
parent817f6cb7e48e2517dd1612c14357d9aa066a9e53 (diff)
AccountTransfer model
Diffstat (limited to 'rust')
-rw-r--r--rust/schist_models/migrations/2024-08-31-084439_initial_setup/down.sql1
-rw-r--r--rust/schist_models/migrations/2024-08-31-084439_initial_setup/up.sql18
-rw-r--r--rust/schist_models/src/account_transfer.rs15
-rw-r--r--rust/schist_models/src/lib.rs1
-rw-r--r--rust/schist_models/src/schema.rs12
-rw-r--r--rust/schist_models/user_data.sqlitebin0 -> 45056 bytes
6 files changed, 47 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
index b9b1675..ba65012 100644
--- 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
@@ -1,4 +1,5 @@
DROP TABLE accounts;
+DROP TABLE account_transfers;
DROP TABLE budget_drips;
DROP TABLE categories;
DROP TABLE transaction_categorisations;
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
index a684ce7..a09bf7b 100644
--- 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
@@ -7,6 +7,24 @@ CREATE TABLE accounts(
opening_date TEXT NOT NULL
);
+CREATE TABLE account_transfers(
+ id INTEGER NOT NULL PRIMARY KEY,
+ date TEXT NOT NULL,
+ description TEXT NOT NULL,
+ quantity INTEGER NOT NULL,
+ from_account_id INTEGER NOT NULL,
+ to_account_id INTEGER NOT NULL,
+ FOREIGN KEY (from_account_id)
+ REFERENCES accounts (id)
+ ON UPDATE CASCADE
+ ON DELETE RESTRICT,
+ FOREIGN KEY (to_account_id)
+ REFERENCES accounts (id)
+ ON UPDATE CASCADE
+ ON DELETE RESTRICT
+);
+
+
CREATE TABLE budget_drips(
id INTEGER NOT NULL PRIMARY KEY,
category_id INTEGER NOT NULL,
diff --git a/rust/schist_models/src/account_transfer.rs b/rust/schist_models/src/account_transfer.rs
new file mode 100644
index 0000000..06c51ac
--- /dev/null
+++ b/rust/schist_models/src/account_transfer.rs
@@ -0,0 +1,15 @@
+use derive_builder::Builder;
+use diesel::prelude::{Identifiable, Insertable, Queryable, Selectable};
+
+use crate::date_utc::DateUtc;
+
+#[derive(Builder, Queryable, Identifiable, Selectable, Debug, PartialEq, Insertable)]
+#[diesel(table_name = crate::schema::account_transfers)]
+pub struct AccountTransfer {
+ pub id: i32,
+ pub date: DateUtc,
+ pub description: String,
+ pub quantity: i32,
+ pub from_account_id: i32,
+ pub to_account_id: i32,
+}
diff --git a/rust/schist_models/src/lib.rs b/rust/schist_models/src/lib.rs
index 1712c36..d9e93c4 100644
--- a/rust/schist_models/src/lib.rs
+++ b/rust/schist_models/src/lib.rs
@@ -1,4 +1,5 @@
pub mod account;
+pub mod account_transfer;
pub mod budget_drip;
pub mod budget_period_unit;
pub mod category;
diff --git a/rust/schist_models/src/schema.rs b/rust/schist_models/src/schema.rs
index 5164d07..1dd1391 100644
--- a/rust/schist_models/src/schema.rs
+++ b/rust/schist_models/src/schema.rs
@@ -1,6 +1,17 @@
// @generated automatically by Diesel CLI.
diesel::table! {
+ account_transfers (id) {
+ id -> Integer,
+ date -> Text,
+ description -> Text,
+ quantity -> Integer,
+ from_account_id -> Integer,
+ to_account_id -> Integer,
+ }
+}
+
+diesel::table! {
accounts (id) {
id -> Integer,
name -> Text,
@@ -67,6 +78,7 @@ diesel::joinable!(transaction_categorisations -> transactions (transaction_id));
diesel::joinable!(transactions -> accounts (account_id));
diesel::allow_tables_to_appear_in_same_query!(
+ account_transfers,
accounts,
budget_drips,
categories,
diff --git a/rust/schist_models/user_data.sqlite b/rust/schist_models/user_data.sqlite
new file mode 100644
index 0000000..a428ff0
--- /dev/null
+++ b/rust/schist_models/user_data.sqlite
Binary files differ