From ee9913b6d0aae42fb433168198f83d353fee1780 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Sun, 1 Nov 2026 14:24:00 -0500 Subject: [PATCH] fix(prometheus): the migration removing sign-in targets runs on a new database, where the metric tables may not exist yet (#6747) Co-Authored-By: Claude Opus 5.5 --- .../migrations/versions/prometheus_005_own_tokens.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/prometheus/migrations/versions/prometheus_005_own_tokens.py b/plugins/prometheus/migrations/versions/prometheus_005_own_tokens.py index 1e62cb0..18959b1 100644 --- a/plugins/prometheus/migrations/versions/prometheus_005_own_tokens.py +++ b/plugins/prometheus/migrations/versions/prometheus_005_own_tokens.py @@ -17,11 +17,13 @@ depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: # Left in place, such a target would ask with no token, and some services ban - # an address for that. Its newest values go with it; history ages out. - op.execute(""" - DELETE FROM plugin_metric_latest l USING prometheus_targets t - WHERE t.token_from IS NOT NULL AND l.source_module = 'prometheus' - AND (l.resource_name = t.name OR left(l.resource_name, length(t.name) + 1) = t.name || ':')""") + # an address for that. Its newest values go with it; history ages out. On a new + # database the metric tables may not exist yet, and there is nothing to remove. + if sa.inspect(op.get_bind()).has_table("plugin_metric_latest"): + op.execute(""" + DELETE FROM plugin_metric_latest l USING prometheus_targets t + WHERE t.token_from IS NOT NULL AND l.source_module = 'prometheus' + AND (l.resource_name = t.name OR left(l.resource_name, length(t.name) + 1) = t.name || ':')""") op.execute("DELETE FROM prometheus_targets WHERE token_from IS NOT NULL") op.drop_column("prometheus_targets", "token_from")