-- 腾讯广告账户关系表
CREATE SEQUENCE IF NOT EXISTS tencent_account_relation_id_seq START WITH 1 INCREMENT BY 1;

CREATE TABLE IF NOT EXISTS tencent_account_relation (
    id BIGINT NOT NULL DEFAULT nextval('tencent_account_relation_id_seq'::regclass),
    tenant_id BIGINT NOT NULL DEFAULT 0,
    creator VARCHAR(100) DEFAULT '',
    created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    updater VARCHAR(100) DEFAULT '',
    updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    deleted_at TIMESTAMP WITH TIME ZONE,
    
    -- 业务字段
    account_id BIGINT NOT NULL,
    corporation_name VARCHAR(500),
    comment_data_list JSONB,
    is_adx BOOLEAN DEFAULT FALSE,
    is_bid BOOLEAN DEFAULT FALSE,
    is_mp BOOLEAN DEFAULT FALSE,
    
    PRIMARY KEY (id)
);

COMMENT ON TABLE tencent_account_relation IS '腾讯广告账户关系表';
COMMENT ON COLUMN tencent_account_relation.id IS '主键ID';
COMMENT ON COLUMN tencent_account_relation.tenant_id IS '租户ID';
COMMENT ON COLUMN tencent_account_relation.creator IS '创建人';
COMMENT ON COLUMN tencent_account_relation.created_at IS '创建时间';
COMMENT ON COLUMN tencent_account_relation.updater IS '更新人';
COMMENT ON COLUMN tencent_account_relation.updated_at IS '更新时间';
COMMENT ON COLUMN tencent_account_relation.deleted_at IS '软删除时间';
COMMENT ON COLUMN tencent_account_relation.account_id IS '账户ID';
COMMENT ON COLUMN tencent_account_relation.corporation_name IS '公司名称';
COMMENT ON COLUMN tencent_account_relation.comment_data_list IS '备注数据列表';
COMMENT ON COLUMN tencent_account_relation.is_adx IS '是否ADX';
COMMENT ON COLUMN tencent_account_relation.is_bid IS '是否BID';
COMMENT ON COLUMN tencent_account_relation.is_mp IS '是否MP';

-- 唯一索引：根据account_id判断是否存在
CREATE UNIQUE INDEX idx_tencent_account_relation_account_id ON tencent_account_relation(tenant_id, account_id);
CREATE INDEX idx_tencent_account_relation_corporation ON tencent_account_relation(tenant_id, corporation_name);
