39 lines
1.4 KiB
SQL
39 lines
1.4 KiB
SQL
-- ============================================================================
|
|
-- Schema: trading
|
|
-- Table: watchlist_items
|
|
-- Description: Items individuales dentro de watchlists
|
|
-- Dependencies: trading.watchlists, trading.symbols
|
|
-- ============================================================================
|
|
|
|
CREATE TABLE trading.watchlist_items (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
|
|
-- Referencias
|
|
watchlist_id UUID NOT NULL REFERENCES trading.watchlists(id) ON DELETE CASCADE,
|
|
symbol_id UUID NOT NULL REFERENCES trading.symbols(id) ON DELETE CASCADE,
|
|
|
|
-- Configuración personalizada
|
|
notes TEXT,
|
|
alert_price_high DECIMAL(20,8),
|
|
alert_price_low DECIMAL(20,8),
|
|
|
|
-- Ordenamiento
|
|
display_order INTEGER DEFAULT 0,
|
|
|
|
-- Timestamps
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
|
|
-- Constraint: un símbolo solo una vez por watchlist
|
|
CONSTRAINT uq_watchlist_items_watchlist_symbol UNIQUE (watchlist_id, symbol_id)
|
|
);
|
|
|
|
-- Índices
|
|
CREATE INDEX idx_watchlist_items_watchlist ON trading.watchlist_items(watchlist_id);
|
|
CREATE INDEX idx_watchlist_items_symbol ON trading.watchlist_items(symbol_id);
|
|
|
|
-- Comentarios
|
|
COMMENT ON TABLE trading.watchlist_items IS 'Símbolos individuales dentro de una watchlist';
|
|
COMMENT ON COLUMN trading.watchlist_items.alert_price_high IS 'Precio superior para alertas';
|
|
COMMENT ON COLUMN trading.watchlist_items.alert_price_low IS 'Precio inferior para alertas';
|