-- 轮询配置表
-- 先删除旧表（如果存在）
DROP TABLE IF EXISTS tb_polling_config CASCADE;

CREATE TABLE tb_polling_config (
    id BIGSERIAL PRIMARY KEY,
    config_name VARCHAR(100) NOT NULL,
    card_condition VARCHAR(50),
    card_category VARCHAR(50),
    carrier_id BIGINT,
    priority INT NOT NULL DEFAULT 100,
    realname_check_interval INT,
    carddata_check_interval INT,
    package_check_interval INT,
    status SMALLINT NOT NULL DEFAULT 1,
    description TEXT,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    created_by BIGINT,
    updated_by BIGINT
);

-- 索引
CREATE INDEX idx_polling_config_status_priority ON tb_polling_config(status, priority);
CREATE INDEX idx_polling_config_carrier_id ON tb_polling_config(carrier_id);

-- 表注释
COMMENT ON TABLE tb_polling_config IS '轮询配置表 - 定义不同条件下的卡轮询策略';

-- 列注释
COMMENT ON COLUMN tb_polling_config.config_name IS '配置名称';
COMMENT ON COLUMN tb_polling_config.card_condition IS '卡状态条件：not_real_name/real_name/activated/suspended';
COMMENT ON COLUMN tb_polling_config.card_category IS '卡业务类型：normal/industry';
COMMENT ON COLUMN tb_polling_config.carrier_id IS '运营商ID（可选，精确匹配）';
COMMENT ON COLUMN tb_polling_config.priority IS '优先级（数字越小优先级越高）';
COMMENT ON COLUMN tb_polling_config.realname_check_interval IS '实名检查间隔（秒），NULL表示不检查';
COMMENT ON COLUMN tb_polling_config.carddata_check_interval IS '流量检查间隔（秒），NULL表示不检查';
COMMENT ON COLUMN tb_polling_config.package_check_interval IS '套餐检查间隔（秒），NULL表示不检查';
COMMENT ON COLUMN tb_polling_config.status IS '状态：0-禁用，1-启用';
COMMENT ON COLUMN tb_polling_config.description IS '配置说明';
COMMENT ON COLUMN tb_polling_config.created_at IS '创建时间';
COMMENT ON COLUMN tb_polling_config.updated_at IS '更新时间';
COMMENT ON COLUMN tb_polling_config.created_by IS '创建人ID';
COMMENT ON COLUMN tb_polling_config.updated_by IS '更新人ID';
