Data Model
Quality Hub GINEZ uses PostgreSQL (via Supabase) as its primary database, with supplementary data from Google Sheets for the product catalog.Database Schema
Primary Table: bitacora_produccion
Stores production batch records with quality control measurements.
Field Descriptions
| Field | Type | Description |
|---|---|---|
id | bigint | Auto-incrementing primary key |
created_at | timestamptz | Automatic timestamp of record creation |
lote_producto | text | Generated batch number (format: YYYYMMDD-SUC-PROD-###) |
codigo_producto | text | Product code (e.g., LIMLIM, TRALIM) |
sucursal | text | Branch name where product was manufactured |
familia_producto | text | Product family (e.g., “Limpiador liquido multiusos”) |
categoria_producto | text | Product category |
fecha_fabricacion | date | Manufacturing date |
tamano_lote | numeric | Batch size in liters or kilograms |
ph | numeric | pH measurement (0-14 scale) |
solidos_medicion_1 | numeric | First % solids measurement (0-55%) |
solidos_medicion_2 | numeric | Second % solids measurement (0-55%) |
apariencia | text | Appearance (CRISTALINO, OPACO, APERLADO) |
color | text | Color conformity (CONFORME, NO CONFORME) |
aroma | text | Aroma conformity (CONFORME, NO CONFORME) |
nombre_preparador | text | Name of the person who prepared the batch |
user_id | uuid | Foreign key to auth.users, identifies record creator |
Supporting Table: profiles
Extends Supabase Auth users with application-specific profile data.
Field Descriptions
| Field | Type | Description |
|---|---|---|
id | uuid | User ID (references auth.users) |
email | text | User email address |
nombre | text | Full name |
area | text | Department/area |
puesto | text | Job position |
is_admin | boolean | Admin flag for elevated permissions |
created_at | timestamptz | Profile creation timestamp |
Data Types & Validation
Product Standards
Product standards are defined in code (lib/production-constants.ts) for real-time validation:
pH Standards
Appearance Standards
Parameter Applicability
Defines which quality parameters apply to each product:Branch (Sucursal) Configuration
Branches are defined as constants with acronym mappings:Product Categories
Hierarchical product organization:Product Groups
High-level grouping for reporting:Computed Fields
Some data is computed on the client side:Average Solids
Conformity Status
Calculated based on control chart logic (see Analysis Utils).Conformity Analysis
The conformity analysis logic is implemented inlib/analysis-utils.ts:
Control Chart Logic
Enriched Record Type
External Data: Google Sheets
The product catalog is synchronized from Google Sheets via CSV export:Raw Materials
- URL configured in
SHEET_MP_CSV_URL - Fields: code, name, type, supplier, etc.
Finished Products
- URL configured in
SHEET_PT_CSV_URL - Fields: code, name, family, category, documentation links
Data Flow
Create Production Record
- User fills form with batch information
- Client validates with Zod schema (
lib/validations.ts) - Conformity analyzed in real-time
- Record submitted to Supabase
- RLS policies verify user permissions
- Record inserted with
user_id - Success response returned
Query Production Records
- Client requests records via Supabase client
- RLS policies filter results:
- Regular users: only their own records
- Admins: all records
- Records returned to client
- Client enriches with conformity analysis
- Data displayed in UI
Indexes
Recommended indexes for performance:Data Integrity
Constraints
user_idmust reference valid user inauth.userslote_productoshould be unique (enforced by generation logic)fecha_fabricacioncannot be in the future (client validation)tamano_lotemust be positivephrange 0-14 (client validation)solidos_medicion_*range 0-55% (client validation)
Audit Trail
created_attimestamp provides creation audituser_idlinks record to creator- Records are never deleted, only soft-deleted in admin operations
- User deletion preserves historical records
