{
  "db_name": "PostgreSQL",
  "query": "\n    UPDATE workspace_settings\n    SET git_app_installations = (\n        SELECT jsonb_agg(updated)\n        FROM (\n            -- For each element, if the account_id matches, replace it\n            SELECT\n                CASE\n                    WHEN elem->>'account_id' = ($1::jsonb)->>'account_id' THEN $1::jsonb\n                    ELSE elem\n                END AS updated\n            FROM jsonb_array_elements(git_app_installations) AS elem\n            UNION ALL\n            -- Append new installation if no element with the same account_id exists\n            SELECT $1::jsonb\n            WHERE NOT EXISTS (\n                SELECT 1\n                FROM jsonb_array_elements(git_app_installations) AS elem\n                WHERE elem->>'account_id' = ($1::jsonb)->>'account_id'\n            )\n        ) sub\n    )\n    WHERE workspace_id = $2;\n    ",
  "describe": {
    "columns": [],
    "parameters": {
      "Left": [
        "Jsonb",
        "Text"
      ]
    },
    "nullable": []
  },
  "hash": "d0bd4f43cb1feabe7ee9e017a0d6af22d25369a33247cec6e9f2d1a5eb851412"
}
