Skip to main content

Overview

The billeteras table stores wallet accounts for users. Each user can create multiple wallets to organize their finances across different accounts (e.g., cash, bank account, savings).

Table Schema

Columns

id
UUID
required
Primary key. Auto-generated unique identifier for the wallet.
nombre
VARCHAR
required
Wallet name. User-defined label for the wallet (max 13 characters).
usuario_id
UUID
required
Foreign key to auth.users. Links the wallet to its owner.
created_at
TIMESTAMPTZ
Timestamp when the wallet was created. Auto-set by database.
updated_at
TIMESTAMPTZ
Timestamp when the wallet was last modified. Auto-updated.

Relationships

  • One-to-Many with transacciones: A wallet can have many transactions
  • Many-to-One with auth.users: Each wallet belongs to one user

Row Level Security (RLS)

The table enforces RLS policies to ensure users can only access their own wallets:
CREATE POLICY "Users can view their own wallets"
  ON billeteras FOR SELECT
  USING (auth.uid() = usuario_id);

CREATE POLICY "Users can insert their own wallets"
  ON billeteras FOR INSERT
  WITH CHECK (auth.uid() = usuario_id);

CREATE POLICY "Users can update their own wallets"
  ON billeteras FOR UPDATE
  USING (auth.uid() = usuario_id);

CREATE POLICY "Users can delete their own wallets"
  ON billeteras FOR DELETE
  USING (auth.uid() = usuario_id);

Example Queries

Fetch All Wallets for Current User

const { data, error } = await supabase
  .from("billeteras")
  .select("id, nombre")
  .order("nombre", { ascending: true });

Create a New Wallet

const { data, error } = await supabase
  .from("billeteras")
  .insert({
    nombre: "Savings Account",
    usuario_id: user.id
  });

Update Wallet Name

const { error } = await supabase
  .from("billeteras")
  .update({ nombre: "Emergency Fund" })
  .eq("id", walletId);

Delete a Wallet

Ensure the wallet has no associated transactions before deleting. The application checks for this constraint.
const { error } = await supabase
  .from("billeteras")
  .delete()
  .eq("id", walletId);

Validation Rules

  • Name Length: Maximum 13 characters (enforced in UI)
  • Name Required: Cannot be empty or null
  • User Ownership: Must belong to authenticated user
  • Deletion Constraint: Cannot delete wallets with transactions

Indexes

CREATE INDEX idx_billeteras_usuario_id ON billeteras(usuario_id);
CREATE INDEX idx_billeteras_nombre ON billeteras(nombre);

Transactions

View transactions associated with wallets

Categories

Categories used in wallet transactions

Build docs developers (and LLMs) love