From c741bed1a4d6e29628a1c3a75e5b8494038de00d Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Thu, 3 Sep 2026 14:20:31 -0700 Subject: [PATCH 1/2] Use standard DDL instead of fn_dropifexists() proc --- .../dbscripts/postgresql/comm-drop.sql | 8 ++-- .../dbscripts/postgresql/core-drop.sql | 4 +- .../dbscripts/postgresql/prop-drop.sql | 2 +- .../dbscripts/postgresql/test-drop.sql | 9 ++-- .../dbscripts/postgresql/exp-0.000-25.000.sql | 4 +- .../schemas/dbscripts/postgresql/exp-drop.sql | 44 +++++++++---------- .../postgresql/list-0.000-22.000.sql | 8 ---- .../dbscripts/postgresql/study-drop.sql | 4 +- 8 files changed, 37 insertions(+), 46 deletions(-) diff --git a/announcements/resources/schemas/dbscripts/postgresql/comm-drop.sql b/announcements/resources/schemas/dbscripts/postgresql/comm-drop.sql index ef530913eda..7591909e16f 100644 --- a/announcements/resources/schemas/dbscripts/postgresql/comm-drop.sql +++ b/announcements/resources/schemas/dbscripts/postgresql/comm-drop.sql @@ -19,7 +19,7 @@ -- NOTE: Don't remove any of these drop statements, even if we stop re-creating the view in *-create.sql. Drop statements must -- remain in place so we can correctly upgrade from older versions, which we commit to for two years after each release. -SELECT core.fn_dropifexists('Threads', 'comm', 'VIEW', NULL); -SELECT core.fn_dropifexists('CurrentWikiVersions', 'comm', 'VIEW', NULL); -SELECT core.fn_dropifexists('AllWikiVersions', 'comm', 'VIEW', NULL); -SELECT core.fn_dropifexists('PagePaths', 'comm', 'VIEW', NULL); +DROP VIEW IF EXISTS comm.Threads; +DROP VIEW IF EXISTS comm.CurrentWikiVersions; +DROP VIEW IF EXISTS comm.AllWikiVersions; +DROP VIEW IF EXISTS comm.PagePaths; diff --git a/core/resources/schemas/dbscripts/postgresql/core-drop.sql b/core/resources/schemas/dbscripts/postgresql/core-drop.sql index f6aed33a0a3..21d0d1c7d7b 100644 --- a/core/resources/schemas/dbscripts/postgresql/core-drop.sql +++ b/core/resources/schemas/dbscripts/postgresql/core-drop.sql @@ -18,5 +18,5 @@ -- NOTE: Don't remove any of these drop statements, even if we stop re-creating the view in *-create.sql. Drop statements must -- remain in place so we can correctly upgrade from older versions, which we commit to for two years after each release. -SELECT core.fn_dropifexists('ActiveUsers', 'core', 'VIEW', NULL); -SELECT core.fn_dropifexists('Users', 'core', 'VIEW', NULL); +DROP VIEW IF EXISTS core.ActiveUsers; +DROP VIEW IF EXISTS core.Users; diff --git a/core/resources/schemas/dbscripts/postgresql/prop-drop.sql b/core/resources/schemas/dbscripts/postgresql/prop-drop.sql index c2053fcb481..06c2b8d8dcc 100644 --- a/core/resources/schemas/dbscripts/postgresql/prop-drop.sql +++ b/core/resources/schemas/dbscripts/postgresql/prop-drop.sql @@ -19,4 +19,4 @@ -- NOTE: Don't remove any of these drop statements, even if we stop re-creating the view in *-create.sql. Drop statements must -- remain in place so we can correctly upgrade from older versions, which we commit to for two years after each release. -SELECT core.fn_dropifexists('PropertyEntries', 'prop', 'VIEW', NULL); +DROP VIEW IF EXISTS prop.PropertyEntries; diff --git a/core/resources/schemas/dbscripts/postgresql/test-drop.sql b/core/resources/schemas/dbscripts/postgresql/test-drop.sql index c6085734953..34d02ee4952 100644 --- a/core/resources/schemas/dbscripts/postgresql/test-drop.sql +++ b/core/resources/schemas/dbscripts/postgresql/test-drop.sql @@ -19,12 +19,11 @@ -- NOTE: Don't remove any of these drop statements, even if we stop re-creating the view in *-create.sql. Drop statements must -- remain in place so we can correctly upgrade from older versions, which we commit to for two years after each release. -SELECT core.fn_dropifexists('TestTable3', 'test', 'VIEW', NULL); -SELECT core.fn_dropifexists('Containers2', 'test', 'VIEW', NULL); -SELECT core.fn_dropifexists('ContainerAliases2', 'test', 'VIEW', NULL); -SELECT core.fn_dropifexists('Users2', 'test', 'VIEW', NULL); +DROP VIEW IF EXISTS test.TestTable3; +DROP VIEW IF EXISTS test.Containers2; +DROP VIEW IF EXISTS test.ContainerAliases2; +DROP VIEW IF EXISTS test.Users2; --- dropifexists() doesn't like tables with % or \ DROP VIEW IF EXISTS test."a$b"; DROP VIEW IF EXISTS test."a_b"; DROP VIEW IF EXISTS test."a%b"; diff --git a/experiment/resources/schemas/dbscripts/postgresql/exp-0.000-25.000.sql b/experiment/resources/schemas/dbscripts/postgresql/exp-0.000-25.000.sql index 9cefdf5a079..8e1488201b1 100644 --- a/experiment/resources/schemas/dbscripts/postgresql/exp-0.000-25.000.sql +++ b/experiment/resources/schemas/dbscripts/postgresql/exp-0.000-25.000.sql @@ -653,8 +653,8 @@ ALTER TABLE exp.List ADD ListId INT NULL; ALTER TABLE exp.List ALTER ListId SET NOT NULL; ALTER TABLE exp.List ADD CONSTRAINT PK_List PRIMARY KEY (Container, ListId); -SELECT core.fn_dropifexists('list', 'exp', 'CONSTRAINT', 'UQ_RowId'); -SELECT core.fn_dropifexists('list', 'exp', 'COLUMN', 'rowid'); +ALTER TABLE exp.list DROP CONSTRAINT IF EXISTS UQ_RowId; +ALTER TABLE exp.list DROP COLUMN IF EXISTS rowid CASCADE; ALTER TABLE exp.list ADD FileAttachmentIndex BOOLEAN NOT NULL DEFAULT FALSE; diff --git a/experiment/resources/schemas/dbscripts/postgresql/exp-drop.sql b/experiment/resources/schemas/dbscripts/postgresql/exp-drop.sql index c23f5f2c1ca..e6acc0273f4 100644 --- a/experiment/resources/schemas/dbscripts/postgresql/exp-drop.sql +++ b/experiment/resources/schemas/dbscripts/postgresql/exp-drop.sql @@ -19,25 +19,25 @@ -- NOTE: Don't remove any of these drop statements, even if we stop re-creating the view in *-create.sql. Drop statements must -- remain in place so we can correctly upgrade from older versions, which we commit to for two years after each release. -SELECT core.fn_dropifexists('ObjectPropertiesView', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('ExperimentRunMaterialOutputs', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('ObjectClasses', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('AllLsidContainers', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('ExperimentRunDataInputs', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('ExperimentRunMaterialInputs', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('ExperimentRunDataOutputs', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('AllLsid', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('OutputDataForNode', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('OutputMaterialForNode', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('MarkedOutputDataForRun', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('MarkedOutputMaterialForRun', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('ChildDataForApplication', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('ChildMaterialForApplication', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('PredecessorAllDataView', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('PredecessorRunStartDataView', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('PredecessorOutputDataView', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('PredecessorAllMaterialsView', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('PredecessorRunStartMaterialsView', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('PredecessorOutputMaterialsView', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('ProtocolActionPredecessorLSIDView', 'exp', 'VIEW', NULL); -SELECT core.fn_dropifexists('ProtocolActionStepDetailsView', 'exp', 'VIEW', NULL); +DROP VIEW IF EXISTS exp.ObjectPropertiesView; +DROP VIEW IF EXISTS exp.ExperimentRunMaterialOutputs; +DROP VIEW IF EXISTS exp.ObjectClasses; +DROP VIEW IF EXISTS exp.AllLsidContainers; +DROP VIEW IF EXISTS exp.ExperimentRunDataInputs; +DROP VIEW IF EXISTS exp.ExperimentRunMaterialInputs; +DROP VIEW IF EXISTS exp.ExperimentRunDataOutputs; +DROP VIEW IF EXISTS exp.AllLsid; +DROP VIEW IF EXISTS exp.OutputDataForNode; +DROP VIEW IF EXISTS exp.OutputMaterialForNode; +DROP VIEW IF EXISTS exp.MarkedOutputDataForRun; +DROP VIEW IF EXISTS exp.MarkedOutputMaterialForRun; +DROP VIEW IF EXISTS exp.ChildDataForApplication; +DROP VIEW IF EXISTS exp.ChildMaterialForApplication; +DROP VIEW IF EXISTS exp.PredecessorAllDataView; +DROP VIEW IF EXISTS exp.PredecessorRunStartDataView; +DROP VIEW IF EXISTS exp.PredecessorOutputDataView; +DROP VIEW IF EXISTS exp.PredecessorAllMaterialsView; +DROP VIEW IF EXISTS exp.PredecessorRunStartMaterialsView; +DROP VIEW IF EXISTS exp.PredecessorOutputMaterialsView; +DROP VIEW IF EXISTS exp.ProtocolActionPredecessorLSIDView; +DROP VIEW IF EXISTS exp.ProtocolActionStepDetailsView; diff --git a/list/resources/schemas/dbscripts/postgresql/list-0.000-22.000.sql b/list/resources/schemas/dbscripts/postgresql/list-0.000-22.000.sql index e3e49183927..3ab8e0ab603 100644 --- a/list/resources/schemas/dbscripts/postgresql/list-0.000-22.000.sql +++ b/list/resources/schemas/dbscripts/postgresql/list-0.000-22.000.sql @@ -14,12 +14,4 @@ * limitations under the License. */ -/* list-13.10-13.20.sql */ - CREATE SCHEMA list; - -SELECT core.fn_dropifexists('indexinteger', 'exp', 'TABLE', NULL); -SELECT core.fn_dropifexists('indexvarchar', 'exp', 'TABLE', NULL); -SELECT core.fn_dropifexists('list', 'exp', 'CONSTRAINT', 'UQ_RowId'); - -ALTER TABLE exp.list DROP COLUMN IF EXISTS rowid CASCADE; diff --git a/study/resources/schemas/dbscripts/postgresql/study-drop.sql b/study/resources/schemas/dbscripts/postgresql/study-drop.sql index b5ebb274f5e..c1af8b95ff5 100644 --- a/study/resources/schemas/dbscripts/postgresql/study-drop.sql +++ b/study/resources/schemas/dbscripts/postgresql/study-drop.sql @@ -20,5 +20,5 @@ -- remain in place so we can correctly upgrade from older versions, which we commit to for two years after each release. -- Current views -SELECT core.fn_dropifexists('LockedSpecimens', 'study', 'VIEW', NULL); -SELECT core.fn_dropifexists('ParticipantGroupCohortUnion', 'study', 'VIEW', NULL); +DROP VIEW IF EXISTS study.LockedSpecimens; +DROP VIEW IF EXISTS study.ParticipantGroupCohortUnion; From 456282298d9ca600a7f3f90f5ab550a1237a1c71 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Fri, 4 Sep 2026 10:35:57 -0700 Subject: [PATCH 2/2] Remove guidance about fn_dropifexists() --- .../labkey/core/admin/sql/SqlScriptController.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/core/src/org/labkey/core/admin/sql/SqlScriptController.java b/core/src/org/labkey/core/admin/sql/SqlScriptController.java index afee8e77ffe..9efae6866b2 100644 --- a/core/src/org/labkey/core/admin/sql/SqlScriptController.java +++ b/core/src/org/labkey/core/admin/sql/SqlScriptController.java @@ -1294,19 +1294,13 @@ protected ActionURL getSaveScriptActionURL(SqlScript script, String newContents, private static final String CLEAN_UP_PROMPT = """ Refactor the script to provide a clean, "final state" version, removing redundant and unnecessary statements. - Note that the `core.fn_dropifexists` stored procedure is used to drop a TABLE, VIEW, COLUMN, or other database - object if it exists. In most cases, the first parameter specifies the table name, the second parameter specifies - the schema name, the third parameter specifies the object type, and the optional fourth parameter specifies - other details such as a column name. Here are some examples: - - `EXEC core.fn_dropifexists @objname = 'MyTable', @objschema = 'MySchema', @objtype = 'TABLE'` is the same as `DROP TABLE IF EXISTS MySchema.MyTable` - - `EXEC core.fn_dropifexists 'MyTable', 'MySchema', 'TABLE'` is the same as `DROP TABLE IF EXISTS MySchema.MyTable` - - `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 & 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 unnecessary DROP TABLE statements 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. + - Remove CREATE TABLE and ALTER TABLE statements followed by DROP TABLE call on that same table. + + Leave all comments in place unless they are associated with statements that are being removed or no longer apply for other reasons. Include a summary of the changes you made at the end. """;