Overview
Thecategorias table stores user-defined categories for organizing income and expense transactions. Each category has a type (income or expense) and can be used across multiple transactions.
Table Schema
Columns
Primary key. Auto-generated unique identifier for the category.
Category name. User-defined label for the category.
Category type. Either
"gasto" (expense) or "ingreso" (income).Foreign key to
auth.users. Links the category to its owner.Timestamp when the category was created. Auto-set by database.
Timestamp when the category was last modified. Auto-updated.
Relationships
- One-to-Many with
transacciones: A category can be used in many transactions - One-to-Many with
presupuestos: An expense category can have multiple budgets - Many-to-One with
auth.users: Each category belongs to one user
Row Level Security (RLS)
The table enforces RLS policies:Example Queries
Fetch All Categories
Fetch Categories by Type
Create a New Category
Calculate Category Usage
Category Types
- Gasto (Expense)
- Ingreso (Income)
Categories for tracking spending.Common examples:
- Food & Dining
- Transportation
- Housing
- Utilities
- Entertainment
- Healthcare
- Can have budgets assigned
- Displayed with red indicators
- Used in expense breakdowns
Validation Rules
- Name Required: Cannot be empty or null
- Type Required: Must be either
"gasto"or"ingreso" - Type Immutable: Cannot change category type after creation (to maintain data integrity)
- Deletion Constraint: Cannot delete categories with associated transactions
Default Category
The system uses
"Sin categoría" (Uncategorized) as a fallback when a category is not specified or has been deleted. This is handled at the application level, not in the database.Indexes
Related Tables
Transactions
Transactions using these categories
Budgets
Budget limits by expense category
