From ebb870036c0dd6d71fab97e8bfedd12b658f134a Mon Sep 17 00:00:00 2001 From: Eric Radman Date: Fri, 18 Oct 2024 11:55:26 -0400 Subject: [PATCH] Add migration to set default alert selector In commits fc1e1f7a and e44fcdb a new Selector option was added to alerts, which may be "first", "min" or "max". This migration sets the default to "first" for existing alerts. --- .../1655999df5e3_default_alert_selector.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 migrations/versions/1655999df5e3_default_alert_selector.py diff --git a/migrations/versions/1655999df5e3_default_alert_selector.py b/migrations/versions/1655999df5e3_default_alert_selector.py new file mode 100644 index 0000000000..982eceee23 --- /dev/null +++ b/migrations/versions/1655999df5e3_default_alert_selector.py @@ -0,0 +1,27 @@ +"""set default alert selector + +Revision ID: 1655999df5e3 +Revises: 7205816877ec +Create Date: 2024-10-18 11:24:49 + +""" + +from redash.models import db + +# revision identifiers, used by Alembic. +revision = '1655999df5e3' +down_revision = '7205816877ec' +branch_labels = None +depends_on = None + + +def upgrade(): + db.session.execute(""" + UPDATE alerts + SET options = jsonb_set(options, '{selector}', '"first"') + WHERE options->>'selector' IS NULL; + """) + db.session.commit() + +def downgrade(): + pass