The Balsamoa database is a PostgreSQL schema hosted on Supabase. It is organized into four domains: the product catalog and its attributes, user accounts and shipping data, orders and payments, and two utility tables for the shopping cart and newsletter. All tables useDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/MateoNavarroMN/Balsamoa-Backend/llms.txt
Use this file to discover all available pages before exploring further.
SERIAL PRIMARY KEY for auto-incrementing IDs and timestamp defaults where relevant. The full schema is defined in inicializar/balsamoa.sql and can be applied to any fresh Supabase project to reproduce the exact structure, seed data, and sequence offsets.
Tables by domain
Catalog & Attributes
categorias, talles, colores, productos, producto_imagenes, variantesUsers & Roles
roles, usuarios, datos_envioOrders & Payments
estados_pedido, metodos_pago, pedidos, detalles_pedido, pagosExtras
carrito_compra, newsletter_suscriptoresCore catalog tables
The six tables below form the heart of the product catalog. They are the ones queried by every public and admin API endpoint.categorias
talles
orden column controls the display order of sizes in the admin panel and the catalog view — sizes are always sorted by orden ASC.
colores
hex column stores the CSS hex color code (e.g. #4A5D23) so the storefront can render color swatches without additional lookups.
productos
destacado flag marks a product for display on the store’s featured section. The activo flag implements soft delete — deactivating a product hides it from the public API without removing any historical order data.
producto_imagenes
orden column determines which image is the principal one (lowest orden value) and the display sequence in gallery views. Up to 6 images per product are supported by the admin panel.
variantes
UNIQUE constraint prevents duplicate combinations and is also used by the model layer’s upsert logic when updating variants (ON CONFLICT (producto_id, talle_id, color_id) DO UPDATE SET ...).
vista_catalogo_productos
The viewvista_catalogo_productos is the single read surface used by both the public storefront API and the admin panel. Rather than joining tables in every query, the view pre-aggregates all product-related data into one denormalized row per product.
| Column | Type | Description |
|---|---|---|
imagen_principal | text | URL of the first image by orden |
stock_total | integer | Sum of all variant stock values |
stock_por_talle | json array | [{ talle, cantidad }] sorted by size order |
colores_hex | json array | Distinct hex codes of all colors with variants |
imagenes | json array | All images as [{ url, orden }] |
talle_ids | json array | Distinct talle_id values used in variants |
color_ids | json array | Distinct color_id values used in variants |
variantes | json array | Full variant list as [{ talle_id, color_id, stock, activo }] |
stock_total, stock_por_talle, talle_ids, color_ids, variantes, activo) before sending the response to the storefront, replacing the numeric stock with a human-readable availability string ("Disponible", "Últimas unidades", or "Agotado").
Key constraints
The schema enforces referential integrity through foreign keys with carefully chosen delete behaviors.| Foreign key | References | On delete |
|---|---|---|
productos.categoria_id | categorias(id) | SET NULL — products are preserved if a category is deleted |
producto_imagenes.producto_id | productos(id) | CASCADE — images are deleted with the product |
variantes.producto_id | productos(id) | CASCADE — variants are deleted with the product |
variantes.talle_id | talles(id) | RESTRICT — cannot delete a size that has variants |
variantes.color_id | colores(id) | RESTRICT — cannot delete a color that has variants |
detalles_pedido.variante_id | variantes(id) | RESTRICT — blocks physical deletion of products with order history |
RESTRICT on detalles_pedido.variante_id is the reason the controller returns HTTP 409 with a recommendation to deactivate instead of delete when a product has existing sales records.
Seed data
Runninginicializar/balsamoa.sql on a fresh database populates the following initial records:
- 2 categories —
Hoodie(buzos con y sin capucha) andRemera(remeras de algodón premium) - 5 sizes —
S,M,L,XL,XXLwithordenvalues 1–5 - 8 colors — Blanco
#F5F5F5, Negro#1A1A1A, Verde#4A5D23, Beige#D5C7A8, Azul#1A365D, Gris Claro#D3D3D3, Gris Oscuro#4A4A4A, Marrón#5C4033 - 10 products — 7 hoodies and 3 remeras with prices ranging from 55,000, 3 marked as
destacado - Variants — 21 variant rows covering various size/color combinations with realistic stock scenarios (sold-out, low-stock, and fully stocked)
setval() on all sequences to advance them past the manually assigned IDs, preventing primary key conflicts when the application creates new records through the API.