From a5cdb83d08c5055eb1dd50ad86095923f753a095 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Mon, 6 Apr 2026 12:56:29 -0700 Subject: [PATCH 1/2] Script reordering: support CREATE/ALTER TRIGGER --- core/src/org/labkey/core/admin/sql/ScriptReorderer.java | 1 + core/src/org/labkey/core/admin/sql/SqlScriptController.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/org/labkey/core/admin/sql/ScriptReorderer.java b/core/src/org/labkey/core/admin/sql/ScriptReorderer.java index b72cf64d750..7b8110f7f3c 100644 --- a/core/src/org/labkey/core/admin/sql/ScriptReorderer.java +++ b/core/src/org/labkey/core/admin/sql/ScriptReorderer.java @@ -118,6 +118,7 @@ public String getReorderedScript(boolean isHtml) patterns.add(new SqlPattern("DROP INDEX (IF EXISTS )?\\w+ ON " + TABLE_NAME_REGEX + STATEMENT_ENDING_REGEX, Type.Table, Operation.Other)); patterns.add(new SqlPattern("(CREATE|ALTER) PROCEDURE .+?" + STATEMENT_ENDING_REGEX, Type.NonTable, Operation.Other)); + patterns.add(new SqlPattern("(CREATE|ALTER) TRIGGER .+?" + "END GO\\s*$", Type.NonTable, Operation.Other)); patterns.add(new SqlPattern("ALTER TABLE " + TABLE_NAME_REGEX + " CHECK CONSTRAINT " + CONSTRAINT_NAME_REGEX + STATEMENT_ENDING_REGEX, Type.Table, Operation.Other)); } else diff --git a/core/src/org/labkey/core/admin/sql/SqlScriptController.java b/core/src/org/labkey/core/admin/sql/SqlScriptController.java index a7868284993..3edd080d635 100644 --- a/core/src/org/labkey/core/admin/sql/SqlScriptController.java +++ b/core/src/org/labkey/core/admin/sql/SqlScriptController.java @@ -1314,7 +1314,7 @@ protected ActionURL getSaveScriptActionURL(SqlScript script, String newContents, - Consolidate all iterative changes (column additions, PK changes, and renames) into the initial CREATE TABLE statements. - Remove unnecessary DROP TABLE statements and core.fn_dropifexists calls, for example, those that come before a table has been created. - Remove all intermediate DROP and ALTER statements that are superseded by later logic. - - Remove CREATE TABLE and ALTER TABLE statements followed by DROP TABLE or and core.fn_dropifexists 'TABLE' call on that same table. + - Remove CREATE TABLE and ALTER TABLE statements followed by DROP TABLE or a core.fn_dropifexists 'TABLE' call on that same table. Include a summary of the changes you made at the end. """; From b6347a2f3ef2e695e4a1fbd46570706654933c4c Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Mon, 6 Apr 2026 13:49:25 -0700 Subject: [PATCH 2/2] Clarify cleanup prompt --- core/src/org/labkey/core/admin/sql/SqlScriptController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/org/labkey/core/admin/sql/SqlScriptController.java b/core/src/org/labkey/core/admin/sql/SqlScriptController.java index 3edd080d635..2fe3959e7de 100644 --- a/core/src/org/labkey/core/admin/sql/SqlScriptController.java +++ b/core/src/org/labkey/core/admin/sql/SqlScriptController.java @@ -1311,7 +1311,7 @@ protected ActionURL getSaveScriptActionURL(SqlScript script, String newContents, - `EXEC core.fn_dropifexists 'MyTable', 'MySchema', 'COLUMN', 'MyColumn` is the same as `ALTER TABLE TableName DROP COLUMN IF EXISTS ColumnName` Please do the following: - - Consolidate all iterative changes (column additions, PK changes, and renames) into the initial CREATE TABLE statements. + - Consolidate all iterative changes (column additions & renames, PK changes, and FK changes) into the initial CREATE TABLE statements. - Remove unnecessary DROP TABLE statements and core.fn_dropifexists calls, for example, those that come before a table has been created. - Remove all intermediate DROP and ALTER statements that are superseded by later logic. - Remove CREATE TABLE and ALTER TABLE statements followed by DROP TABLE or a core.fn_dropifexists 'TABLE' call on that same table.