From 2809e6a2ef3ea636f3de5873f6c874923b410400 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Thu, 15 Jan 2026 22:35:39 +0000 Subject: renames categories -> buckets, refactors category_transfers -> bucket_transactions --- .../2024-08-31-084439_initial_setup/down.sql | 2 +- .../2024-08-31-084439_initial_setup/up.sql | 11 +++-------- schist_core/schist_models/src/bucket.rs | 2 -- schist_core/schist_models/src/bucket_transaction.rs | 11 +++++++++++ schist_core/schist_models/src/bucket_transfer.rs | 12 ------------ schist_core/schist_models/src/lib.rs | 4 ++-- schist_core/schist_models/src/schema.rs | 8 ++++---- schist_core/schist_models/user_data.sqlite | Bin 45056 -> 49152 bytes 8 files changed, 21 insertions(+), 29 deletions(-) create mode 100644 schist_core/schist_models/src/bucket_transaction.rs delete mode 100644 schist_core/schist_models/src/bucket_transfer.rs (limited to 'schist_core/schist_models') diff --git a/schist_core/schist_models/migrations/2024-08-31-084439_initial_setup/down.sql b/schist_core/schist_models/migrations/2024-08-31-084439_initial_setup/down.sql index 3b2c73e..f6ead07 100644 --- a/schist_core/schist_models/migrations/2024-08-31-084439_initial_setup/down.sql +++ b/schist_core/schist_models/migrations/2024-08-31-084439_initial_setup/down.sql @@ -1,7 +1,7 @@ DROP TABLE accounts; DROP TABLE account_transfers; DROP TABLE buckets; -DROP TABLE bucket_transfers; +DROP TABLE bucket_transactions; DROP TABLE drips; DROP TABLE pipes; DROP TABLE transactions; diff --git a/schist_core/schist_models/migrations/2024-08-31-084439_initial_setup/up.sql b/schist_core/schist_models/migrations/2024-08-31-084439_initial_setup/up.sql index b37c626..e645d43 100644 --- a/schist_core/schist_models/migrations/2024-08-31-084439_initial_setup/up.sql +++ b/schist_core/schist_models/migrations/2024-08-31-084439_initial_setup/up.sql @@ -32,17 +32,12 @@ CREATE TABLE buckets( name TEXT NOT NULL ); -CREATE TABLE bucket_transfers( +CREATE TABLE bucket_transactions( id INTEGER NOT NULL PRIMARY KEY, amount INTEGER NOT NULL, + bucket_id INTEGER NOT NULL, description TEXT NOT NULL, - from_bucket_id INTEGER NOT NULL, - to_bucket_id INTEGER NOT NULL, - FOREIGN KEY (from_bucket_id) - REFERENCES buckets (id) - ON UPDATE CASCADE - ON DELETE RESTRICT, - FOREIGN KEY (to_bucket_id) + FOREIGN KEY (bucket_id) REFERENCES buckets (id) ON UPDATE CASCADE ON DELETE RESTRICT diff --git a/schist_core/schist_models/src/bucket.rs b/schist_core/schist_models/src/bucket.rs index 67ed31e..debbab7 100644 --- a/schist_core/schist_models/src/bucket.rs +++ b/schist_core/schist_models/src/bucket.rs @@ -35,9 +35,7 @@ impl Bucket { .iter() .all(|t| t.bucket_id.is_none_or(|id| id != self.id)) } -} -impl Bucket { pub fn pretty_balance_per_100(&self) -> String { let abs_balance_per_100 = self.balance.unwrap_or(0).div(100).abs(); if self.balance.is_none_or(|balance| balance >= 0) { diff --git a/schist_core/schist_models/src/bucket_transaction.rs b/schist_core/schist_models/src/bucket_transaction.rs new file mode 100644 index 0000000..2aeae8a --- /dev/null +++ b/schist_core/schist_models/src/bucket_transaction.rs @@ -0,0 +1,11 @@ +use derive_builder::Builder; +use diesel::prelude::*; + +#[derive(Builder, Queryable, Identifiable, Selectable, Debug, PartialEq, Insertable)] +#[diesel(table_name = crate::schema::bucket_transactions)] +pub struct BucketTransaction { + pub id: i32, + pub amount: i32, + pub bucket_id: i32, + pub description: String, +} diff --git a/schist_core/schist_models/src/bucket_transfer.rs b/schist_core/schist_models/src/bucket_transfer.rs deleted file mode 100644 index 7c3a9d2..0000000 --- a/schist_core/schist_models/src/bucket_transfer.rs +++ /dev/null @@ -1,12 +0,0 @@ -use derive_builder::Builder; -use diesel::prelude::*; - -#[derive(Builder, Queryable, Identifiable, Selectable, Debug, PartialEq, Insertable)] -#[diesel(table_name = crate::schema::bucket_transfers)] -pub struct BucketTransfer { - pub id: i32, - pub amount: i32, - pub description: String, - pub from_bucket_id: i32, - pub to_bucket_id: i32, -} diff --git a/schist_core/schist_models/src/lib.rs b/schist_core/schist_models/src/lib.rs index 3aa4733..2a119cb 100644 --- a/schist_core/schist_models/src/lib.rs +++ b/schist_core/schist_models/src/lib.rs @@ -1,7 +1,7 @@ mod account; mod account_transfer; mod bucket; -mod bucket_transfer; +mod bucket_transaction; mod budget_period_unit; mod date_utc; mod datetime_utc; @@ -15,7 +15,7 @@ pub mod schema; pub use account::Account; pub use account_transfer::{AccountTransfer, AccountTransferBuilder}; pub use bucket::{Bucket, BucketBuilder}; -pub use bucket_transfer::{BucketTransfer, BucketTransferBuilder}; +pub use bucket_transaction::{BucketTransaction, BucketTransactionBuilder}; pub use budget_period_unit::BudgetPeriodUnit; pub use date_utc::DateUtc; pub use datetime_utc::DatetimeUtc; diff --git a/schist_core/schist_models/src/schema.rs b/schist_core/schist_models/src/schema.rs index d16e636..8744696 100644 --- a/schist_core/schist_models/src/schema.rs +++ b/schist_core/schist_models/src/schema.rs @@ -21,12 +21,11 @@ diesel::table! { } diesel::table! { - bucket_transfers (id) { + bucket_transactions (id) { id -> Integer, amount -> Integer, + bucket_id -> Integer, description -> Text, - from_bucket_id -> Integer, - to_bucket_id -> Integer, } } @@ -74,6 +73,7 @@ diesel::table! { } } +diesel::joinable!(bucket_transactions -> buckets (bucket_id)); diesel::joinable!(drips -> buckets (bucket_id)); diesel::joinable!(pipes -> buckets (bucket_id)); diesel::joinable!(transactions -> accounts (account_id)); @@ -81,7 +81,7 @@ diesel::joinable!(transactions -> accounts (account_id)); diesel::allow_tables_to_appear_in_same_query!( account_transfers, accounts, - bucket_transfers, + bucket_transactions, buckets, drips, pipes, diff --git a/schist_core/schist_models/user_data.sqlite b/schist_core/schist_models/user_data.sqlite index 175ce60..81fd25c 100644 Binary files a/schist_core/schist_models/user_data.sqlite and b/schist_core/schist_models/user_data.sqlite differ -- cgit v1.2.3