-- 系统参数表（与 internal/system/entity/param_entity.go 中 GORM 模型一致；PostgreSQL）
-- 执行：psql $DATABASE_URL -f migrations/postgres/002_system.sql

BEGIN;

CREATE TABLE IF NOT EXISTS system_param (
    id              varchar(36) PRIMARY KEY,
    param_key       varchar(100)  NOT NULL,
    param_value     varchar(1000) NOT NULL,
    param_type      varchar(20)   NOT NULL DEFAULT 'text',
    param_group     varchar(50)   NOT NULL DEFAULT 'default',
    param_desc      varchar(500)  NULL,
    creator_id      varchar(36)   NOT NULL DEFAULT '',
    create_time     timestamptz   NULL DEFAULT now(),
    last_updater_id varchar(36)   NOT NULL DEFAULT '',
    update_time     timestamptz   NULL DEFAULT now()
);

CREATE UNIQUE INDEX IF NOT EXISTS uq_system_param_key ON system_param (param_key);

COMMENT ON TABLE system_param IS '系统运行参数（键值）';
COMMENT ON COLUMN system_param.param_type IS 'text,number,boolean,select';
COMMENT ON COLUMN system_param.param_group IS 'basic,security,business,system,default 等';

COMMIT;
