DELETE FROM custom_attribute_definitions WHERE attribute_model = 'conversation_attribute' AND attribute_name IN ( 'swt_source_url', 'swt_source_search_term', 'swt_source_purchase_term', 'swt_source_keyword_id', 'swt_source_channel', 'swt_source_realtime_location', 'swt_source_region', 'swt_source_ad_account_id', 'swt_source_wakeable', 'swt_baidu_conversation_type', 'swt_baidu_agent_name', 'swt_baidu_ssid' ); UPDATE conversations SET custom_attributes = COALESCE(custom_attributes, '{}'::jsonb) - 'swt_source_url' - 'swt_source_description' - 'swt_source_search_term' - 'swt_source_purchase_term' - 'swt_source_keyword_id' - 'swt_source_channel' - 'swt_source_realtime_location' - 'swt_source_region' - 'swt_source_ad_account_id' - 'swt_source_wakeable' - 'swt_baidu_conversation_type' - 'swt_baidu_agent_name' - 'swt_baidu_ssid', updated_at = CURRENT_TIMESTAMP WHERE COALESCE(custom_attributes, '{}'::jsonb) ?| ARRAY[ 'swt_source_url', 'swt_source_description', 'swt_source_search_term', 'swt_source_purchase_term', 'swt_source_keyword_id', 'swt_source_channel', 'swt_source_realtime_location', 'swt_source_region', 'swt_source_ad_account_id', 'swt_source_wakeable', 'swt_baidu_conversation_type', 'swt_baidu_agent_name', 'swt_baidu_ssid' ]; -- Historical kind=8 system messages are backfilled from the Connector SQLite -- store because PostgreSQL intentionally does not retain the raw encoded payload.