-- 创建受控系统配置表；具体业务 Key 由所属业务模块注册，不在公共迁移中预置。
CREATE TABLE tb_system_config (
    id bigserial PRIMARY KEY,
    config_key varchar(150) NOT NULL,
    config_value text NOT NULL,
    value_type varchar(20) NOT NULL,
    module varchar(100) NOT NULL,
    description varchar(500) NOT NULL,
    is_readonly boolean NOT NULL DEFAULT false,
    is_sensitive boolean NOT NULL DEFAULT false,
    creator bigint NOT NULL DEFAULT 0,
    updater bigint NOT NULL DEFAULT 0,
    created_at timestamptz NOT NULL DEFAULT NOW(),
    updated_at timestamptz NOT NULL DEFAULT NOW(),
    CONSTRAINT uq_system_config_key UNIQUE (config_key),
    CONSTRAINT ck_system_config_value_type CHECK (value_type IN ('string', 'int', 'bool', 'json'))
);

CREATE INDEX idx_system_config_module_key ON tb_system_config (module, config_key);

COMMENT ON TABLE tb_system_config IS '受控系统配置表';
COMMENT ON COLUMN tb_system_config.value_type IS '值类型 string/int/bool/json';
