Skip to content

Commit ef7a447

Browse files
authored
Script reordering: support CREATE/ALTER TRIGGER (#7553)
1 parent e730d71 commit ef7a447

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

core/src/org/labkey/core/admin/sql/ScriptReorderer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public String getReorderedScript(boolean isHtml)
118118
patterns.add(new SqlPattern("DROP INDEX (IF EXISTS )?\\w+ ON " + TABLE_NAME_REGEX + STATEMENT_ENDING_REGEX, Type.Table, Operation.Other));
119119

120120
patterns.add(new SqlPattern("(CREATE|ALTER) PROCEDURE .+?" + STATEMENT_ENDING_REGEX, Type.NonTable, Operation.Other));
121+
patterns.add(new SqlPattern("(CREATE|ALTER) TRIGGER .+?" + "END GO\\s*$", Type.NonTable, Operation.Other));
121122
patterns.add(new SqlPattern("ALTER TABLE " + TABLE_NAME_REGEX + " CHECK CONSTRAINT " + CONSTRAINT_NAME_REGEX + STATEMENT_ENDING_REGEX, Type.Table, Operation.Other));
122123
}
123124
else

core/src/org/labkey/core/admin/sql/SqlScriptController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,10 +1311,10 @@ protected ActionURL getSaveScriptActionURL(SqlScript script, String newContents,
13111311
- `EXEC core.fn_dropifexists 'MyTable', 'MySchema', 'COLUMN', 'MyColumn` is the same as `ALTER TABLE TableName DROP COLUMN IF EXISTS ColumnName`
13121312
13131313
Please do the following:
1314-
- Consolidate all iterative changes (column additions, PK changes, and renames) into the initial CREATE TABLE statements.
1314+
- Consolidate all iterative changes (column additions & renames, PK changes, and FK changes) into the initial CREATE TABLE statements.
13151315
- Remove unnecessary DROP TABLE statements and core.fn_dropifexists calls, for example, those that come before a table has been created.
13161316
- Remove all intermediate DROP and ALTER statements that are superseded by later logic.
1317-
- Remove CREATE TABLE and ALTER TABLE statements followed by DROP TABLE or and core.fn_dropifexists 'TABLE' call on that same table.
1317+
- Remove CREATE TABLE and ALTER TABLE statements followed by DROP TABLE or a core.fn_dropifexists 'TABLE' call on that same table.
13181318
13191319
Include a summary of the changes you made at the end.
13201320
""";

0 commit comments

Comments
 (0)