trading-platform-database-v2/ddl/schemas/trading/tables/13-drawing_templates.sql
Adrian Flores Cortes 6da2786590 [TASK-2026-02-03-ANALISIS-DDL-MODELADO] feat(ddl): FASE-3 Moderate P1 gaps
ST-3.1: Course tags system
- education.course_tags with slug, color, featured flag
- education.course_tag_assignments (M:N) with auto usage_count
- Seeds: 10 initial tags (forex, crypto, ICT, etc.)

ST-3.2: Drawing tools for charts
- Enum: trading.drawing_tool_type (18 types including ICT)
- trading.drawing_tools with JSONB points and styles
- trading.drawing_templates for reusable presets

ST-3.3: Complete agent_executions
- Added 10 columns: execution_time_ms, slippage, risk_score, etc.
- 5 new performance indexes
- Trigger for updated_at

ST-3.4: ML composite indexes
- 8 new composite/partial indexes for predictions
- Optimized for symbol+timeframe+date queries
- Partial indexes for high confidence and overlay display

New files: 7 DDL, 2 migrations, 1 seed
Modified: 3 existing DDL files

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 23:55:24 -06:00

46 lines
2.3 KiB
SQL

-- ============================================================================
-- Schema: trading
-- File: 13-drawing_templates.sql
-- Description: Reusable drawing templates and presets
-- Related: OQI-003 Trading Charts, GAP-006
-- Dependencies: 00-enums.sql, auth.users
-- ============================================================================
CREATE TABLE IF NOT EXISTS trading.drawing_templates (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID REFERENCES auth.users(id) ON DELETE CASCADE, -- NULL = system template
name VARCHAR(100) NOT NULL,
description TEXT,
tool_type trading.drawing_tool_type NOT NULL,
style JSONB NOT NULL,
fib_levels DECIMAL(5,4)[] DEFAULT NULL,
is_system BOOLEAN NOT NULL DEFAULT false,
is_public BOOLEAN NOT NULL DEFAULT false,
usage_count INTEGER NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT drawing_templates_name_not_empty CHECK (length(trim(name)) > 0)
);
-- Indexes
CREATE INDEX idx_drawing_templates_user ON trading.drawing_templates(user_id);
CREATE INDEX idx_drawing_templates_tool_type ON trading.drawing_templates(tool_type);
CREATE INDEX idx_drawing_templates_public ON trading.drawing_templates(is_public) WHERE is_public = true;
CREATE INDEX idx_drawing_templates_system ON trading.drawing_templates(is_system) WHERE is_system = true;
-- Trigger
CREATE TRIGGER trg_drawing_templates_updated_at
BEFORE UPDATE ON trading.drawing_templates
FOR EACH ROW
EXECUTE FUNCTION public.update_updated_at();
-- Comments
COMMENT ON TABLE trading.drawing_templates IS 'Reusable drawing templates and presets for chart annotations';
COMMENT ON COLUMN trading.drawing_templates.user_id IS 'Owner of template, NULL for system templates';
COMMENT ON COLUMN trading.drawing_templates.style IS 'Default style configuration for the template';
COMMENT ON COLUMN trading.drawing_templates.fib_levels IS 'Default Fibonacci levels for retracement/extension templates';
COMMENT ON COLUMN trading.drawing_templates.is_system IS 'System-provided template (cannot be deleted by users)';
COMMENT ON COLUMN trading.drawing_templates.is_public IS 'Template is visible to all users';
COMMENT ON COLUMN trading.drawing_templates.usage_count IS 'Number of times this template has been applied';