Tables
Detailed documentation of all database tables
Overview
The BudgetBuddyDE schema contains the following tables:
- payment_method: Payment methods and accounts
- category: Categories for transactions
- transaction: Individual financial transactions
- recurring_payment: Recurring payments
- budget: Budgets/spending goals
- budget_category: Link between budgets and categories
payment_method
Stores payment methods such as bank accounts, credit cards, or digital wallets.
Fields
| Field | Type | Constraints | Description |
|---|---|---|---|
payment_method_id | UUID | PRIMARY KEY, DEFAULT RANDOM | Unique ID of the payment method |
owner_id | VARCHAR | NOT NULL | Owner's ID |
name | VARCHAR(40) | NOT NULL | Name of the payment method |
provider | VARCHAR(32) | NOT NULL | Provider (e.g., "Sparkasse", "Visa") |
address | VARCHAR(32) | NOT NULL | Account number/address |
description | TEXT | NULLABLE | Optional description |
created_at | TIMESTAMP WITH TIMEZONE | NOT NULL, DEFAULT NOW | Creation timestamp |
updated_at | TIMESTAMP WITH TIMEZONE | NOT NULL, DEFAULT NOW | Last update timestamp |
Relationships
- Has Many:
transaction(viapayment_method_id) - Has Many:
recurring_payment(viapayment_method_id)
Example
category
Categories for classifying transactions (e.g., "Groceries", "Rent", "Salary").
Fields
| Field | Type | Constraints | Description |
|---|---|---|---|
category_id | UUID | PRIMARY KEY, DEFAULT RANDOM | Unique ID of the category |
owner_id | VARCHAR | NOT NULL | Owner's ID |
name | VARCHAR(40) | NOT NULL | Name of the category |
description | TEXT | NULLABLE | Optional description |
created_at | TIMESTAMP WITH TIMEZONE | NOT NULL, DEFAULT NOW | Creation timestamp |
updated_at | TIMESTAMP WITH TIMEZONE | NOT NULL, DEFAULT NOW | Last update timestamp |
Relationships
- Has Many:
transaction(viacategory_id) - Has Many:
recurring_payment(viacategory_id) - Has Many:
budget_category(viacategory_id)
Example
transaction
Central table for all financial transactions (income and expenses).
Fields
| Field | Type | Constraints | Description |
|---|---|---|---|
transaction_id | UUID | PRIMARY KEY, DEFAULT RANDOM | Unique ID of the transaction |
owner_id | VARCHAR | NOT NULL | Owner's ID |
category_id | UUID | NOT NULL, FK → category(category_id) ON DELETE CASCADE | Transaction category |
payment_method_id | UUID | NOT NULL, FK → payment_method(payment_method_id) ON DELETE CASCADE | Payment method used |
processed_at | TIMESTAMP | NOT NULL | Transaction timestamp |
receiver | VARCHAR(100) | NOT NULL | Receiver/sender |
transfer_amount | DOUBLE PRECISION | NOT NULL | Amount (positive = income, negative = expense) |
information | TEXT | NULLABLE | Additional information |
created_at | TIMESTAMP WITH TIMEZONE | NOT NULL, DEFAULT NOW | Creation timestamp |
updated_at | TIMESTAMP WITH TIMEZONE | NOT NULL, DEFAULT NOW | Last update timestamp |
Relationships
- Belongs To:
category(viacategory_id) - Belongs To:
payment_method(viapayment_method_id)
Specifics
- Positive amounts: Income/revenue
- Negative amounts: Expenses
processed_atis the actual transaction time, not the booking time
Example
recurring_payment
Recurring payments that are automatically processed on a specific day of the month.
Fields
| Field | Type | Constraints | Description |
|---|---|---|---|
recurring_payment_id | UUID | PRIMARY KEY, DEFAULT RANDOM | Unique ID of the recurring payment |
owner_id | VARCHAR | NOT NULL | Owner's ID |
category_id | UUID | NOT NULL, FK → category(category_id) ON DELETE CASCADE | Payment category |
payment_method_id | UUID | NOT NULL, FK → payment_method(payment_method_id) ON DELETE CASCADE | Payment method used |
execute_at | INTEGER | NOT NULL | Day of month (1-31) for execution |
paused | BOOLEAN | NOT NULL, DEFAULT false | Is the payment paused? |
receiver | VARCHAR(100) | NOT NULL | Receiver/sender |
transfer_amount | DOUBLE PRECISION | NOT NULL | Amount |
information | TEXT | NULLABLE | Additional information |
created_at | TIMESTAMP WITH TIMEZONE | NOT NULL, DEFAULT NOW | Creation timestamp |
updated_at | TIMESTAMP WITH TIMEZONE | NOT NULL, DEFAULT NOW | Last update timestamp |
Relationships
- Belongs To:
category(viacategory_id) - Belongs To:
payment_method(viapayment_method_id)
Specifics
- execute_at: For days > month length, executed at end of month (e.g., 31st is executed on Feb 28/29)
- paused: Paused payments are skipped by the job
Example
budget
Budgets/spending goals for specific categories.
Fields
| Field | Type | Constraints | Description |
|---|---|---|---|
budget_id | UUID | PRIMARY KEY, DEFAULT RANDOM | Unique ID of the budget |
owner_id | VARCHAR | NOT NULL | Owner's ID |
type | ENUM('i', 'e') | NOT NULL | Budget type: 'i' = Income, 'e' = Expense |
name | VARCHAR(32) | NOT NULL | Name of the budget |
budget | DOUBLE PRECISION | NOT NULL | Budget amount |
description | TEXT | NULLABLE | Optional description |
created_at | TIMESTAMP WITH TIMEZONE | NOT NULL, DEFAULT NOW | Creation timestamp |
updated_at | TIMESTAMP WITH TIMEZONE | NOT NULL, DEFAULT NOW | Last update timestamp |
Relationships
- Has Many:
budget_category(viabudget_id)
Enum: budget_type
'i': Income (income budget)'e': Expense (expense budget)
Example
budget_category
Junction table between budgets and categories (many-to-many).
Fields
| Field | Type | Constraints | Description |
|---|---|---|---|
budget_id | UUID | PRIMARY KEY (composite), FK → budget(budget_id) ON DELETE CASCADE | Budget ID |
category_id | UUID | PRIMARY KEY (composite), FK → category(category_id) ON DELETE CASCADE | Category ID |
Relationships
- Belongs To:
budget(viabudget_id) - Belongs To:
category(viacategory_id)
Specifics
- Composite Primary Key: Combination of
budget_idandcategory_id - Allows multiple categories per budget
- Cascade delete: When deleting a budget or category, the links are automatically removed
Example
Migrations
Database migrations are managed with Drizzle Kit:
Schema Export
The complete schema is exported from the following files:
src/db/schema/tables.ts- Table definitionssrc/db/schema/relations.ts- Relationships between tablessrc/db/schema/views.ts- View definitionssrc/db/schema/schema.ts- Schema configuration
BudgetBuddyDE