# ANALISIS MAESTRO - Validacion Integral del Modelado de Base de Datos # Trading Platform - TASK-2026-02-05-ANALISIS-VALIDACION-MODELADO-BD **Fecha:** 2026-02-05 **Perfil:** Especialista en Base de Datos y Modelado de Datos **Modo:** @ANALYSIS (CAPVED: C+A+P sin ejecutar) **Estado:** FASE-1 COMPLETADA --- ## 1. CONTEXTO (C) ### 1.1 Situacion Actual El proyecto trading-platform es una plataforma de trading e inversiones con arquitectura hibrida TypeScript/Python. Cuenta con: - **11 schemas** PostgreSQL 16+ - **100 tablas** DDL definidas (vs 81 documentadas en inventario) - **50+ enums** personalizados - **17+ funciones** stored procedures - **39+ triggers** automaticos - **9 modulos** epicos (OQI-001 a OQI-009) - **Coherencia global actual:** 81.25% ### 1.2 Problema Identificado El modelado de datos presenta discrepancias significativas entre: 1. **DDL real** (100 tablas) vs **inventario documentado** (81 tablas) = 19 tablas sin documentar 2. **Conflictos de enums** duplicados entre schemas (3 conflictos activos) 3. **1 error critico** de FK en price_alerts (referencia incorrecta) 4. **Acoplamiento debil** entre schemas criticos (wallets <-> investment, bots <-> wallets) 5. **Duplicacion funcional** en catalogo de simbolos (trading.symbols vs market_data.tickers) 6. **Documentacion desactualizada** con tareas completadas mezcladas con pendientes ### 1.3 Objetivo Lograr un modelado de datos validado al 100%, coherente con la documentacion, sin conflictos ni duplicidades, preparado para integracion backend, con un plan de ejecucion detallado por fases. --- ## 2. ANALISIS (A) ### 2.1 Inventario de Hallazgos Criticos #### 2.1.1 ERROR CRITICO: FK Incorrecta en price_alerts | Atributo | Valor | |----------|-------| | **Archivo** | `apps/database/ddl/schemas/trading/tables/11-price_alerts.sql` | | **Linea** | 15 | | **Error** | `REFERENCES auth.user_profiles(id)` | | **Correcto** | `REFERENCES auth.users(id)` | | **Impacto** | Tabla NO se puede crear - BLOQUEANTE | | **Prioridad** | P0 - INMEDIATO | #### 2.1.2 Tablas No Documentadas (19 tablas) | # | Schema | Tabla | Archivo DDL | Impacto | |---|--------|-------|-------------|---------| | 1 | education | instructors | 17-instructors.sql | Backend tiene servicio sin tabla doc | | 2 | education | course_tags | 18-course_tags.sql | Funcionalidad de tags no integrada | | 3 | education | course_tag_assignments | 19-course_tag_assignments.sql | M:N tags-cursos sin doc | | 4 | education | review_helpful_votes | 16-review_helpful_votes.sql | Votos de reviews sin doc | | 5 | education | user_activity_log | 13-user_activity_log.sql | Tracking gamificacion sin doc | | 6 | education | user_gamification_profile | 12-user_gamification_profile.sql | Perfil XP sin doc en inventario | | 7 | education | course_reviews | 14-course_reviews.sql | Reviews de cursos sin doc | | 8 | trading | drawing_tools | 12-drawing_tools.sql | Herramientas dibujo chart | | 9 | trading | drawing_templates | 13-drawing_templates.sql | Templates de dibujo | | 10 | financial | refunds | 11-refunds.sql | Reembolsos sin doc | | 11 | financial | currency_exchange_rates | 07-currency_exchange_rates.sql | Tipos de cambio sin doc | | 12 | investment | agent_executions | 10-agent_executions.sql | Ejecuciones agentes sin doc | | 13 | investment | risk_questionnaire | 02-risk_questionnaire.sql | Cuestionario riesgo sin doc inv | | 14 | ml | llm_signals | 11-llm_signals.sql | Senales LLM sin doc | | 15 | ml | prediction_overlays | 12-prediction_overlays.sql | Overlays prediccion sin doc | | 16 | feature_flags | flags | 01-flags.sql | Schema completo sin doc | | 17 | auth | notifications | 11-notifications.sql | Notificaciones sin doc inv | | 18 | auth | user_push_tokens | 12-user_push_tokens.sql | Push tokens sin doc inv | | 19 | portfolio | portfolio_snapshots | 05-portfolio_snapshots.sql | Snapshots sin doc inv | #### 2.1.3 Conflictos de Enums (3 activos) | ID | Enum | Schemas | Estado | Accion | |----|------|---------|--------|--------| | CONF-E1 | `transaction_type` | financial, investment | Migracion pendiente | Renombrar a wallet_transaction_type / investment_transaction_type | | CONF-E2 | `risk_profile` | investment, portfolio | NO marcado para migracion | Consolidar en public.risk_profile | | CONF-E3 | `timeframe` | public, trading, market_data | Parcialmente migrado | Completar migracion, agregar '1M' a market_data | #### 2.1.4 Acoplamiento Debil entre Schemas | ID | Relacion Faltante | Impacto | Prioridad | |----|-------------------|---------|-----------| | WEAK-1 | investment.accounts <-> financial.wallets | Cuentas inversion sin wallet vinculado | P1 | | WEAK-2 | trading.bots <-> financial.wallets | Bots sin tracking de capital en wallet | P1 | | WEAK-3 | portfolio.portfolios <-> investment.accounts | Portafolio sin link a cuentas | P2 | | WEAK-4 | market_data.tickers -> trading.symbols | Catalogo duplicado sin referencia cruzada | P1 | #### 2.1.5 Duplicacion Funcional | ID | Objeto A | Objeto B | Tipo | Resolucion | |----|----------|----------|------|------------| | DUP-1 | trading.symbols (UUID PK) | market_data.tickers (SERIAL PK) | Catalogo simbolos | Consolidar en trading.symbols como master | | DUP-2 | auth.users.role | auth.user_status | Status/Role dual | Mantener separados (correcto) | | DUP-3 | financial.wallet_audit_log | audit.audit_logs | Auditoria | Complementarios, mantener | ### 2.2 Analisis de Completitud por Schema #### Schema: auth (13 tablas DDL / 10 inventario) | Tabla | DDL | Inventario | Backend Entity | Backend Service | Gap | |-------|-----|-----------|----------------|-----------------|-----| | users | OK | OK | OK | OK | - | | user_profiles | OK | OK | OK | OK | - | | oauth_accounts | OK | OK | OK | OK | - | | sessions | OK | OK | OK | OK | - | | email_verifications | OK | OK | OK | OK | - | | phone_verifications | OK | OK | OK | OK | - | | password_reset_tokens | OK | OK | OK | OK | - | | auth_logs | OK | OK | OK | OK | - | | login_attempts | OK | OK | OK | Parcial | Falta rate limit service | | rate_limiting_config | OK | OK | NO | NO | Falta entity + service | | **notifications** | OK | **FALTA** | OK | Parcial | Falta doc inventario | | **user_push_tokens** | OK | **FALTA** | NO | NO | Falta entity + service + doc | **Coherencia auth:** 10/13 documentadas = 77% (deberia ser 100%) #### Schema: trading (13 tablas DDL / 11 inventario) | Tabla | DDL | Inventario | Backend Entity | Backend Service | Gap | |-------|-----|-----------|----------------|-----------------|-----| | symbols | OK | OK | OK | OK | - | | watchlists | OK | OK | OK | OK | - | | watchlist_items | OK | OK | OK | OK | - | | bots | OK | OK | OK | Parcial (60%) | Falta completar bot service | | orders | OK | OK | OK | OK | - | | positions | OK | OK | OK | OK | - | | trades | OK | OK | OK | OK | - | | signals | OK | OK | OK | OK | - | | trading_metrics | OK | OK | OK | Parcial | Falta metrics service | | paper_balances | OK | OK | OK | OK | - | | price_alerts | OK | OK | NO | NO | **FK ERROR + falta entity** | | **drawing_tools** | OK | **FALTA** | NO | NO | Nuevo - falta todo | | **drawing_templates** | OK | **FALTA** | NO | NO | Nuevo - falta todo | **Coherencia trading:** 11/13 documentadas = 85% #### Schema: education (19 tablas DDL / 12 inventario) | Tabla | DDL | Inventario | Backend Entity | Backend Service | Gap | |-------|-----|-----------|----------------|-----------------|-----| | categories | OK | OK | OK | OK | - | | courses | OK | OK | OK | OK | - | | modules | OK | OK | OK | OK | - | | lessons | OK | OK | OK | OK | - | | enrollments | OK | OK | OK | OK | - | | progress | OK | Falta | OK | Parcial | Falta doc | | quizzes | OK | OK | OK | OK | - | | quiz_questions | OK | OK | OK | OK | - | | quiz_attempts | OK | OK | OK | OK | - | | certificates | OK | OK | OK | OK | - | | user_achievements | OK | OK | OK | OK | - | | user_gamification_profile | OK | OK | OK | OK | - | | videos | OK | OK | NO | NO | Falta entity | | **user_activity_log** | OK | **FALTA** | NO | NO | Falta todo | | **course_reviews** | OK | **FALTA** | NO | Parcial | Falta entity | | **review_helpful_votes** | OK | **FALTA** | NO | NO | Falta todo | | **instructors** | OK | **FALTA** | NO | Existe stub | Falta entity real | | **course_tags** | OK | **FALTA** | NO | NO | Falta todo | | **course_tag_assignments** | OK | **FALTA** | NO | NO | Falta todo | **Coherencia education:** 12/19 documentadas = 63% (la peor) #### Schema: financial (11 tablas DDL / 9 inventario) | Tabla | DDL | Inventario | Backend Entity | Backend Service | Gap | |-------|-----|-----------|----------------|-----------------|-----| | wallets | OK | OK | OK | OK | - | | wallet_transactions | OK | OK | OK | OK | - | | subscriptions | OK | OK | OK | OK | - | | invoices | OK | OK | OK | OK | - | | payments | OK | OK | OK | OK | - | | wallet_audit_log | OK | OK | OK | OK | - | | wallet_limits | OK | OK | NO | NO | Falta entity | | customers | OK | OK | OK | OK | - | | payment_methods | OK | OK | OK | OK | - | | **currency_exchange_rates** | OK | **FALTA** | NO | NO | Falta todo | | **refunds** | OK | **FALTA** | NO | NO | Falta todo | **Coherencia financial:** 9/11 documentadas = 82% #### Schema: investment (10 tablas DDL / 8 inventario) | Tabla | DDL | Inventario | Backend Entity | Backend Service | Gap | |-------|-----|-----------|----------------|-----------------|-----| | products | OK | OK | OK | OK | - | | risk_questionnaire | OK | Falta | OK | Parcial | Falta doc inv | | accounts | OK | OK | OK | OK | - | | distributions | OK | OK | OK | OK | - | | transactions | OK | OK | OK | OK | - | | withdrawal_requests | OK | OK | OK | OK | - | | daily_performance | OK | OK | OK | Parcial | Falta performance service | | distribution_history | OK | OK | NO | NO | Nuevo Sprint 3 | | distribution_runs | OK | OK | NO | NO | Nuevo Sprint 3 | | **agent_executions** | OK | **FALTA** | NO | NO | Falta todo | **Coherencia investment:** 8/10 documentadas = 80% #### Schema: ml (12 tablas DDL / 10 inventario) | Tabla | DDL | Inventario | Backend Entity | Backend Service | Gap | |-------|-----|-----------|----------------|-----------------|-----| | models | OK | OK | OK | OK | - | | model_versions | OK | OK | OK | OK | - | | predictions | OK | OK | OK | OK | - | | prediction_outcomes | OK | OK | OK | OK | - | | feature_store | OK | OK | OK | OK | - | | llm_predictions | OK | OK | OK | OK | - | | llm_prediction_outcomes | OK | OK | OK | OK | - | | llm_decisions | OK | OK | OK | OK | - | | risk_events | OK | OK | OK | OK | - | | backtest_runs | OK | OK | OK | OK | - | | **llm_signals** | OK | **FALTA** | NO | NO | Falta todo | | **prediction_overlays** | OK | **FALTA** | NO | NO | Falta todo | **Coherencia ml:** 10/12 documentadas = 83% #### Schema: llm (5 tablas DDL / 4 inventario) | Tabla | DDL | Inventario | Backend Entity | Backend Service | Gap | |-------|-----|-----------|----------------|-----------------|-----| | conversations | OK | OK | OK | OK | - | | messages | OK | OK | OK | OK | - | | user_preferences | OK | Falta | OK | OK | Falta doc inv | | user_memory | OK | OK | OK | OK | - | | embeddings | OK | OK | OK | Parcial | pgvector integration | **Coherencia llm:** 4/5 documentadas = 80% #### Schema: audit (7 tablas DDL / 7 inventario) Todas documentadas. **Coherencia: 100%**. Sin embargo, NO tiene servicios backend. #### Schema: portfolio (5 tablas DDL / 4 inventario) | Tabla | DDL | Inventario | Backend Entity | Backend Service | Gap | |-------|-----|-----------|----------------|-----------------|-----| | portfolios | OK | OK | OK | OK | - | | portfolio_allocations | OK | OK | OK | OK | - | | portfolio_goals | OK | OK | OK | OK | - | | rebalance_history | OK | OK | NO | NO | Falta entity | | **portfolio_snapshots** | OK | **FALTA** | NO | NO | Falta todo | **Coherencia portfolio:** 4/5 documentadas = 80% #### Schema: market_data (4 tablas DDL / 3 inventario) | Tabla | DDL | Inventario | Backend Entity | Backend Service | Gap | |-------|-----|-----------|----------------|-----------------|-----| | tickers | OK | OK | OK | Parcial | Falta completar | | ohlcv_5m | OK | OK | NO | NO | Falta entity | | ohlcv_15m | OK | OK | NO | NO | Falta entity | | staging | OK | Falta | NO | NO | ETL staging | **Coherencia market_data:** 3/4 documentadas = 75% #### Schema: feature_flags (1 tabla DDL / 0 inventario) | Tabla | DDL | Inventario | Backend Entity | Backend Service | Gap | |-------|-----|-----------|----------------|-----------------|-----| | **flags** | OK | **FALTA** | NO | Parcial | Schema completo sin doc | **Coherencia feature_flags:** 0/1 documentadas = 0% (peor caso) ### 2.3 Resumen de Coherencia DDL-Inventario | Schema | DDL | Documentadas | Coherencia | |--------|-----|-------------|------------| | auth | 13 | 10 | 77% | | trading | 13 | 11 | 85% | | education | 19 | 12 | **63%** | | financial | 11 | 9 | 82% | | investment | 10 | 8 | 80% | | ml | 12 | 10 | 83% | | llm | 5 | 4 | 80% | | audit | 7 | 7 | **100%** | | portfolio | 5 | 4 | 80% | | market_data | 4 | 3 | 75% | | feature_flags | 1 | 0 | **0%** | | **TOTAL** | **100** | **78** | **78%** | ### 2.4 Analisis de Documentacion para Purga #### Documentacion Obsoleta / Candidatos a Purga | Ubicacion | Tipo | Razon | Accion | |-----------|------|-------|--------| | orchestration/tareas/_archive/2026-01/ | Tareas archivadas | Estructura creada pero archivos no movidos | Completar archivado | | orchestration/analisis/_archive/2026-01-25/ | Analisis OQI-001 viejos | Superseded por TASK-2026-02-03 | Mantener en archive | | docs/_archive/04-fase-backlog/ | Backlog deprecado | Links rotos a /docs/planning/ | Eliminar | | docs/_archive/00-notas/NOTA-DISCREPANCIA-PUERTOS-2025-12-08.md | Nota resuelta | Resuelto 2026-01-07 | Eliminar | | orchestration/analisis/coherencia/COHERENCE-BASELINE-2026-01-28.md | Baseline viejo | Superseded por version actual | Mover a _archive | | orchestration/tareas/2026-01-25/ | Carpeta fecha antigua | Tareas movidas o completadas | Verificar y archivar | | orchestration/tareas/2026-01-27/ | Carpeta fecha antigua | Tareas movidas o completadas | Verificar y archivar | #### Documentacion Faltante (a integrar) | Tipo | Contenido | Ubicacion Sugerida | |------|-----------|-------------------| | Definicion | feature_flags schema completo | docs/02-definicion-modulos/ (transversal) | | Especificacion | ET para drawing_tools/templates | docs/02-definicion-modulos/OQI-003-trading-charts/ | | Historia Usuario | US para price_alerts | docs/02-definicion-modulos/OQI-003-trading-charts/ | | Requerimiento | RF para refunds | docs/02-definicion-modulos/OQI-005-payments-stripe/ | | Especificacion | ET para course_tags | docs/02-definicion-modulos/OQI-002-education/ | | Historia Usuario | US para instructors management | docs/02-definicion-modulos/OQI-002-education/ | | Requerimiento | RF para agent_executions | docs/02-definicion-modulos/OQI-004-investment-accounts/ | | Especificacion | ET para prediction_overlays | docs/02-definicion-modulos/OQI-006-ml-signals/ | --- ## 3. PLANIFICACION (P) - PLAN MAESTRO POR FASES ### 3.0 Estructura General de Fases ``` FASE-1: Analisis y Planificacion (COMPLETADA - este documento) | v FASE-2: Validacion de Esquemas y Objetos DDL ├── 2.1: Correccion de errores criticos DDL ├── 2.2: Validacion schema-por-schema ├── 2.3: Resolucion de conflictos de enums └── 2.4: Resolucion de duplicaciones funcionales | v FASE-3: Auditoria de Integridad y Coherencia ├── 3.1: Validacion de foreign keys ├── 3.2: Validacion de indices ├── 3.3: Validacion de constraints ├── 3.4: Validacion de funciones y triggers └── 3.5: Validacion de relaciones entre schemas | v FASE-4: Coherencia DDL-Backend ├── 4.1: Mapeo tablas -> entities ├── 4.2: Mapeo entities -> services ├── 4.3: Mapeo services -> controllers ├── 4.4: Identificacion de gaps de implementacion └── 4.5: Plan de entidades faltantes | v FASE-5: Purga y Reorganizacion Documental ├── 5.1: Purgar documentacion obsoleta ├── 5.2: Integrar definiciones faltantes ├── 5.3: Actualizar inventarios └── 5.4: Actualizar documentacion de modulos | v FASE-6: Plan Maestro de Remediacion ├── 6.1: Priorizar acciones por impacto ├── 6.2: Definir orden de ejecucion con dependencias ├── 6.3: Estimar esfuerzo por subtarea └── 6.4: Generar roadmap actualizado ``` --- ### FASE-2: Validacion de Esquemas y Objetos DDL #### SUBTAREA 2.1: Correccion de Errores Criticos DDL **CAPVED:** - **C:** price_alerts tiene FK incorrecta que impide creacion de tabla - **A:** Error en linea 15 de 11-price_alerts.sql: `auth.user_profiles(id)` deberia ser `auth.users(id)` - **P:** Modificar archivo SQL corrigiendo la referencia - **V:** Recrear BD en WSL, verificar tabla se crea correctamente - **E:** Modificar archivo, ejecutar DDL - **D:** Documentar correccion en changelog | ID | Tarea | Archivo | Prioridad | Esfuerzo | Dependencias | |----|-------|---------|-----------|----------|--------------| | 2.1.1 | Corregir FK price_alerts | trading/tables/11-price_alerts.sql | P0 | 0.5h | Ninguna | | 2.1.2 | Verificar creacion tabla | Script recreacion BD | P0 | 0.5h | 2.1.1 | #### SUBTAREA 2.2: Validacion Schema por Schema Para CADA schema se debe validar (CAPVED por cada uno): | ID | Schema | Tablas | Accion Principal | Esfuerzo | Paralelizable | |----|--------|--------|-----------------|----------|---------------| | 2.2.1 | auth | 13 | Documentar notifications + user_push_tokens | 2h | Si | | 2.2.2 | trading | 13 | Documentar drawing_tools + drawing_templates | 2h | Si | | 2.2.3 | education | 19 | Documentar 7 tablas faltantes | 4h | Si | | 2.2.4 | financial | 11 | Documentar refunds + currency_exchange_rates | 2h | Si | | 2.2.5 | investment | 10 | Documentar agent_executions + risk_questionnaire | 2h | Si | | 2.2.6 | ml | 12 | Documentar llm_signals + prediction_overlays | 2h | Si | | 2.2.7 | llm | 5 | Documentar user_preferences | 1h | Si | | 2.2.8 | audit | 7 | Validar completitud (ya 100%) | 0.5h | Si | | 2.2.9 | portfolio | 5 | Documentar portfolio_snapshots | 1h | Si | | 2.2.10 | market_data | 4 | Documentar staging | 1h | Si | | 2.2.11 | feature_flags | 1 | Documentar schema completo | 2h | Si | **Total 2.2:** 19.5h (paralelizable a ~8h con 3 agentes) **CAPVED para cada 2.2.X:** - **C:** Schema tiene N tablas DDL, M documentadas en inventario - **A:** Leer cada archivo SQL, comparar con inventario, identificar campos/tipos/constraints - **P:** Crear/actualizar entrada en DATABASE_INVENTORY.yml para tablas faltantes - **V:** Verificar coherencia post-actualizacion - **E:** Actualizar DATABASE_INVENTORY.yml - **D:** Registrar cambios en changelog #### SUBTAREA 2.3: Resolucion de Conflictos de Enums | ID | Conflicto | Accion | Esfuerzo | Dependencias | |----|-----------|--------|----------|--------------| | 2.3.1 | CONF-E1: transaction_type | Verificar migracion existe, crear si no | 2h | 2.2.4, 2.2.5 | | 2.3.2 | CONF-E2: risk_profile | Crear migracion a public.risk_profile | 2h | 2.2.5, 2.2.9 | | 2.3.3 | CONF-E3: timeframe | Completar migracion, agregar '1M' a market_data | 1h | 2.2.10 | **Total 2.3:** 5h #### SUBTAREA 2.4: Resolucion de Duplicaciones Funcionales | ID | Duplicacion | Accion | Esfuerzo | Dependencias | |----|------------|--------|----------|--------------| | 2.4.1 | DUP-1: symbols vs tickers | Analizar consolidacion, crear plan de migracion | 4h | 2.2.2, 2.2.10 | **Total 2.4:** 4h **TOTAL FASE-2:** 30h (~12h con paralelizacion) --- ### FASE-3: Auditoria de Integridad y Coherencia #### SUBTAREA 3.1: Validacion de Foreign Keys **CAPVED:** - **C:** 100 tablas con multiples FKs inter-schema - **A:** Recorrer cada tabla, verificar que FKs referencian tablas existentes con tipos correctos - **P:** Generar matriz de FKs con estado de validacion - **V:** Cada FK validada contra tabla destino - **E:** Ejecutar validacion - **D:** Generar FK-VALIDATION-MATRIX.yml | ID | Grupo | Tablas | Accion | Esfuerzo | Paralelizable | |----|-------|--------|--------|----------|---------------| | 3.1.1 | auth -> auth | 13 tablas | Validar FKs internas | 1h | Si | | 3.1.2 | trading -> auth, trading | 13 tablas | Validar FKs cross-schema | 1.5h | Si | | 3.1.3 | education -> auth, education | 19 tablas | Validar FKs cross-schema | 2h | Si | | 3.1.4 | financial -> auth, financial | 11 tablas | Validar FKs cross-schema | 1.5h | Si | | 3.1.5 | investment -> auth, investment | 10 tablas | Validar FKs cross-schema | 1h | Si | | 3.1.6 | ml, llm, portfolio, audit | 29 tablas | Validar FKs cross-schema | 2h | Si | | 3.1.7 | Relaciones faltantes | WEAK-1 a WEAK-4 | Documentar y proponer FKs | 2h | No (depende de 3.1.1-3.1.6) | **Total 3.1:** 11h (~5h con paralelizacion) #### SUBTAREA 3.2: Validacion de Indices | ID | Accion | Esfuerzo | Paralelizable | |----|--------|----------|---------------| | 3.2.1 | Inventariar todos los indices existentes | 3h | Si (por schema) | | 3.2.2 | Identificar queries criticas sin indice | 2h | No | | 3.2.3 | Proponer indices faltantes | 1h | No | **Total 3.2:** 6h #### SUBTAREA 3.3: Validacion de Constraints | ID | Accion | Esfuerzo | Paralelizable | |----|--------|----------|---------------| | 3.3.1 | Validar CHECK constraints por tabla | 3h | Si | | 3.3.2 | Validar UNIQUE constraints | 1h | Si | | 3.3.3 | Validar NOT NULL en campos criticos | 1h | Si | | 3.3.4 | Validar DEFAULT values | 1h | Si | **Total 3.3:** 6h #### SUBTAREA 3.4: Validacion de Funciones y Triggers | ID | Accion | Esfuerzo | Paralelizable | |----|--------|----------|---------------| | 3.4.1 | Inventariar 17+ funciones | 2h | Si | | 3.4.2 | Validar funciones usadas en triggers | 1h | No | | 3.4.3 | Identificar funciones huerfanas | 1h | No | | 3.4.4 | Validar triggers de updated_at | 1h | Si | | 3.4.5 | Validar triggers de auditoria | 1h | Si | **Total 3.4:** 6h #### SUBTAREA 3.5: Validacion de Relaciones Inter-Schema | ID | Accion | Esfuerzo | Paralelizable | |----|--------|----------|---------------| | 3.5.1 | Mapear dependencias auth -> todos los schemas | 2h | No | | 3.5.2 | Identificar ciclos de dependencia | 1h | No | | 3.5.3 | Validar ON DELETE behavior (CASCADE vs RESTRICT) | 2h | No | | 3.5.4 | Documentar diagrama ER inter-schema | 3h | No | **Total 3.5:** 8h **TOTAL FASE-3:** 37h (~18h con paralelizacion) --- ### FASE-4: Coherencia DDL-Backend #### SUBTAREA 4.1: Mapeo Tablas -> Entities **CAPVED por cada modulo backend:** | ID | Modulo | Tablas | Entities Existentes | Gap | Esfuerzo | |----|--------|--------|-------------------|-----|----------| | 4.1.1 | auth | 13 | 10 | 3 faltantes | 2h | | 4.1.2 | trading | 13 | 10 | 3 faltantes | 2h | | 4.1.3 | education | 19 | 12 | 7 faltantes | 3h | | 4.1.4 | financial | 11 | 9 | 2 faltantes | 1.5h | | 4.1.5 | investment | 10 | 7 | 3 faltantes | 1.5h | | 4.1.6 | ml | 12 | 10 | 2 faltantes | 1h | | 4.1.7 | llm | 5 | 4 | 1 faltante | 0.5h | | 4.1.8 | portfolio | 5 | 3 | 2 faltantes | 1h | | 4.1.9 | market_data | 4 | 1 | 3 faltantes | 1.5h | | 4.1.10 | audit | 7 | 0 | 7 faltantes | 2h | | 4.1.11 | feature_flags | 1 | 0 | 1 faltante | 0.5h | **Total 4.1:** 16.5h #### SUBTAREA 4.2: Mapeo Entities -> Services | ID | Accion | Esfuerzo | |----|--------|----------| | 4.2.1 | Listar todos los servicios existentes | 2h | | 4.2.2 | Mapear servicios a entities | 2h | | 4.2.3 | Identificar entities sin servicio | 1h | | 4.2.4 | Identificar servicios sin entity | 1h | **Total 4.2:** 6h #### SUBTAREA 4.3: Mapeo Services -> Controllers/Routes | ID | Accion | Esfuerzo | |----|--------|----------| | 4.3.1 | Listar todos los controllers existentes | 1h | | 4.3.2 | Mapear controllers a servicios | 1h | | 4.3.3 | Identificar endpoints sin implementacion | 2h | **Total 4.3:** 4h #### SUBTAREA 4.4: Identificacion de Gaps Backend | ID | Accion | Esfuerzo | |----|--------|----------| | 4.4.1 | Consolidar gaps DDL -> Entity | 2h | | 4.4.2 | Consolidar gaps Entity -> Service | 2h | | 4.4.3 | Consolidar gaps Service -> Controller | 1h | | 4.4.4 | Generar BACKEND-GAPS-MATRIX.yml | 2h | **Total 4.4:** 7h #### SUBTAREA 4.5: Plan de Entities Faltantes | ID | Accion | Esfuerzo | |----|--------|----------| | 4.5.1 | Priorizar entities por impacto funcional | 2h | | 4.5.2 | Definir campos de cada entity faltante | 4h | | 4.5.3 | Definir DTOs necesarios por entity | 3h | | 4.5.4 | Definir servicios necesarios por entity | 3h | **Total 4.5:** 12h **TOTAL FASE-4:** 45.5h (~20h con paralelizacion) --- ### FASE-5: Purga y Reorganizacion Documental #### SUBTAREA 5.1: Purgar Documentacion Obsoleta | ID | Accion | Archivos | Esfuerzo | |----|--------|----------|----------| | 5.1.1 | Eliminar docs/_archive/04-fase-backlog/ | 1 archivo | 0.25h | | 5.1.2 | Eliminar nota discrepancia puertos resuelta | 1 archivo | 0.25h | | 5.1.3 | Mover coherence baseline a archive | 1 archivo | 0.25h | | 5.1.4 | Verificar y completar archivado tareas 2026-01 | 20 tareas | 2h | | 5.1.5 | Limpiar carpetas de fechas vacias | 2-3 carpetas | 0.5h | **Total 5.1:** 3.25h #### SUBTAREA 5.2: Integrar Definiciones Faltantes | ID | Definicion | Modulo OQI | Tipo Doc | Esfuerzo | |----|-----------|-----------|----------|----------| | 5.2.1 | feature_flags schema | Transversal | ET + RF | 3h | | 5.2.2 | drawing_tools/templates | OQI-003 | ET + US | 2h | | 5.2.3 | price_alerts | OQI-003 | US + RF | 2h | | 5.2.4 | refunds | OQI-005 | ET + US + RF | 2h | | 5.2.5 | course_tags/instructors | OQI-002 | ET + US | 2h | | 5.2.6 | agent_executions | OQI-004 | ET + US | 2h | | 5.2.7 | prediction_overlays | OQI-006 | ET | 1h | | 5.2.8 | portfolio_snapshots | OQI-008 | ET | 1h | **Total 5.2:** 15h #### SUBTAREA 5.3: Actualizar Inventarios | ID | Inventario | Accion | Esfuerzo | |----|-----------|--------|----------| | 5.3.1 | DATABASE_INVENTORY.yml | Actualizar de 81 a 100 tablas, agregar feature_flags | 3h | | 5.3.2 | BACKEND_INVENTORY.yml | Actualizar con gaps identificados en Fase 4 | 2h | | 5.3.3 | MASTER_INVENTORY.yml | Sincronizar con cambios | 1h | | 5.3.4 | DDL-COMPLETE-MATRIX.yml | Actualizar de 93 a 100 tablas | 2h | | 5.3.5 | GAPS-TRACKING.yml | Actualizar con nuevos gaps | 2h | **Total 5.3:** 10h #### SUBTAREA 5.4: Actualizar Documentacion de Modulos | ID | Modulo | Accion | Esfuerzo | |----|--------|--------|----------| | 5.4.1 | OQI-002 | Agregar docs para 7 tablas nuevas education | 3h | | 5.4.2 | OQI-003 | Agregar docs para drawing_tools, price_alerts | 2h | | 5.4.3 | OQI-004 | Agregar docs para agent_executions | 1h | | 5.4.4 | OQI-005 | Agregar docs para refunds, currency_exchange | 2h | | 5.4.5 | OQI-006 | Agregar docs para prediction_overlays, llm_signals | 1.5h | | 5.4.6 | OQI-008 | Agregar docs para portfolio_snapshots | 1h | **Total 5.4:** 10.5h **TOTAL FASE-5:** 38.75h (~15h con paralelizacion) --- ### FASE-6: Plan Maestro de Remediacion #### SUBTAREA 6.1: Priorizar Acciones por Impacto | ID | Accion | Esfuerzo | |----|--------|----------| | 6.1.1 | Clasificar todos los gaps por P0/P1/P2/P3 | 2h | | 6.1.2 | Calcular impacto funcional de cada gap | 2h | | 6.1.3 | Generar matriz impacto vs esfuerzo | 1h | **Total 6.1:** 5h #### SUBTAREA 6.2: Definir Orden de Ejecucion | ID | Accion | Esfuerzo | |----|--------|----------| | 6.2.1 | Mapear dependencias entre subtareas | 2h | | 6.2.2 | Identificar camino critico | 1h | | 6.2.3 | Identificar tareas paralelizables | 1h | | 6.2.4 | Generar diagrama de dependencias | 2h | **Total 6.2:** 6h #### SUBTAREA 6.3: Estimar Esfuerzo | ID | Accion | Esfuerzo | |----|--------|----------| | 6.3.1 | Estimar horas por subtarea | 2h | | 6.3.2 | Agregar buffer (20%) | 0.5h | | 6.3.3 | Calcular ruta critica temporal | 1h | **Total 6.3:** 3.5h #### SUBTAREA 6.4: Generar Roadmap Actualizado | ID | Accion | Esfuerzo | |----|--------|----------| | 6.4.1 | Actualizar ROADMAP-2026-Q1.yml | 3h | | 6.4.2 | Generar EXECUTION-PLAN-MODELADO.yml | 3h | | 6.4.3 | Crear REMEDIATION-CHECKLIST.md | 2h | **Total 6.4:** 8h **TOTAL FASE-6:** 22.5h --- ## 4. RESUMEN DE ESFUERZO | Fase | Descripcion | Horas Secuencial | Horas Paralelo (est.) | |------|-------------|-----------------|----------------------| | FASE-1 | Analisis y Planificacion | COMPLETADA | COMPLETADA | | FASE-2 | Validacion Esquemas DDL | 30h | 12h | | FASE-3 | Auditoria Integridad | 37h | 18h | | FASE-4 | Coherencia DDL-Backend | 45.5h | 20h | | FASE-5 | Purga y Reorganizacion | 38.75h | 15h | | FASE-6 | Plan Maestro Remediacion | 22.5h | 22.5h | | **TOTAL** | | **173.75h** | **~87.5h** | ### Prioridad de Ejecucion ``` INMEDIATO (Hoy): └── 2.1.1: Corregir FK price_alerts (P0 BLOQUEANTE) URGENTE (Esta semana): ├── 2.2.1-2.2.11: Documentar tablas faltantes (paralelo) ├── 2.3.1-2.3.3: Resolver conflictos enums └── 5.3.1: Actualizar DATABASE_INVENTORY.yml IMPORTANTE (Proxima semana): ├── 3.1.1-3.1.7: Validar FKs ├── 4.1.1-4.1.11: Mapeo tablas -> entities └── 5.1.1-5.1.5: Purgar docs obsoletas PLANIFICADO (Semana 3-4): ├── 3.2-3.5: Indices, constraints, funciones ├── 4.2-4.5: Mapeo completo backend ├── 5.2-5.4: Integrar definiciones faltantes └── 6.1-6.4: Plan maestro remediacion ``` --- ## 5. METRICAS DE EXITO | Metrica | Baseline | Target Post-Analisis | |---------|----------|---------------------| | Coherencia DDL-Inventario | 78% (78/100) | 100% (100/100) | | FK Errors | 1 | 0 | | Conflictos Enum | 3 | 0 | | Tablas sin documentar | 19 | 0 | | Schemas sin documentar | 1 (feature_flags) | 0 | | Relaciones debiles | 4 | 0 (documentadas o resueltas) | | Duplicaciones funcionales | 1 (symbols/tickers) | 0 (plan de consolidacion) | | Docs obsoletas | ~25 archivos | 0 | | Definiciones faltantes | 8 | 0 | --- ## 6. DEPENDENCIAS ENTRE FASES ``` FASE-2 ──┐ ├──> FASE-3 (necesita schemas validados) │ ├──> FASE-4 (necesita inventario actualizado) │ └──> FASE-5 (necesita gaps identificados) │ └──> FASE-6 (necesita docs limpias y gaps consolidados) ``` **Nota:** FASE-2, FASE-4, y FASE-5 pueden ejecutarse parcialmente en paralelo. --- ## 7. ORQUESTACION DE SUBAGENTES ### Subagentes Recomendados para Paralelizacion | Subagente | Rol | Fases | Tareas Asignables | |-----------|-----|-------|-------------------| | SA-DDL-1 | Validador DDL Auth+Trading | F2, F3 | 2.2.1, 2.2.2, 3.1.1, 3.1.2 | | SA-DDL-2 | Validador DDL Education+Financial | F2, F3 | 2.2.3, 2.2.4, 3.1.3, 3.1.4 | | SA-DDL-3 | Validador DDL Investment+ML+Rest | F2, F3 | 2.2.5-2.2.11, 3.1.5, 3.1.6 | | SA-BACKEND-1 | Mapper Backend Auth+Trading | F4 | 4.1.1, 4.1.2, 4.2.1 | | SA-BACKEND-2 | Mapper Backend Education+Financial | F4 | 4.1.3, 4.1.4, 4.2.2 | | SA-DOCS-1 | Documentador/Purga | F5 | 5.1.X, 5.2.X, 5.3.X | ### Secuencia de Orquestacion ``` Turno 1 (Paralelo): SA-DDL-1, SA-DDL-2, SA-DDL-3 → Resultado: Schemas validados, inventario actualizado Turno 2 (Paralelo): SA-BACKEND-1, SA-BACKEND-2, SA-DOCS-1 → Resultado: Mapeo backend, docs purgadas Turno 3 (Secuencial): Orquestador consolida → Resultado: FASE-6 plan maestro ``` --- *Generado por: Claude Code (Opus 4.6) - Especialista en Modelado de Datos* *Sistema: SIMCO v4.0.0 | Metodologia: CAPVED* *Fecha: 2026-02-05*