Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 2 additions & 2 deletions core/resources/schemas/dbscripts/postgresql/core-drop.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion core/resources/schemas/dbscripts/postgresql/prop-drop.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
9 changes: 4 additions & 5 deletions core/resources/schemas/dbscripts/postgresql/test-drop.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
14 changes: 4 additions & 10 deletions core/src/org/labkey/core/admin/sql/SqlScriptController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
""";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
44 changes: 22 additions & 22 deletions experiment/resources/schemas/dbscripts/postgresql/exp-drop.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 2 additions & 2 deletions study/resources/schemas/dbscripts/postgresql/study-drop.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;