Imported from XavierPappalardo/UTN-TUPaD-TP_Base_de_Datos_Semana3_2PRO1 (
TP-Semana3-FoodStore_Gomez_Pappalardo_Ibañez_Arroyo_Reinoso_Sisterna/AGENTS.md). Install upstream withnpx skills add XavierPappalardo/UTN-TUPaD-TP_Base_de_Datos_Semana3_2PRO1 --skill TP-Semana3-FoodStore_Gomez_Pappalardo_Ibañez_Arroyo_Reinoso_Sisterna. Copyright stays with the author.
AGENTS.md
Project
UTN TUPaD TPI academic project: Food Store — a pure PostgreSQL 16+ database schema for a fictional food store (categories, products, users, orders, order details). There is no application code and no build/test/lint/CI system. Everything (SQL code, identifiers, comments) is in Spanish.
Authoritative spec
Read .kiro/steering/*.md first — it is the canonical design doc and matches the committed SQL:
01-schema.md/03-objetos.md— tables, ENUMs, views, functions, triggers, procedure02-convenciones.md— naming & style conventions04-soft-delete-transacciones-stock.md— soft-delete, transactions, stock/concurrency05-orden-ejecucion.md— script execution order & dependencies
Execution order (mandatory)
Scripts depend on each other; run in SQL/ in this order:
1. schema.sql -> ENUMs, tables, indexes
2. objects.sql -> views, functions, triggers, procedure
3. data.sql -> seed data (single transaction; activates triggers)
4. queries.sql -> example DML (may INSERT/UPDATE data)
5. transacciones.sql -> ACID/concurrency tests
queries.sqlandtransacciones.sqlrequire the first three already run.- Concurrency scenarios in
transacciones.sqlneed two simultaneous DB sessions (SECTION A / SECTION B) — cannot run in one sequential session. data.sqlhardcodes IDs (e.g.WHERE id_pedido = 5) that only match a freshly-seeded clean DB.
Conventions (differ from SQL defaults; follow the spec)
- Naming prefixes:
v_views,fn_functions,sp_procedures,trg_triggers,idx_indexes;p_params,v_locals.- Exception:
calcular_total_pedido()has nofn_prefix (intentional — public/calculable). - Gotcha:
detalle_pedidoPK isid_detallepedido(no underscore before "pedido").
- Exception:
- ENUM type names lowercase; ENUM values UPPERCASE (
PENDIENTE,CONFIRMADO...). - Filter active rows with
where eliminado = FALSEonly — never<> TRUE,NOT eliminado, orIS FALSE. Every table haseliminado BOOLEAN(soft delete). total_pedidois trigger-computed — never set manually. Two separate AFTER STATEMENT triggers (trg_total_ins,trg_total_upd) exist because PG transition tables can't span multiple events in one trigger.- Order deactivation = two-step transaction:
UPDATE detalle_pedido ... ; UPDATE pedido ...together in oneBEGIN;...COMMIT;. - Use
COALESCE(nuevo_valor, columna_actual)in UPDATEs for partial updates, andRETURNING <pk>in INSERTs to recover generated IDs. - Deactivation/delete of a parent row on
detalle_pedidois blocked byON DELETE RESTRICTonpedido_idFK; the soft-delete path is via triggers.
Known quirks (verified)
objects.sqlcontains stray editor-comment artifacts (-- corregido: id -> id_pedido); code itself is correct.- No
trg_total_deltrigger (soft delete converts DELETEs to UPDATEs, sotrg_total_updstill fires). v_pedidos_resumendoes not filterusuario.eliminado;v_pedido_detalledoes not filterproducto.eliminado— likely intentional to preserve history.- Stock decrement is done in
sp_crear_pedidousingSELECT ... FOR UPDATEfor concurrency control.
Git
.kiro/,Link al Repo.txt, and the TP1 zip are untracked; no.gitignore.
