The presupuestos table stores budget limits set by users for expense categories. Each budget defines a spending limit for a specific category and time period (typically monthly).
CREATE POLICY "Users can view their own budgets" ON presupuestos FOR SELECT USING (auth.uid() = usuario_id);CREATE POLICY "Users can insert their own budgets" ON presupuestos FOR INSERT WITH CHECK (auth.uid() = usuario_id);CREATE POLICY "Users can update their own budgets" ON presupuestos FOR UPDATE USING (auth.uid() = usuario_id);CREATE POLICY "Users can delete their own budgets" ON presupuestos FOR DELETE USING (auth.uid() = usuario_id);
CREATE INDEX idx_presupuestos_usuario_id ON presupuestos(usuario_id);CREATE INDEX idx_presupuestos_categoria_id ON presupuestos(categoria_id);CREATE INDEX idx_presupuestos_periodo ON presupuestos(periodo DESC);CREATE UNIQUE INDEX idx_presupuestos_unique ON presupuestos(usuario_id, categoria_id, periodo);
The unique index prevents duplicate budgets for the same category and period.