From 750554246fc30e23a0324c4018b4f9edf24a498b Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Tue, 22 Jul 2025 22:05:11 -0700 Subject: [PATCH 1/7] Option to migrate SQL Server hard tables to PostgreSQL --- .../schemas/dbscripts/postgresql/prot-0.000-21.000.sql | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/protein/resources/schemas/dbscripts/postgresql/prot-0.000-21.000.sql b/protein/resources/schemas/dbscripts/postgresql/prot-0.000-21.000.sql index fb01593c0..425cd39eb 100644 --- a/protein/resources/schemas/dbscripts/postgresql/prot-0.000-21.000.sql +++ b/protein/resources/schemas/dbscripts/postgresql/prot-0.000-21.000.sql @@ -70,6 +70,7 @@ CREATE TABLE prot.InfoSources /*** Initializations */ +@SkipOnEmptySchemasBegin INSERT INTO prot.InfoSources (Name, Url, InsertDate) VALUES ('Genbank', 'http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=protein&cmd=search&term={}', '2005-03-04 12:08:10'); INSERT INTO prot.InfoSources (Name, Url, InsertDate) VALUES ('NiceProt', 'http://au.expasy.org/cgi-bin/niceprot.pl?{}', '2005-03-04 12:08:10'); INSERT INTO prot.InfoSources (Name, Url, InsertDate) VALUES ('GeneCards', 'http://www.genecards.org/cgi-bin/carddisp?{}&alias=yes', '2005-03-04 12:08:10'); @@ -80,6 +81,7 @@ UPDATE prot.InfoSources SET Url = 'http://www.genecards.org/cgi-bin/carddisp.pl? UPDATE prot.InfoSources SET URL = 'http://www.uniprot.org/uniprot/{}' WHERE Name = 'NiceProt'; UPDATE prot.InfoSources SET URL = 'http://www.ncbi.nlm.nih.gov/protein/{}' WHERE Name = 'Genbank'; UPDATE prot.infosources SET url = 'http://amigo.geneontology.org/amigo/term/{}' WHERE Name = 'GO'; +@SkipOnEmptySchemasEnd /****** AnnotationTypes */ CREATE TABLE prot.AnnotationTypes @@ -97,6 +99,7 @@ CREATE TABLE prot.AnnotationTypes ); CREATE UNIQUE INDEX UQ_ProtAnnotationTypes ON prot.AnnotationTypes(Name); +@SkipOnEmptySchemasBegin INSERT INTO prot.AnnotationTypes (Name,SourceId,EntryDate) VALUES ('GO_F',5,'2005-03-04 11:37:15'); INSERT INTO prot.AnnotationTypes (Name,SourceId,EntryDate) VALUES ('GO_P',5,'2005-03-04 11:37:15'); INSERT INTO prot.AnnotationTypes (Name,EntryDate) VALUES ('keyword','2005-03-04 11:37:15'); @@ -104,6 +107,7 @@ INSERT INTO prot.AnnotationTypes (Name,EntryDate) VALUES ('feature','2005-03-04 INSERT INTO prot.AnnotationTypes (Name,SourceId,EntryDate) VALUES ('GO_C',5,'2005-03-04 11:38:13'); INSERT INTO prot.AnnotationTypes (Name,EntryDate) VALUES ('FullOrganismName',now()); INSERT INTO prot.AnnotationTypes (Name,EntryDate) VALUES ('LookupString',now()); +@SkipOnEmptySchemasEnd CREATE INDEX IX_AnnotationTypes_SourceId ON prot.annotationtypes(SourceId); @@ -124,6 +128,7 @@ CREATE TABLE prot.IdentTypes CREATE UNIQUE INDEX UQ_ProtIdentTypes ON prot.IdentTypes(Name); CREATE INDEX IX_IdentTypes_cannonicalsourceid ON prot.IdentTypes(cannonicalsourceid); +@SkipOnEmptySchemasBegin INSERT INTO prot.IdentTypes (Name,CannonicalSourceId,EntryDate) VALUES ('Genbank',1,'2005-03-04 11:37:14'); INSERT INTO prot.IdentTypes (Name,CannonicalSourceId,EntryDate) VALUES ('SwissProt',2,'2005-03-04 11:37:14'); INSERT INTO prot.IdentTypes (Name,CannonicalSourceId,EntryDate) VALUES ('GeneName',3,'2005-03-04 11:37:14'); @@ -193,6 +198,7 @@ INSERT INTO prot.IdentTypes (Name,EntryDate) VALUES ('PhosSite','2005-03-04 12:4 INSERT INTO prot.IdentTypes (Name,EntryDate) VALUES ('REBASE','2005-03-04 13:25:29'); INSERT INTO prot.IdentTypes (Name,EntryDate) VALUES ('Maize-2DPAGE','2005-03-04 15:10:53'); INSERT INTO prot.IdentTypes (Name,EntryDate) VALUES ('HIV','2005-03-04 22:13:40'); +@SkipOnEmptySchemasEnd /****** Organisms */ CREATE TABLE prot.Organisms @@ -209,7 +215,9 @@ CREATE TABLE prot.Organisms ); CREATE UNIQUE INDEX UQ_ProtOrganisms_Genus_Species ON prot.Organisms(Genus, Species); +@SkipOnEmptySchemasBegin INSERT INTO prot.Organisms (CommonName,Genus,Species,Comments) VALUES ('Unknown organism','Unknown','unknown','Organism is unknown'); +@SkipOnEmptySchemasEnd CREATE INDEX IX_Organisms_IdentId ON prot.Organisms(IdentId); @@ -497,6 +505,7 @@ CREATE FUNCTION prot.drop_go_indexes() RETURNS void AS $$ END; $$ LANGUAGE plpgsql; +@SkipOnEmptySchemasBegin -- add most common ncbi Taxonomy id's CREATE TEMPORARY TABLE idents @@ -568,6 +577,7 @@ UPDATE prot.Organisms WHERE i.OrgId = Organisms.OrgId; DROP TABLE idents; +@SkipOnEmptySchemasEnd CREATE TABLE prot.FastaSequences ( From c48cdc22770a4a7ddb38bc2f3b63acb54a18dcf3 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Fri, 25 Jul 2025 15:39:51 -0700 Subject: [PATCH 2/7] Register handlers for schema-specific functionality --- .../src/org/labkey/protein/ProteinModule.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/protein/src/org/labkey/protein/ProteinModule.java b/protein/src/org/labkey/protein/ProteinModule.java index 1ebf33e9b..9155c65e3 100644 --- a/protein/src/org/labkey/protein/ProteinModule.java +++ b/protein/src/org/labkey/protein/ProteinModule.java @@ -20,9 +20,14 @@ import org.jetbrains.annotations.Nullable; import org.labkey.api.data.Container; import org.labkey.api.data.ContainerManager; +import org.labkey.api.data.DbSchema; +import org.labkey.api.data.SqlExecutor; +import org.labkey.api.data.TableInfo; import org.labkey.api.data.TableSelector; import org.labkey.api.files.FileContentService; import org.labkey.api.files.TableUpdaterFileListener; +import org.labkey.api.module.DatabaseMigration; +import org.labkey.api.module.DatabaseMigration.DefaultMigrationHandler; import org.labkey.api.module.DefaultModule; import org.labkey.api.module.ModuleContext; import org.labkey.api.pipeline.PipelineService; @@ -125,6 +130,26 @@ public void doStartup(ModuleContext moduleContext) } ProteinService.get().registerProteinSearchView(new ProteinSearchViewProvider()); + DatabaseMigration.registerHandler(ProteinSchema.getSchema(), new DefaultMigrationHandler() + { + @Override + public void beforeSchema(DbSchema targetSchema) + { + new SqlExecutor(targetSchema).execute("ALTER TABLE prot.Organisms DROP CONSTRAINT FK_ProtOrganisms_ProtIdentifiers"); + } + + @Override + public List getTablesToCopy(DbSchema targetSchema) + { + return super.getTablesToCopy(targetSchema); + } + + @Override + public void afterSchema(DbSchema targetSchema) + { + new SqlExecutor(targetSchema).execute("ALTER TABLE prot.Organisms ADD CONSTRAINT FK_ProtOrganisms_ProtIdentifiers FOREIGN KEY (IdentId) REFERENCES prot.Identifiers (IdentId)"); + } + }); } @Override From b5081f2cb78d9038d4fe41dc8dd3b64e4300d123 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Sat, 26 Jul 2025 11:45:35 -0700 Subject: [PATCH 3/7] Remove unnecessary override --- protein/src/org/labkey/protein/ProteinModule.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/protein/src/org/labkey/protein/ProteinModule.java b/protein/src/org/labkey/protein/ProteinModule.java index 9155c65e3..a95f89b8f 100644 --- a/protein/src/org/labkey/protein/ProteinModule.java +++ b/protein/src/org/labkey/protein/ProteinModule.java @@ -138,12 +138,6 @@ public void beforeSchema(DbSchema targetSchema) new SqlExecutor(targetSchema).execute("ALTER TABLE prot.Organisms DROP CONSTRAINT FK_ProtOrganisms_ProtIdentifiers"); } - @Override - public List getTablesToCopy(DbSchema targetSchema) - { - return super.getTablesToCopy(targetSchema); - } - @Override public void afterSchema(DbSchema targetSchema) { From 50489b8c16dc170ac9d2f2d532a6b30f571f7175 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Sat, 26 Jul 2025 15:42:06 -0700 Subject: [PATCH 4/7] Support skip annotations in comments for convenience --- .../postgresql/prot-0.000-21.000.sql | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/protein/resources/schemas/dbscripts/postgresql/prot-0.000-21.000.sql b/protein/resources/schemas/dbscripts/postgresql/prot-0.000-21.000.sql index 425cd39eb..a192d30d6 100644 --- a/protein/resources/schemas/dbscripts/postgresql/prot-0.000-21.000.sql +++ b/protein/resources/schemas/dbscripts/postgresql/prot-0.000-21.000.sql @@ -70,7 +70,7 @@ CREATE TABLE prot.InfoSources /*** Initializations */ -@SkipOnEmptySchemasBegin +-- @SkipOnEmptySchemasBegin INSERT INTO prot.InfoSources (Name, Url, InsertDate) VALUES ('Genbank', 'http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=protein&cmd=search&term={}', '2005-03-04 12:08:10'); INSERT INTO prot.InfoSources (Name, Url, InsertDate) VALUES ('NiceProt', 'http://au.expasy.org/cgi-bin/niceprot.pl?{}', '2005-03-04 12:08:10'); INSERT INTO prot.InfoSources (Name, Url, InsertDate) VALUES ('GeneCards', 'http://www.genecards.org/cgi-bin/carddisp?{}&alias=yes', '2005-03-04 12:08:10'); @@ -81,7 +81,7 @@ UPDATE prot.InfoSources SET Url = 'http://www.genecards.org/cgi-bin/carddisp.pl? UPDATE prot.InfoSources SET URL = 'http://www.uniprot.org/uniprot/{}' WHERE Name = 'NiceProt'; UPDATE prot.InfoSources SET URL = 'http://www.ncbi.nlm.nih.gov/protein/{}' WHERE Name = 'Genbank'; UPDATE prot.infosources SET url = 'http://amigo.geneontology.org/amigo/term/{}' WHERE Name = 'GO'; -@SkipOnEmptySchemasEnd +-- @SkipOnEmptySchemasEnd /****** AnnotationTypes */ CREATE TABLE prot.AnnotationTypes @@ -99,7 +99,7 @@ CREATE TABLE prot.AnnotationTypes ); CREATE UNIQUE INDEX UQ_ProtAnnotationTypes ON prot.AnnotationTypes(Name); -@SkipOnEmptySchemasBegin +-- @SkipOnEmptySchemasBegin INSERT INTO prot.AnnotationTypes (Name,SourceId,EntryDate) VALUES ('GO_F',5,'2005-03-04 11:37:15'); INSERT INTO prot.AnnotationTypes (Name,SourceId,EntryDate) VALUES ('GO_P',5,'2005-03-04 11:37:15'); INSERT INTO prot.AnnotationTypes (Name,EntryDate) VALUES ('keyword','2005-03-04 11:37:15'); @@ -107,7 +107,7 @@ INSERT INTO prot.AnnotationTypes (Name,EntryDate) VALUES ('feature','2005-03-04 INSERT INTO prot.AnnotationTypes (Name,SourceId,EntryDate) VALUES ('GO_C',5,'2005-03-04 11:38:13'); INSERT INTO prot.AnnotationTypes (Name,EntryDate) VALUES ('FullOrganismName',now()); INSERT INTO prot.AnnotationTypes (Name,EntryDate) VALUES ('LookupString',now()); -@SkipOnEmptySchemasEnd +-- @SkipOnEmptySchemasEnd CREATE INDEX IX_AnnotationTypes_SourceId ON prot.annotationtypes(SourceId); @@ -128,7 +128,7 @@ CREATE TABLE prot.IdentTypes CREATE UNIQUE INDEX UQ_ProtIdentTypes ON prot.IdentTypes(Name); CREATE INDEX IX_IdentTypes_cannonicalsourceid ON prot.IdentTypes(cannonicalsourceid); -@SkipOnEmptySchemasBegin +-- @SkipOnEmptySchemasBegin INSERT INTO prot.IdentTypes (Name,CannonicalSourceId,EntryDate) VALUES ('Genbank',1,'2005-03-04 11:37:14'); INSERT INTO prot.IdentTypes (Name,CannonicalSourceId,EntryDate) VALUES ('SwissProt',2,'2005-03-04 11:37:14'); INSERT INTO prot.IdentTypes (Name,CannonicalSourceId,EntryDate) VALUES ('GeneName',3,'2005-03-04 11:37:14'); @@ -198,7 +198,7 @@ INSERT INTO prot.IdentTypes (Name,EntryDate) VALUES ('PhosSite','2005-03-04 12:4 INSERT INTO prot.IdentTypes (Name,EntryDate) VALUES ('REBASE','2005-03-04 13:25:29'); INSERT INTO prot.IdentTypes (Name,EntryDate) VALUES ('Maize-2DPAGE','2005-03-04 15:10:53'); INSERT INTO prot.IdentTypes (Name,EntryDate) VALUES ('HIV','2005-03-04 22:13:40'); -@SkipOnEmptySchemasEnd +-- @SkipOnEmptySchemasEnd /****** Organisms */ CREATE TABLE prot.Organisms @@ -215,9 +215,9 @@ CREATE TABLE prot.Organisms ); CREATE UNIQUE INDEX UQ_ProtOrganisms_Genus_Species ON prot.Organisms(Genus, Species); -@SkipOnEmptySchemasBegin +-- @SkipOnEmptySchemasBegin INSERT INTO prot.Organisms (CommonName,Genus,Species,Comments) VALUES ('Unknown organism','Unknown','unknown','Organism is unknown'); -@SkipOnEmptySchemasEnd +-- @SkipOnEmptySchemasEnd CREATE INDEX IX_Organisms_IdentId ON prot.Organisms(IdentId); @@ -505,7 +505,7 @@ CREATE FUNCTION prot.drop_go_indexes() RETURNS void AS $$ END; $$ LANGUAGE plpgsql; -@SkipOnEmptySchemasBegin +-- @SkipOnEmptySchemasBegin -- add most common ncbi Taxonomy id's CREATE TEMPORARY TABLE idents @@ -577,7 +577,7 @@ UPDATE prot.Organisms WHERE i.OrgId = Organisms.OrgId; DROP TABLE idents; -@SkipOnEmptySchemasEnd +-- @SkipOnEmptySchemasEnd CREATE TABLE prot.FastaSequences ( From dd043dcb95db18acdb21849e35ac4c9baa2d3251 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Sat, 26 Jul 2025 18:13:10 -0700 Subject: [PATCH 5/7] Drop unused, problematic Deleted columns in prot schema --- .../dbscripts/postgresql/prot-25.000-25.001.sql | 8 ++++++++ .../dbscripts/sqlserver/prot-25.000-25.001.sql | 8 ++++++++ protein/resources/schemas/prot.xml | 17 ----------------- .../src/org/labkey/protein/ProteinModule.java | 3 +-- 4 files changed, 17 insertions(+), 19 deletions(-) create mode 100644 protein/resources/schemas/dbscripts/postgresql/prot-25.000-25.001.sql create mode 100644 protein/resources/schemas/dbscripts/sqlserver/prot-25.000-25.001.sql diff --git a/protein/resources/schemas/dbscripts/postgresql/prot-25.000-25.001.sql b/protein/resources/schemas/dbscripts/postgresql/prot-25.000-25.001.sql new file mode 100644 index 000000000..2c81d8562 --- /dev/null +++ b/protein/resources/schemas/dbscripts/postgresql/prot-25.000-25.001.sql @@ -0,0 +1,8 @@ +-- These columns are unused and, due to data type differences, are problematic for SQL Server -> PostgreSQL migration +ALTER TABLE prot.InfoSources DROP COLUMN Deleted; +ALTER TABLE prot.AnnotationTypes DROP COLUMN Deleted; +ALTER TABLE prot.IdentTypes DROP COLUMN Deleted; +ALTER TABLE prot.Organisms DROP COLUMN Deleted; +ALTER TABLE prot.Sequences DROP COLUMN Deleted; +ALTER TABLE prot.Identifiers DROP COLUMN Deleted; +ALTER TABLE prot.Annotations DROP COLUMN Deleted; diff --git a/protein/resources/schemas/dbscripts/sqlserver/prot-25.000-25.001.sql b/protein/resources/schemas/dbscripts/sqlserver/prot-25.000-25.001.sql new file mode 100644 index 000000000..a88892cbc --- /dev/null +++ b/protein/resources/schemas/dbscripts/sqlserver/prot-25.000-25.001.sql @@ -0,0 +1,8 @@ +-- These columns are unused and, due to data type differences, are problematic for SQL Server -> PostgreSQL migration +EXEC core.fn_dropifexists 'InfoSources', 'prot', 'COLUMN', 'Deleted'; +EXEC core.fn_dropifexists 'AnnotationTypes', 'prot', 'COLUMN', 'Deleted'; +EXEC core.fn_dropifexists 'IdentTypes', 'prot', 'COLUMN', 'Deleted'; +EXEC core.fn_dropifexists 'Organisms', 'prot', 'COLUMN', 'Deleted'; +EXEC core.fn_dropifexists 'Sequences', 'prot', 'COLUMN', 'Deleted'; +EXEC core.fn_dropifexists 'Identifiers', 'prot', 'COLUMN', 'Deleted'; +EXEC core.fn_dropifexists 'Annotations', 'prot', 'COLUMN', 'Deleted'; diff --git a/protein/resources/schemas/prot.xml b/protein/resources/schemas/prot.xml index 3034492ea..7b8a17834 100644 --- a/protein/resources/schemas/prot.xml +++ b/protein/resources/schemas/prot.xml @@ -38,9 +38,6 @@ - - true - @@ -53,7 +50,6 @@ -
@@ -135,9 +131,6 @@ true - - true -
@@ -151,9 +144,6 @@ - - true -
@@ -169,7 +159,6 @@ -
@@ -185,9 +174,6 @@ true - - true -
@@ -229,9 +215,6 @@ - - true - Contains a row per protein known to this server installation.
diff --git a/protein/src/org/labkey/protein/ProteinModule.java b/protein/src/org/labkey/protein/ProteinModule.java index a95f89b8f..7670f5f1d 100644 --- a/protein/src/org/labkey/protein/ProteinModule.java +++ b/protein/src/org/labkey/protein/ProteinModule.java @@ -22,7 +22,6 @@ import org.labkey.api.data.ContainerManager; import org.labkey.api.data.DbSchema; import org.labkey.api.data.SqlExecutor; -import org.labkey.api.data.TableInfo; import org.labkey.api.data.TableSelector; import org.labkey.api.files.FileContentService; import org.labkey.api.files.TableUpdaterFileListener; @@ -67,7 +66,7 @@ public String getName() @Override public @Nullable Double getSchemaVersion() { - return 25.000; + return 25.001; } @Override From 39f5eed6da1b3264b66aacc9663ab95b80156673 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Mon, 28 Jul 2025 13:23:19 -0700 Subject: [PATCH 6/7] Move FK to correct table --- .../schemas/dbscripts/sqlserver/prot-25.001-25.002.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 protein/resources/schemas/dbscripts/sqlserver/prot-25.001-25.002.sql diff --git a/protein/resources/schemas/dbscripts/sqlserver/prot-25.001-25.002.sql b/protein/resources/schemas/dbscripts/sqlserver/prot-25.001-25.002.sql new file mode 100644 index 000000000..13807b79f --- /dev/null +++ b/protein/resources/schemas/dbscripts/sqlserver/prot-25.001-25.002.sql @@ -0,0 +1,3 @@ +-- Move foreign key to the correct table. Issue 53523. +ALTER TABLE prot.Organisms DROP CONSTRAINT FK_ProtSequences_ProtOrganisms; +ALTER TABLE prot.Sequences ADD CONSTRAINT FK_ProtSequences_ProtOrganisms FOREIGN KEY (OrgId) REFERENCES prot.Organisms (OrgId); From e30b841941c2f741673035eae17341f92ba528d4 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Mon, 28 Jul 2025 16:19:08 -0700 Subject: [PATCH 7/7] Don't redirect to a string --- flow/src/org/labkey/flow/controllers/FlowController.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/flow/src/org/labkey/flow/controllers/FlowController.java b/flow/src/org/labkey/flow/controllers/FlowController.java index 62b5baec3..4dc09b289 100644 --- a/flow/src/org/labkey/flow/controllers/FlowController.java +++ b/flow/src/org/labkey/flow/controllers/FlowController.java @@ -46,6 +46,7 @@ import org.labkey.api.util.FileUtil; import org.labkey.api.util.JobRunner; import org.labkey.api.util.TestContext; +import org.labkey.api.util.URLHelper; import org.labkey.api.view.ActionURL; import org.labkey.api.view.HttpView; import org.labkey.api.view.JspView; @@ -72,8 +73,6 @@ import org.springframework.validation.Errors; import org.springframework.web.servlet.ModelAndView; -import java.net.URI; - @Marshal(Marshaller.Jackson) public class FlowController extends BaseFlowController { @@ -367,8 +366,8 @@ public class SavePreferencesAction extends SimpleViewAction public ModelAndView getView(Object o, BindException errors) throws Exception { FlowPreference.update(getRequest()); - URI uri = new URI(getRequest().getContextPath() + "/_.gif"); - return HttpView.redirect(uri.toString()); + URLHelper url = new URLHelper(getRequest().getContextPath() + "/_.gif"); + return HttpView.redirect(url, false); } @Override