CREATE TABLE user_preferences (
                                  user_id BIGINT PRIMARY KEY REFERENCES users(id),
                                  notification_order BOOLEAN DEFAULT TRUE,
                                  notification_community BOOLEAN DEFAULT TRUE,
                                  notification_system BOOLEAN DEFAULT TRUE,
                                  theme VARCHAR(20) DEFAULT 'light',
                                  language VARCHAR(10) DEFAULT 'zh-CN',
                                  updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),

                                  CONSTRAINT chk_theme CHECK (theme IN ('light', 'dark', 'auto'))
);

CREATE TRIGGER trigger_preferences_updated_at
    BEFORE UPDATE ON user_preferences
    FOR EACH ROW
    EXECUTE FUNCTION update_updated_at_column();