Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(migrator): guard migration 3.20.2 against non-array sqlReviewRules (#20766)

rebelice2cc0759d32d6
diff --git a/backend/migrator/migration/3.20/0002##remove_select_only_sql_review_rules.sql b/backend/migrator/migration/3.20/0002##remove_select_only_sql_review_rules.sql
index 9fcd054cf8..baf652030e 100644
--- a/backend/migrator/migration/3.20/0002##remove_select_only_sql_review_rules.sql
+++ b/backend/migrator/migration/3.20/0002##remove_select_only_sql_review_rules.sql
@@ -35,7 +35,12 @@ SET payload = jsonb_set(
'[]'::jsonb
)
)
-WHERE payload ? 'sqlReviewRules'
+-- jsonb_typeof guards against non-array values: `{"sqlReviewRules": null}`
+-- exists in the wild and `payload ? 'sqlReviewRules'` alone lets the scalar
+-- reach jsonb_array_elements, aborting the migration with SQLSTATE 22023
+-- ("cannot extract elements from a scalar") and blocking server startup.
+-- Non-array shapes carry no rule references, so skipping them is safe.
+WHERE jsonb_typeof(payload->'sqlReviewRules') = 'array'
AND EXISTS (
SELECT 1
FROM jsonb_array_elements(payload->'sqlReviewRules') AS rule