WITH metamod_rule AS ( SELECT '[ { "id": "cs2-install-latest-metamod", "event": "server.install.completed", "enabled": true, "runOncePerServer": true, "continueOnError": false, "actions": [ { "id": "install-cs2-metamod", "type": "http_directory_extract", "indexUrl": "https://mms.alliedmods.net/mmsdrop/2.0/", "assetNamePattern": "^mmsource-2\\.0\\.0-git\\d+-linux\\.tar\\.gz$", "destination": "/game/csgo", "stripComponents": 0, "maxBytes": 268435456 }, { "id": "ensure-cs2-metamod-gameinfo-entry", "type": "insert_before_line", "path": "/game/csgo/gameinfo.gi", "line": "\\t\\t\\tGame csgo/addons/metamod", "beforePattern": "^\\\\s*Game\\\\s+csgo\\\\s*$", "existsPattern": "^\\\\s*Game\\\\s+csgo/addons/metamod\\\\s*$", "skipIfExists": true } ] } ]'::jsonb AS rule ) UPDATE "games" g SET "automation_rules" = CASE WHEN g."automation_rules" IS NULL OR jsonb_typeof(g."automation_rules") <> 'array' THEN (SELECT rule FROM metamod_rule) ELSE g."automation_rules" || (SELECT rule FROM metamod_rule) END, "updated_at" = now() WHERE g."slug" = 'cs2' AND NOT ( COALESCE(g."automation_rules", '[]'::jsonb) @> '[{"id":"cs2-install-latest-metamod"}]'::jsonb );