Commit Graph

12 Commits

Author SHA1 Message Date
Adrian Flores Cortes
fa67494ec7 feat(ddl): Add FK indexes for 32 missing foreign keys
Creates 99-additional-fk-indexes.sql with indexes for all FKs
that were identified without dedicated index coverage.

Organized by priority:
- HIGH: billing (3), notifications (1), sales (2), commissions (1)
- MEDIUM: audit (2), storage (1), webhooks (1), whatsapp (1)
- LOW: created_by/approved_by fields across multiple schemas

References: TASK-2026-02-03-REMEDIACION-BD (P1)
Based on: INFORME-INTEGRIDAD-REFERENCIAL.md analysis

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 17:18:51 -06:00
Adrian Flores Cortes
c1c5892364 fix(ddl): Add storage triggers and fix whatsapp RLS pattern
- Add 06-triggers.sql with trg_files_updated_at and trg_usage_updated_at
  for storage.files and storage.usage tables
- Fix RLS policies in whatsapp schema to use current_setting with true
  parameter to avoid errors when app.current_tenant_id is not set

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 17:18:07 -06:00
Adrian Flores Cortes
0d3e0228f4 [CRIT-002] feat(ddl): Add public.set_updated_at() function
Create missing trigger function required by MLM schema triggers.
The function updates the updated_at column to CURRENT_TIMESTAMP
on row updates for mlm.structures, mlm.ranks, and mlm.nodes tables.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 17:17:16 -06:00
Adrian Flores Cortes
f30b672e92 fix(P3): Add missing columns to roles DDL
- Added `code` VARCHAR(50) NOT NULL for programmatic use
- Added `is_active` BOOLEAN DEFAULT TRUE
- Added `metadata` JSONB DEFAULT '{}'
- Added indexes for code and is_active
- Added unique constraint for code per tenant

Aligns DDL with role.entity.ts

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 16:07:10 -06:00
Adrian Flores Cortes
2837480e17 [SAAS-021] feat: Add MLM module DDL
- 6 tables: structures, ranks, nodes, commissions, bonuses, rank_history
- 5 enums: structure_type, node_status, commission_type, commission_status, bonus_type
- LTREE extension for hierarchical path queries
- 24 RLS policies for multi-tenancy
- GIST index for LTREE path column

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 06:48:34 -06:00
Adrian Flores Cortes
6e5244b612 [SAAS-022] feat: Add Goals module DDL
- 00-schema.sql: Schema creation with grants
- 01-enums.sql: 8 enums (goal_type, metric_type, period_type, etc.)
- 02-tables.sql: 4 tables (definitions, assignments, progress_log, milestone_notifications)
- 04-rls.sql: 16 RLS policies for tenant isolation
- 05-indexes.sql: Performance indexes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 06:29:04 -06:00
Adrian Flores Cortes
a3f354528a [SAAS-019] feat: Add Portfolio module DDL
- Schema creation and grants
- Enums: product_type, product_status, price_type, attribute_type
- Tables: categories, products, variants, prices
- RLS policies for tenant isolation
- Performance indexes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 05:43:02 -06:00
Adrian Flores Cortes
8915b7ce71 [SAAS-020] feat: Add Commissions DDL schema
- Add 01-schema.sql: Create commissions schema
- Add 02-tables.sql: commission_schemes, commission_assignments, commission_entries, commission_periods
- Add 03-functions.sql: calculate_commission(), close_period()
- Add 04-triggers.sql: Auto-calculate on insert, prevent double-counting
- Add 05-indexes.sql: Performance indexes for queries
- Add 06-seed.sql: Sample commission schemes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-24 22:51:06 -06:00
Adrian Flores Cortes
ea4f8b18a0 [SAAS-018] feat: Add sales schema DDL
- Create sales schema (00-schema.sql)
- Add sales enums (01-enums.sql): lead_status, lead_source, opportunity_stage, activity_type, activity_status
- Add tables (02-tables.sql): pipeline_stages, leads, opportunities, activities
- Add functions (03-functions.sql): convert_lead_to_opportunity, update_opportunity_stage, calculate_lead_score, get_pipeline_summary, initialize_default_stages
- Add RLS policies (04-rls.sql) for tenant isolation
- Add indexes (05-indexes.sql) for performance

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-24 20:49:35 -06:00
27de049441 [TEMPLATE-SAAS-DB] chore: Update audit schema and add migrations
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-20 04:38:47 -06:00
3ce06fbce4 Initial commit - Database de template-saas migrado desde monorepo
Migración desde workspace-v2/projects/template-saas/apps/database
Este repositorio es parte del estándar multi-repo v2

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 08:07:11 -06:00
293e228945 Initial commit 2026-01-16 14:04:04 +00:00