From bf681e330b269f668235c47cfb6be0faaac1b2ec Mon Sep 17 00:00:00 2001 From: ivan-m-dev Date: Fri, 13 Feb 2026 12:38:10 +0100 Subject: [PATCH] HCK-14816-expect-clause-formatting --- forward_engineering/utils/general.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/forward_engineering/utils/general.js b/forward_engineering/utils/general.js index fd7ef16..5cf25f3 100644 --- a/forward_engineering/utils/general.js +++ b/forward_engineering/utils/general.js @@ -190,10 +190,20 @@ const wrapInBrackets = (str = '') => { * @param statements {Array} * */ const buildScript = statements => { + const FAIL_UPDATE_TOKEN = 'FAIL_UPDATE_GUARD_TOKEN'; + const nonEmptyScripts = statements.filter(statement => statement); - const formattedScripts = nonEmptyScripts.map(script => - sqlFormatter.format(script, { indent: ' ', linesBetweenQueries: 2 }).replace(/\{ \{ (.+?) } }/g, '{{$1}}'), - ); + const formattedScripts = nonEmptyScripts.map(script => { + // We need to replace "FAIL UPDATE" with a guard token before formatting the script, + // because the SQL formatter doesn't recognize "FAIL UPDATE" as a valid syntax and breaks it, + // while "FAIL_UPDATE_GUARD_TOKEN" is not a valid SQL syntax and will be left unchanged by the formatter. + const protectedScript = script.replaceAll(/FAIL\s+UPDATE/gi, FAIL_UPDATE_TOKEN); + + return sqlFormatter + .format(protectedScript, { indent: ' ', linesBetweenQueries: 2 }) + .replace(/\{ \{ (.+?) } }/g, '{{$1}}') + .replaceAll(FAIL_UPDATE_TOKEN, 'FAIL UPDATE'); + }); return formattedScripts.join('\n\n') + '\n\n'; };