-- Migration 008: symbol_protections table (Layer D3)
-- Durable symbol-protection state that survives process restarts.

BEGIN;

CREATE TABLE IF NOT EXISTS symbol_protections (
    symbol              VARCHAR(32) PRIMARY KEY,
    cooldown_until      TIMESTAMPTZ,
    blacklist_until     TIMESTAMPTZ,
    consecutive_losses  INT NOT NULL DEFAULT 0,
    last_updated        TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_symbol_protections_cooldown
    ON symbol_protections (cooldown_until)
    WHERE cooldown_until IS NOT NULL;

CREATE INDEX IF NOT EXISTS idx_symbol_protections_blacklist
    ON symbol_protections (blacklist_until)
    WHERE blacklist_until IS NOT NULL;

INSERT INTO schema_versions (version, description)
VALUES (8, 'symbol_protections table for cooldowns and blacklists')
ON CONFLICT DO NOTHING;

COMMIT;
