diff --git a/openupgrade_scripts/scripts/im_livechat/19.0.1.0/post-migration.py b/openupgrade_scripts/scripts/im_livechat/19.0.1.0/post-migration.py index 5aa89d143a0..03591793d5f 100644 --- a/openupgrade_scripts/scripts/im_livechat/19.0.1.0/post-migration.py +++ b/openupgrade_scripts/scripts/im_livechat/19.0.1.0/post-migration.py @@ -30,6 +30,27 @@ def im_livechat_channel_rule_chatbot_enabled_condition(env): ) +def discuss_channel_livechat_end_dt(env): + """19.0 replaces the ``livechat_active`` boolean with ``livechat_end_dt``. + Without a backfill every historically closed session migrates as still + open (multi-year durations, live status in the new dashboards). Clearing + the status also satisfies CHECK(livechat_end_dt IS NULL OR livechat_status + IS NULL).""" + if not openupgrade.column_exists(env.cr, "discuss_channel", "livechat_active"): + return + openupgrade.logged_query( + env.cr, + """ + UPDATE discuss_channel + SET livechat_end_dt = COALESCE(write_date, create_date), + livechat_status = NULL + WHERE channel_type = 'livechat' + AND livechat_active IS NOT TRUE + AND livechat_end_dt IS NULL + """, + ) + + @openupgrade.migrate() def migrate(env, version): openupgrade.load_data(env, "im_livechat", "19.0.1.0/noupdate_changes.xml") @@ -43,3 +64,4 @@ def migrate(env, version): ) chatbot_script_step_message(env) im_livechat_channel_rule_chatbot_enabled_condition(env) + discuss_channel_livechat_end_dt(env)