-- 添加缺失的字段到 sys_user_config 表 (PostgreSQL 版本)

-- 添加 create_by 字段
DO $$ 
BEGIN
    IF NOT EXISTS (SELECT 1 FROM information_schema.columns 
                   WHERE table_name='sys_user_config' AND column_name='create_by') THEN
        ALTER TABLE sys_user_config ADD COLUMN create_by VARCHAR(64) DEFAULT NULL;
    END IF;
END $$;

-- 添加 create_time 字段
DO $$ 
BEGIN
    IF NOT EXISTS (SELECT 1 FROM information_schema.columns 
                   WHERE table_name='sys_user_config' AND column_name='create_time') THEN
        ALTER TABLE sys_user_config ADD COLUMN create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
        COMMENT ON COLUMN sys_user_config.create_time IS '创建时间';
    END IF;
END $$;

-- 添加 update_by 字段
DO $$ 
BEGIN
    IF NOT EXISTS (SELECT 1 FROM information_schema.columns 
                   WHERE table_name='sys_user_config' AND column_name='update_by') THEN
        ALTER TABLE sys_user_config ADD COLUMN update_by VARCHAR(64) DEFAULT NULL;
    END IF;
END $$;

-- 添加 update_time 字段
DO $$ 
BEGIN
    IF NOT EXISTS (SELECT 1 FROM information_schema.columns 
                   WHERE table_name='sys_user_config' AND column_name='update_time') THEN
        ALTER TABLE sys_user_config ADD COLUMN update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
        COMMENT ON COLUMN sys_user_config.update_time IS '更新时间';
    END IF;
END $$;