diff --git a/migrations/20241218042446_even-more-categories.down.sql b/migrations/20241218042446_even-more-categories.down.sql new file mode 100644 index 0000000..de51b07 --- /dev/null +++ b/migrations/20241218042446_even-more-categories.down.sql @@ -0,0 +1,26 @@ +BEGIN; + +ALTER TYPE expense_category RENAME TO expense_category_old; + +CREATE TYPE expense_category AS ENUM ( + 'restaurants', + 'shopping', + 'services', + 'entertainment', + 'groceries', + 'salary', + 'interest Income', + 'utilities', + 'pharmacy', + 'transfer', + 'transport', + 'others' +); + +ALTER TABLE expenses + ALTER COLUMN category TYPE expense_category + USING category::text::expense_category; + +DROP TYPE expense_category_old; + +COMMIT; diff --git a/migrations/20241218042446_even-more-categories.up.sql b/migrations/20241218042446_even-more-categories.up.sql new file mode 100644 index 0000000..ca26e97 --- /dev/null +++ b/migrations/20241218042446_even-more-categories.up.sql @@ -0,0 +1,22 @@ +BEGIN; +ALTER TYPE expense_category RENAME TO expense_category_old; +CREATE TYPE expense_category AS ENUM ( + 'restaurants', + 'shopping', + 'services', + 'entertainment', + 'groceries', + 'salary', + 'interestincome', + 'utilities', + 'pharmacy', + 'transfer', + 'transport', + 'others', + 'investments' +); +ALTER TABLE expenses + ALTER COLUMN category TYPE expense_category + USING category::text::expense_category; +DROP TYPE expense_category_old; +COMMIT; diff --git a/src/schema.rs b/src/schema.rs index 7dbf115..0cea99d 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -17,6 +17,7 @@ pub enum ExpenseCategory { Entertainment, Groceries, Salary, + #[serde(rename = "Interest Income")] InterestIncome, Utilities, Pharmacy, @@ -24,6 +25,7 @@ pub enum ExpenseCategory { Transport, #[default] Others, + Investments, } impl FromStr for ExpenseCategory { @@ -37,7 +39,7 @@ impl FromStr for ExpenseCategory { "Entertainment" => return Ok(Self::Entertainment), "Groceries" => return Ok(Self::Groceries), "Salary" => return Ok(Self::Salary), - "InterestIncome" => return Ok(Self::InterestIncome), + "Interest Income" => return Ok(Self::InterestIncome), "Utilities" => return Ok(Self::Utilities), "Pharmacy" => return Ok(Self::Pharmacy), "Transfer" => return Ok(Self::Transfer), @@ -57,12 +59,13 @@ impl Display for ExpenseCategory { Self::Entertainment => return write!(fmtr, "Entertainment"), Self::Groceries => return write!(fmtr, "Groceries"), Self::Salary => return write!(fmtr, "Salary"), - Self::InterestIncome => return write!(fmtr, "InterestIncome"), + Self::InterestIncome => return write!(fmtr, "Interest Income"), Self::Utilities => return write!(fmtr, "Utilities"), Self::Pharmacy => return write!(fmtr, "Pharmacy"), Self::Transfer => return write!(fmtr, "Transfer"), Self::Transport => return write!(fmtr, "Transport"), Self::Others => return write!(fmtr, "Others"), + Self::Investments => return write!(fmtr, "Investments"), } } }