-- Migration 013: per-domain per-model discount overrides
SET search_path TO crawl;

-- 域名下某个模型的自定义折扣，优先级高于域名全局折扣
-- model_name 对应 price_snapshot.model_name
CREATE TABLE IF NOT EXISTS domain_model_prices (
    id           BIGSERIAL    PRIMARY KEY,
    domain       VARCHAR(255) NOT NULL,
    model_name   VARCHAR(255) NOT NULL,
    discount     NUMERIC(5,4) NOT NULL CHECK (discount > 0 AND discount <= 1),
    note         TEXT,
    created_at   TIMESTAMPTZ  NOT NULL DEFAULT NOW(),
    updated_at   TIMESTAMPTZ  NOT NULL DEFAULT NOW(),
    UNIQUE (domain, model_name)
);

CREATE INDEX IF NOT EXISTS idx_dmp_domain ON domain_model_prices (domain);
