- Updated date from 2026-01-10 to 2026-01-20 - Updated version from 2.2.1 to 2.2.2 - Updated SIMCO version reference from v3.8.0 to v4.0.0 - Synced with FRONTEND and BACKEND inventories - Added Sprint 8 sync note Resolves: TASK-2026-01-20-003 audit P1 gap Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
927 lines
26 KiB
YAML
927 lines
26 KiB
YAML
# DATABASE INVENTORY - MiChangarrito
|
|
# Version: 2.2.2
|
|
# Ultima actualizacion: 2026-01-20
|
|
# Sistema: SIMCO v4.0.0 + CAPVED
|
|
# Actualizado: Sprint 8 - Sync con FRONTEND/BACKEND inventarios
|
|
|
|
metadata:
|
|
proyecto: "michangarrito"
|
|
componente: "database"
|
|
db_name: "michangarrito_dev"
|
|
version_pg: "16+"
|
|
estado: "100% DDL completado"
|
|
actualizado: "2026-01-20"
|
|
actualizado_por: "Agente Auditor"
|
|
|
|
# ============================================================================
|
|
# RESUMEN
|
|
# ============================================================================
|
|
|
|
resumen:
|
|
total_schemas: 11
|
|
total_tablas: 49
|
|
total_archivos_ddl: 18
|
|
total_extensiones: 4
|
|
total_funciones: 16
|
|
total_triggers: 23
|
|
total_enums: 6
|
|
rls_habilitado: true
|
|
multi_tenant: true
|
|
tenant_column: "tenant_id"
|
|
|
|
# ============================================================================
|
|
# EXTENSIONES POSTGRESQL
|
|
# ============================================================================
|
|
|
|
extensiones:
|
|
- nombre: "uuid-ossp"
|
|
proposito: "Generacion de UUIDs para PKs"
|
|
archivo: "00-extensions.sql"
|
|
|
|
- nombre: "pgcrypto"
|
|
proposito: "Funciones criptograficas"
|
|
archivo: "00-extensions.sql"
|
|
|
|
- nombre: "unaccent"
|
|
proposito: "Full-text search sin acentos"
|
|
archivo: "00-extensions.sql"
|
|
|
|
- nombre: "pg_trgm"
|
|
proposito: "Indices de texto para busqueda fuzzy"
|
|
archivo: "00-extensions.sql"
|
|
|
|
# ============================================================================
|
|
# ARCHIVOS DDL
|
|
# ============================================================================
|
|
|
|
archivos_ddl:
|
|
- archivo: "00-extensions.sql"
|
|
lineas: 16
|
|
descripcion: "Extensiones PostgreSQL"
|
|
estado: completado
|
|
|
|
- archivo: "01-schemas.sql"
|
|
lineas: 61
|
|
descripcion: "Creacion de 11 schemas con permisos"
|
|
schemas_creados:
|
|
- public
|
|
- auth
|
|
- catalog
|
|
- sales
|
|
- inventory
|
|
- customers
|
|
- orders
|
|
- subscriptions
|
|
- messaging
|
|
- billing
|
|
- marketplace
|
|
estado: completado
|
|
|
|
- archivo: "02-functions.sql"
|
|
lineas: 250
|
|
descripcion: "Funciones utilitarias y triggers"
|
|
funciones:
|
|
- update_updated_at()
|
|
- sales.generate_ticket_number()
|
|
- sales.generate_codi_reference()
|
|
- sales.get_codi_spei_summary()
|
|
- orders.generate_order_number()
|
|
- customers.update_customer_fiado_balance()
|
|
- inventory.update_stock_on_sale()
|
|
- subscriptions.generate_referral_code()
|
|
- subscriptions.get_referral_stats()
|
|
- billing.get_next_invoice_folio()
|
|
- billing.get_invoice_summary()
|
|
- marketplace.update_supplier_rating()
|
|
- marketplace.update_supplier_orders_count()
|
|
- marketplace.find_suppliers_by_zone()
|
|
- marketplace.get_marketplace_stats()
|
|
estado: completado
|
|
|
|
- archivo: "03-public.sql"
|
|
lineas: 101
|
|
descripcion: "Schema public - tenants y configuracion"
|
|
tablas:
|
|
- tenants
|
|
- tenant_configs
|
|
estado: completado
|
|
|
|
- archivo: "04-auth.sql"
|
|
lineas: 85
|
|
descripcion: "Autenticacion y usuarios"
|
|
tablas:
|
|
- users
|
|
- sessions
|
|
- otp_codes
|
|
estado: completado
|
|
|
|
- archivo: "05-catalog.sql"
|
|
lineas: 100
|
|
descripcion: "Catalogo de productos"
|
|
tablas:
|
|
- categories
|
|
- products
|
|
- product_templates
|
|
estado: completado
|
|
|
|
- archivo: "06-sales.sql"
|
|
lineas: 220
|
|
descripcion: "Punto de venta con CoDi/SPEI"
|
|
tablas:
|
|
- sales
|
|
- sale_items
|
|
- payments
|
|
- daily_closures
|
|
- virtual_accounts
|
|
- codi_transactions
|
|
- spei_transactions
|
|
- payment_config
|
|
estado: completado
|
|
|
|
- archivo: "07-inventory.sql"
|
|
lineas: 58
|
|
descripcion: "Control de inventario"
|
|
tablas:
|
|
- inventory_movements
|
|
- stock_alerts
|
|
estado: completado
|
|
|
|
- archivo: "08-customers.sql"
|
|
lineas: 107
|
|
descripcion: "Clientes y fiados"
|
|
tablas:
|
|
- customers
|
|
- fiados
|
|
- fiado_payments
|
|
estado: completado
|
|
|
|
- archivo: "09-orders.sql"
|
|
lineas: 73
|
|
descripcion: "Pedidos"
|
|
tablas:
|
|
- orders
|
|
- order_items
|
|
estado: completado
|
|
|
|
- archivo: "10-subscriptions.sql"
|
|
lineas: 200
|
|
descripcion: "Planes, suscripciones y referidos"
|
|
tablas:
|
|
- plans
|
|
- subscriptions
|
|
- token_packages
|
|
- token_usage
|
|
- tenant_token_balance
|
|
- referral_codes
|
|
- referrals
|
|
- referral_rewards
|
|
estado: completado
|
|
|
|
- archivo: "11-messaging.sql"
|
|
lineas: 89
|
|
descripcion: "Mensajeria WhatsApp"
|
|
tablas:
|
|
- conversations
|
|
- messages
|
|
- notifications
|
|
estado: completado
|
|
|
|
- archivo: "12-integrations.sql"
|
|
lineas: 146
|
|
descripcion: "Integraciones por tenant"
|
|
enums:
|
|
- integration_type
|
|
- integration_provider
|
|
tablas:
|
|
- tenant_integration_credentials
|
|
- tenant_whatsapp_numbers
|
|
estado: completado
|
|
|
|
- archivo: "13-referrals.sql"
|
|
lineas: 143
|
|
descripcion: "Sistema de referidos y recompensas"
|
|
tablas:
|
|
- referral_codes
|
|
- referrals
|
|
- referral_rewards
|
|
estado: completado
|
|
|
|
- archivo: "14-codi-spei.sql"
|
|
lineas: 168
|
|
descripcion: "Pagos CoDi/SPEI y cuentas virtuales"
|
|
tablas:
|
|
- virtual_accounts
|
|
- codi_transactions
|
|
- spei_transactions
|
|
- payment_config
|
|
estado: completado
|
|
|
|
- archivo: "15-invoices.sql"
|
|
lineas: 245
|
|
descripcion: "Facturacion electronica CFDI 4.0"
|
|
tablas:
|
|
- tax_configs
|
|
- invoices
|
|
- invoice_items
|
|
- invoice_item_taxes
|
|
- invoice_history
|
|
estado: completado
|
|
|
|
- archivo: "16-marketplace.sql"
|
|
lineas: 390
|
|
descripcion: "Marketplace B2B de proveedores"
|
|
tablas:
|
|
- suppliers
|
|
- supplier_products
|
|
- supplier_orders
|
|
- supplier_order_items
|
|
- supplier_reviews
|
|
- supplier_favorites
|
|
estado: completado
|
|
|
|
- archivo: "templates.sql"
|
|
lineas: 250
|
|
descripcion: "Templates de productos por proveedor y giro (MCH-007)"
|
|
epica: MCH-007
|
|
enums:
|
|
- template_provider
|
|
- template_giro
|
|
tablas:
|
|
- product_templates (extendida)
|
|
- template_imports
|
|
seeds_incluidos: 85
|
|
proveedores:
|
|
- sabritas (15 productos)
|
|
- coca-cola (15 productos)
|
|
- bimbo (10 productos)
|
|
- marinela (10 productos)
|
|
- gamesa (10 productos)
|
|
- pepsi (10 productos)
|
|
- nestle (10 productos)
|
|
- generic/papeleria (15 productos)
|
|
estado: completado
|
|
|
|
# ============================================================================
|
|
# SCHEMAS DETALLADOS
|
|
# ============================================================================
|
|
|
|
schemas:
|
|
public:
|
|
descripcion: "Datos globales y tenants"
|
|
tablas:
|
|
- nombre: tenants
|
|
columnas:
|
|
- id (UUID PK)
|
|
- name, slug (VARCHAR UNIQUE)
|
|
- business_type, phone, email
|
|
- address, city, state, zip_code
|
|
- timezone (default America/Mexico_City)
|
|
- currency (default MXN)
|
|
- tax_rate (default 16.00)
|
|
- whatsapp_number, whatsapp_verified
|
|
- current_plan_id (FK plans)
|
|
- subscription_status, status
|
|
- onboarding_completed
|
|
- created_at, updated_at
|
|
rls: false
|
|
descripcion: "Organizaciones/negocios"
|
|
|
|
- nombre: tenant_configs
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id (UUID FK UNIQUE)
|
|
- opening_hour, closing_hour
|
|
- working_days (INTEGER[])
|
|
- ticket_header, ticket_footer
|
|
- fiados_enabled, default_fiado_limit
|
|
- delivery_enabled, delivery_fee
|
|
- payment_cash, payment_card, payment_codi
|
|
- created_at, updated_at
|
|
rls: true
|
|
descripcion: "Configuraciones por tenant"
|
|
|
|
- nombre: tenant_integration_credentials
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id (UUID FK)
|
|
- integration_type (ENUM)
|
|
- provider (ENUM)
|
|
- credentials (JSONB)
|
|
- config (JSONB)
|
|
- is_active, is_verified
|
|
- created_at, updated_at
|
|
rls: true
|
|
descripcion: "Credenciales de integraciones"
|
|
|
|
- nombre: tenant_whatsapp_numbers
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id (UUID FK)
|
|
- phone_number_id (VARCHAR UNIQUE)
|
|
- phone_number, display_name
|
|
- is_platform_number, is_active
|
|
- created_at
|
|
rls: true
|
|
descripcion: "Mapeo de numeros WhatsApp"
|
|
|
|
auth:
|
|
descripcion: "Autenticacion y sesiones"
|
|
tablas:
|
|
- nombre: users
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id (UUID FK)
|
|
- phone, email, name
|
|
- pin_hash (bcrypt)
|
|
- biometric_enabled, biometric_key
|
|
- role (owner, employee, viewer)
|
|
- permissions (JSONB)
|
|
- status, failed_attempts, locked_until
|
|
- last_login_at, created_at, updated_at
|
|
rls: true
|
|
descripcion: "Usuarios del sistema"
|
|
|
|
- nombre: sessions
|
|
columnas:
|
|
- id (UUID PK)
|
|
- user_id (UUID FK)
|
|
- token_hash, refresh_token_hash
|
|
- device_type, device_info (JSONB)
|
|
- ip_address
|
|
- expires_at, refresh_expires_at
|
|
- created_at, last_activity_at
|
|
rls: true
|
|
descripcion: "Sesiones activas"
|
|
|
|
- nombre: otp_codes
|
|
columnas:
|
|
- id (UUID PK)
|
|
- phone
|
|
- code (6 digitos)
|
|
- purpose (login, verify_phone, reset_pin)
|
|
- attempts, max_attempts
|
|
- expires_at, used_at
|
|
- created_at
|
|
rls: false
|
|
descripcion: "Codigos OTP"
|
|
|
|
catalog:
|
|
descripcion: "Catalogo de productos"
|
|
tablas:
|
|
- nombre: categories
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id (UUID FK)
|
|
- name, description
|
|
- icon, color
|
|
- sort_order, status
|
|
- created_at, updated_at
|
|
rls: true
|
|
descripcion: "Categorias de productos"
|
|
|
|
- nombre: products
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id (UUID FK)
|
|
- category_id (UUID FK nullable)
|
|
- name, description, sku, barcode
|
|
- price, cost_price, compare_price
|
|
- track_inventory, stock_quantity
|
|
- low_stock_threshold, unit
|
|
- image_url, status, is_featured
|
|
- created_at, updated_at
|
|
rls: true
|
|
descripcion: "Productos"
|
|
|
|
- nombre: product_templates
|
|
columnas:
|
|
- id (UUID PK)
|
|
- provider_name (Bimbo, Coca-Cola, etc)
|
|
- name, description, barcode
|
|
- suggested_price, category_suggestion
|
|
- unit, image_url
|
|
- business_types (TEXT[])
|
|
- popularity
|
|
- created_at, updated_at
|
|
rls: false
|
|
descripcion: "Templates de productos predefinidos"
|
|
|
|
sales:
|
|
descripcion: "Punto de venta"
|
|
tablas:
|
|
- nombre: sales
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id (UUID FK)
|
|
- ticket_number (UNIQUE)
|
|
- subtotal, discount_amount, tax_amount, total
|
|
- payment_method, payment_status
|
|
- cash_received, change_amount
|
|
- customer_id (FK nullable)
|
|
- is_fiado, fiado_id (FK nullable)
|
|
- created_by (UUID FK)
|
|
- status, notes
|
|
- created_at, updated_at
|
|
rls: true
|
|
descripcion: "Ventas registradas"
|
|
|
|
- nombre: sale_items
|
|
columnas:
|
|
- id (UUID PK)
|
|
- sale_id (UUID FK CASCADE)
|
|
- product_id (UUID FK nullable)
|
|
- product_name, product_sku
|
|
- quantity, unit_price
|
|
- discount_amount, subtotal
|
|
- created_at
|
|
rls: true
|
|
descripcion: "Detalle de venta"
|
|
|
|
- nombre: payments
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id (UUID FK)
|
|
- sale_id, fiado_id, subscription_id (FKs nullable)
|
|
- method, provider
|
|
- amount, fee_amount, net_amount
|
|
- external_id, external_status
|
|
- status, metadata (JSONB)
|
|
- created_at, updated_at
|
|
rls: true
|
|
descripcion: "Pagos registrados"
|
|
|
|
- nombre: daily_closures
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id (UUID FK)
|
|
- closure_date (UNIQUE per tenant)
|
|
- opened_at, closed_at
|
|
- expected_cash, actual_cash
|
|
- cash_difference
|
|
- total_sales, total_cancelled, total_fiados
|
|
- closed_by (UUID FK)
|
|
- status, notes
|
|
- created_at, updated_at
|
|
rls: true
|
|
descripcion: "Cortes de caja"
|
|
|
|
inventory:
|
|
descripcion: "Control de inventario"
|
|
tablas:
|
|
- nombre: inventory_movements
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id, product_id (UUIDs FK)
|
|
- movement_type (purchase, sale, adjustment, loss, return)
|
|
- quantity (positivo o negativo)
|
|
- previous_stock, new_stock
|
|
- unit_cost, total_cost
|
|
- reference_type, reference_id
|
|
- notes, created_by
|
|
- created_at
|
|
rls: true
|
|
descripcion: "Movimientos de stock"
|
|
|
|
- nombre: stock_alerts
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id, product_id (UUIDs FK)
|
|
- current_stock, threshold
|
|
- status (active, resolved, ignored)
|
|
- notified_at, resolved_at
|
|
- created_at, updated_at
|
|
rls: true
|
|
descripcion: "Alertas de stock bajo"
|
|
|
|
customers:
|
|
descripcion: "Clientes y credito"
|
|
tablas:
|
|
- nombre: customers
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id (UUID FK)
|
|
- name, phone, email
|
|
- address, address_reference
|
|
- latitude, longitude
|
|
- fiado_enabled, fiado_limit
|
|
- current_fiado_balance
|
|
- total_purchases, purchase_count
|
|
- last_purchase_at
|
|
- whatsapp_opt_in, notes, status
|
|
- created_at, updated_at
|
|
rls: true
|
|
descripcion: "Clientes"
|
|
|
|
- nombre: fiados
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id, customer_id, sale_id (UUIDs FK)
|
|
- original_amount, paid_amount, remaining_amount
|
|
- due_date
|
|
- status (pending, partial, paid, overdue, cancelled)
|
|
- description
|
|
- last_reminder_at, reminder_count
|
|
- created_at, updated_at
|
|
rls: true
|
|
descripcion: "Cuentas de credito"
|
|
|
|
- nombre: fiado_payments
|
|
columnas:
|
|
- id (UUID PK)
|
|
- fiado_id (UUID FK)
|
|
- amount
|
|
- payment_method
|
|
- notes
|
|
- created_by (UUID FK)
|
|
- created_at
|
|
rls: true
|
|
descripcion: "Pagos de fiados"
|
|
|
|
orders:
|
|
descripcion: "Pedidos"
|
|
tablas:
|
|
- nombre: orders
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id, customer_id (UUIDs FK)
|
|
- order_number (UNIQUE)
|
|
- channel (whatsapp, app, web)
|
|
- subtotal, delivery_fee, discount_amount, total
|
|
- order_type (pickup, delivery)
|
|
- delivery_address, delivery_notes
|
|
- estimated_delivery_at
|
|
- status (pending, confirmed, preparing, ready, delivered, completed, cancelled)
|
|
- payment_status, payment_method
|
|
- timestamps por estado
|
|
- customer_notes, internal_notes
|
|
- created_at, updated_at
|
|
rls: true
|
|
descripcion: "Pedidos"
|
|
|
|
- nombre: order_items
|
|
columnas:
|
|
- id (UUID PK)
|
|
- order_id, product_id (UUIDs FK)
|
|
- product_name
|
|
- quantity, unit_price, subtotal
|
|
- notes
|
|
- created_at
|
|
rls: true
|
|
descripcion: "Detalle de pedido"
|
|
|
|
subscriptions:
|
|
descripcion: "Planes y tokens IA"
|
|
tablas:
|
|
- nombre: plans
|
|
columnas:
|
|
- id (UUID PK)
|
|
- name, code (UNIQUE)
|
|
- description
|
|
- price_monthly, price_yearly
|
|
- currency (default MXN)
|
|
- included_tokens
|
|
- features (JSONB)
|
|
- max_products, max_users
|
|
- whatsapp_own_number
|
|
- stripe_price_id_monthly, stripe_price_id_yearly
|
|
- status, created_at, updated_at
|
|
rls: false
|
|
descripcion: "Planes disponibles"
|
|
|
|
- nombre: subscriptions
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id, plan_id (UUIDs FK)
|
|
- billing_cycle (monthly, yearly)
|
|
- current_period_start, current_period_end
|
|
- status (trialing, active, past_due, cancelled)
|
|
- cancel_at_period_end
|
|
- payment_method
|
|
- stripe_subscription_id, stripe_customer_id
|
|
- trial_ends_at
|
|
- created_at, updated_at
|
|
rls: true
|
|
descripcion: "Suscripciones activas"
|
|
|
|
- nombre: token_packages
|
|
columnas:
|
|
- id (UUID PK)
|
|
- name, tokens, price
|
|
- currency, bonus_tokens
|
|
- stripe_price_id
|
|
- status, created_at
|
|
rls: false
|
|
descripcion: "Paquetes de tokens"
|
|
|
|
- nombre: token_usage
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id (UUID FK)
|
|
- tokens_used
|
|
- action (chat, report, ocr, transcription)
|
|
- description, model
|
|
- input_tokens, output_tokens
|
|
- reference_type, reference_id
|
|
- created_at
|
|
rls: true
|
|
descripcion: "Consumo de tokens"
|
|
|
|
- nombre: tenant_token_balance
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id (UUID FK UNIQUE)
|
|
- available_tokens, used_tokens
|
|
- last_reset_at
|
|
- updated_at
|
|
rls: true
|
|
descripcion: "Balance de tokens"
|
|
|
|
messaging:
|
|
descripcion: "WhatsApp y notificaciones"
|
|
tablas:
|
|
- nombre: conversations
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id (UUID FK nullable)
|
|
- phone_number, contact_name
|
|
- conversation_type (owner, customer, support, onboarding)
|
|
- status (active, archived, blocked)
|
|
- last_message_at, last_message_preview
|
|
- unread_count
|
|
- wa_conversation_id
|
|
- created_at, updated_at
|
|
rls: true
|
|
descripcion: "Conversaciones WhatsApp"
|
|
|
|
- nombre: messages
|
|
columnas:
|
|
- id (UUID PK)
|
|
- conversation_id (UUID FK)
|
|
- direction (inbound, outbound)
|
|
- message_type (text, image, audio, video, document, location)
|
|
- content, media_url, media_mime_type
|
|
- processed_by_llm, llm_response_id, tokens_used
|
|
- wa_message_id, wa_status, wa_timestamp
|
|
- error_code, error_message
|
|
- created_at
|
|
rls: true
|
|
descripcion: "Mensajes"
|
|
|
|
- nombre: notifications
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id, user_id (UUIDs FK)
|
|
- notification_type (low_stock, new_order, fiado_reminder, daily_summary)
|
|
- channels (TEXT[])
|
|
- title, body
|
|
- data (JSONB)
|
|
- push_sent, push_sent_at
|
|
- whatsapp_sent, whatsapp_sent_at
|
|
- read_at
|
|
- created_at
|
|
rls: true
|
|
descripcion: "Notificaciones push y WhatsApp"
|
|
|
|
billing:
|
|
descripcion: "Facturacion electronica CFDI 4.0"
|
|
tablas:
|
|
- nombre: tax_configs
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id (UUID FK UNIQUE)
|
|
- rfc, razon_social, regimen_fiscal
|
|
- cfdi_enabled
|
|
- pac_provider, pac_api_key (encrypted)
|
|
- certificate_serial, certificate_password (encrypted)
|
|
- default_uso_cfdi
|
|
- created_at, updated_at
|
|
rls: true
|
|
descripcion: "Configuracion fiscal por tenant"
|
|
|
|
- nombre: invoices
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id (UUID FK)
|
|
- sale_id (UUID FK nullable)
|
|
- customer_rfc, customer_name, customer_email
|
|
- customer_zip, customer_regimen_fiscal
|
|
- serie, folio
|
|
- subtotal, total_tax, total_amount
|
|
- forma_pago, metodo_pago, uso_cfdi
|
|
- uuid_fiscal, sello_sat, sello_cfd
|
|
- fecha_timbrado
|
|
- status (pending, stamped, sent, cancelled)
|
|
- xml_content, pdf_url
|
|
- created_at, updated_at
|
|
rls: true
|
|
descripcion: "Facturas CFDI 4.0"
|
|
|
|
- nombre: invoice_items
|
|
columnas:
|
|
- id (UUID PK)
|
|
- invoice_id (UUID FK CASCADE)
|
|
- clave_prod_serv, clave_unidad
|
|
- description, quantity
|
|
- unit_price, subtotal
|
|
- created_at
|
|
rls: true
|
|
descripcion: "Conceptos de factura"
|
|
|
|
- nombre: invoice_item_taxes
|
|
columnas:
|
|
- id (UUID PK)
|
|
- invoice_item_id (UUID FK CASCADE)
|
|
- tax_type (IVA, ISR, IEPS)
|
|
- rate, amount
|
|
- is_retention
|
|
- created_at
|
|
rls: true
|
|
descripcion: "Impuestos por concepto"
|
|
|
|
- nombre: invoice_history
|
|
columnas:
|
|
- id (UUID PK)
|
|
- invoice_id (UUID FK)
|
|
- action (created, stamped, sent, cancelled)
|
|
- details (JSONB)
|
|
- created_by (UUID FK)
|
|
- created_at
|
|
rls: true
|
|
descripcion: "Historial de cambios de facturas"
|
|
|
|
marketplace:
|
|
descripcion: "Marketplace B2B de proveedores"
|
|
tablas:
|
|
- nombre: suppliers
|
|
columnas:
|
|
- id (UUID PK)
|
|
- business_name, contact_name
|
|
- phone, email, rfc
|
|
- category
|
|
- address, city, state
|
|
- delivery_zones (TEXT[])
|
|
- minimum_order, delivery_days
|
|
- rating, reviews_count, orders_count
|
|
- is_active, is_verified
|
|
- logo_url
|
|
- created_at, updated_at
|
|
rls: false
|
|
descripcion: "Proveedores verificados"
|
|
|
|
- nombre: supplier_products
|
|
columnas:
|
|
- id (UUID PK)
|
|
- supplier_id (UUID FK)
|
|
- name, description, sku
|
|
- price, compare_price
|
|
- unit, minimum_quantity
|
|
- category
|
|
- image_url, is_active
|
|
- created_at, updated_at
|
|
rls: false
|
|
descripcion: "Productos de proveedores"
|
|
|
|
- nombre: supplier_orders
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id (UUID FK)
|
|
- supplier_id (UUID FK)
|
|
- order_number (UNIQUE)
|
|
- subtotal, shipping_cost, total_amount
|
|
- status (pending, confirmed, shipped, delivered, cancelled)
|
|
- estimated_delivery, actual_delivery
|
|
- shipping_address, notes
|
|
- created_at, updated_at
|
|
rls: true
|
|
descripcion: "Ordenes a proveedores"
|
|
|
|
- nombre: supplier_order_items
|
|
columnas:
|
|
- id (UUID PK)
|
|
- order_id (UUID FK CASCADE)
|
|
- product_id (UUID FK)
|
|
- product_name
|
|
- quantity, unit_price, subtotal
|
|
- created_at
|
|
rls: true
|
|
descripcion: "Items de orden a proveedor"
|
|
|
|
- nombre: supplier_reviews
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id (UUID FK)
|
|
- supplier_id (UUID FK)
|
|
- order_id (UUID FK)
|
|
- rating (1-5)
|
|
- comment
|
|
- created_at
|
|
rls: true
|
|
descripcion: "Reseñas de proveedores"
|
|
|
|
- nombre: supplier_favorites
|
|
columnas:
|
|
- id (UUID PK)
|
|
- tenant_id (UUID FK)
|
|
- supplier_id (UUID FK)
|
|
- created_at
|
|
rls: true
|
|
descripcion: "Proveedores favoritos"
|
|
|
|
# ============================================================================
|
|
# ENUMS
|
|
# ============================================================================
|
|
|
|
enums:
|
|
- nombre: integration_type
|
|
valores:
|
|
- whatsapp
|
|
- llm
|
|
- stripe
|
|
- mercadopago
|
|
- clip
|
|
archivo: "12-integrations.sql"
|
|
|
|
- nombre: integration_provider
|
|
valores:
|
|
- meta
|
|
- openai
|
|
- openrouter
|
|
- anthropic
|
|
- ollama
|
|
- azure_openai
|
|
- stripe
|
|
- mercadopago
|
|
- clip
|
|
archivo: "12-integrations.sql"
|
|
|
|
# ============================================================================
|
|
# SEEDS
|
|
# ============================================================================
|
|
|
|
seeds:
|
|
- archivo: "01-plans.sql"
|
|
lineas: 17
|
|
descripcion: "Planes de suscripcion y paquetes de tokens"
|
|
datos:
|
|
- "Plan Changarrito: $99/mes, 500 tokens, 100 productos max"
|
|
- "Plan Tiendita: $199/mes, 2000 tokens, sin limite"
|
|
- "Paquetes: 1000, 3000, 8000, 20000 tokens"
|
|
|
|
- archivo: "02-templates.sql"
|
|
lineas: 103
|
|
descripcion: "Templates de productos por proveedor"
|
|
proveedores:
|
|
- Bimbo (10 productos)
|
|
- Coca-Cola (15 productos)
|
|
- Sabritas (10 productos)
|
|
- Pepsi (7 productos)
|
|
- Ricolino (7 productos)
|
|
- Lacteos (6 productos)
|
|
- Basicos (9 productos)
|
|
- Comida (11 productos)
|
|
total_productos: 75
|
|
|
|
# ============================================================================
|
|
# SCRIPTS
|
|
# ============================================================================
|
|
|
|
scripts:
|
|
creacion: "database/scripts/create-database.sh"
|
|
recreacion: "database/scripts/recreate-database.sh"
|
|
validacion: "database/scripts/validate-integrations.sh"
|
|
|
|
# ============================================================================
|
|
# RUTAS
|
|
# ============================================================================
|
|
|
|
rutas:
|
|
schemas_base: "database/schemas/"
|
|
seeds_base: "database/seeds/"
|
|
scripts_base: "database/scripts/"
|
|
init_base: "database/init/"
|
|
|
|
# ============================================================================
|
|
# COMANDOS
|
|
# ============================================================================
|
|
|
|
comandos:
|
|
crear_db: "./database/scripts/create-database.sh"
|
|
recrear_db: "./database/scripts/recreate-database.sh"
|
|
validar: "./database/scripts/validate-integrations.sh"
|
|
conectar: "psql -d michangarrito_dev"
|
|
|
|
# ============================================================================
|
|
# NOTAS
|
|
# ============================================================================
|
|
|
|
notas:
|
|
- "RLS habilitado en todas las tablas excepto tenants, plans, token_packages, otp_codes, product_templates, suppliers, supplier_products"
|
|
- "Multi-tenant por columna tenant_id en todas las tablas"
|
|
- "Trigger updated_at automatico en tablas con updated_at"
|
|
- "4 extensiones PostgreSQL para UUIDs, criptografia y busqueda de texto"
|
|
- "4 ENUMs para tipos de integracion, proveedores, invoice_status, supplier_order_status"
|
|
- "75 productos predefinidos en templates para onboarding rapido"
|
|
- "11 schemas: public, auth, catalog, sales, inventory, customers, orders, subscriptions, messaging, billing, marketplace"
|
|
- "47 tablas totales con soporte completo de CFDI 4.0 y marketplace B2B"
|
|
- "Sprint 8: Sincronizado con FRONTEND_INVENTORY y BACKEND_INVENTORY (2026-01-20)"
|