Skip to content

Commit 1c7b2af

Browse files
authored
Option to migrate SQL Server hard tables to PostgreSQL (#907)
1 parent 9468951 commit 1c7b2af

7 files changed

Lines changed: 51 additions & 22 deletions

File tree

flow/src/org/labkey/flow/controllers/FlowController.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.labkey.api.util.FileUtil;
4747
import org.labkey.api.util.JobRunner;
4848
import org.labkey.api.util.TestContext;
49+
import org.labkey.api.util.URLHelper;
4950
import org.labkey.api.view.ActionURL;
5051
import org.labkey.api.view.HttpView;
5152
import org.labkey.api.view.JspView;
@@ -72,8 +73,6 @@
7273
import org.springframework.validation.Errors;
7374
import org.springframework.web.servlet.ModelAndView;
7475

75-
import java.net.URI;
76-
7776
@Marshal(Marshaller.Jackson)
7877
public class FlowController extends BaseFlowController
7978
{
@@ -367,8 +366,8 @@ public class SavePreferencesAction extends SimpleViewAction<Object>
367366
public ModelAndView getView(Object o, BindException errors) throws Exception
368367
{
369368
FlowPreference.update(getRequest());
370-
URI uri = new URI(getRequest().getContextPath() + "/_.gif");
371-
return HttpView.redirect(uri.toString());
369+
URLHelper url = new URLHelper(getRequest().getContextPath() + "/_.gif");
370+
return HttpView.redirect(url, false);
372371
}
373372

374373
@Override

protein/resources/schemas/dbscripts/postgresql/prot-0.000-21.000.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ CREATE TABLE prot.InfoSources
7070

7171
/*** Initializations */
7272

73+
-- @SkipOnEmptySchemasBegin
7374
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');
7475
INSERT INTO prot.InfoSources (Name, Url, InsertDate) VALUES ('NiceProt', 'http://au.expasy.org/cgi-bin/niceprot.pl?{}', '2005-03-04 12:08:10');
7576
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?
8081
UPDATE prot.InfoSources SET URL = 'http://www.uniprot.org/uniprot/{}' WHERE Name = 'NiceProt';
8182
UPDATE prot.InfoSources SET URL = 'http://www.ncbi.nlm.nih.gov/protein/{}' WHERE Name = 'Genbank';
8283
UPDATE prot.infosources SET url = 'http://amigo.geneontology.org/amigo/term/{}' WHERE Name = 'GO';
84+
-- @SkipOnEmptySchemasEnd
8385

8486
/****** AnnotationTypes */
8587
CREATE TABLE prot.AnnotationTypes
@@ -97,13 +99,15 @@ CREATE TABLE prot.AnnotationTypes
9799
);
98100
CREATE UNIQUE INDEX UQ_ProtAnnotationTypes ON prot.AnnotationTypes(Name);
99101

102+
-- @SkipOnEmptySchemasBegin
100103
INSERT INTO prot.AnnotationTypes (Name,SourceId,EntryDate) VALUES ('GO_F',5,'2005-03-04 11:37:15');
101104
INSERT INTO prot.AnnotationTypes (Name,SourceId,EntryDate) VALUES ('GO_P',5,'2005-03-04 11:37:15');
102105
INSERT INTO prot.AnnotationTypes (Name,EntryDate) VALUES ('keyword','2005-03-04 11:37:15');
103106
INSERT INTO prot.AnnotationTypes (Name,EntryDate) VALUES ('feature','2005-03-04 11:37:15');
104107
INSERT INTO prot.AnnotationTypes (Name,SourceId,EntryDate) VALUES ('GO_C',5,'2005-03-04 11:38:13');
105108
INSERT INTO prot.AnnotationTypes (Name,EntryDate) VALUES ('FullOrganismName',now());
106109
INSERT INTO prot.AnnotationTypes (Name,EntryDate) VALUES ('LookupString',now());
110+
-- @SkipOnEmptySchemasEnd
107111

108112
CREATE INDEX IX_AnnotationTypes_SourceId ON prot.annotationtypes(SourceId);
109113

@@ -124,6 +128,7 @@ CREATE TABLE prot.IdentTypes
124128
CREATE UNIQUE INDEX UQ_ProtIdentTypes ON prot.IdentTypes(Name);
125129
CREATE INDEX IX_IdentTypes_cannonicalsourceid ON prot.IdentTypes(cannonicalsourceid);
126130

131+
-- @SkipOnEmptySchemasBegin
127132
INSERT INTO prot.IdentTypes (Name,CannonicalSourceId,EntryDate) VALUES ('Genbank',1,'2005-03-04 11:37:14');
128133
INSERT INTO prot.IdentTypes (Name,CannonicalSourceId,EntryDate) VALUES ('SwissProt',2,'2005-03-04 11:37:14');
129134
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
193198
INSERT INTO prot.IdentTypes (Name,EntryDate) VALUES ('REBASE','2005-03-04 13:25:29');
194199
INSERT INTO prot.IdentTypes (Name,EntryDate) VALUES ('Maize-2DPAGE','2005-03-04 15:10:53');
195200
INSERT INTO prot.IdentTypes (Name,EntryDate) VALUES ('HIV','2005-03-04 22:13:40');
201+
-- @SkipOnEmptySchemasEnd
196202

197203
/****** Organisms */
198204
CREATE TABLE prot.Organisms
@@ -209,7 +215,9 @@ CREATE TABLE prot.Organisms
209215
);
210216
CREATE UNIQUE INDEX UQ_ProtOrganisms_Genus_Species ON prot.Organisms(Genus, Species);
211217

218+
-- @SkipOnEmptySchemasBegin
212219
INSERT INTO prot.Organisms (CommonName,Genus,Species,Comments) VALUES ('Unknown organism','Unknown','unknown','Organism is unknown');
220+
-- @SkipOnEmptySchemasEnd
213221

214222
CREATE INDEX IX_Organisms_IdentId ON prot.Organisms(IdentId);
215223

@@ -497,6 +505,7 @@ CREATE FUNCTION prot.drop_go_indexes() RETURNS void AS $$
497505
END;
498506
$$ LANGUAGE plpgsql;
499507

508+
-- @SkipOnEmptySchemasBegin
500509
-- add most common ncbi Taxonomy id's
501510

502511
CREATE TEMPORARY TABLE idents
@@ -568,6 +577,7 @@ UPDATE prot.Organisms
568577
WHERE i.OrgId = Organisms.OrgId;
569578

570579
DROP TABLE idents;
580+
-- @SkipOnEmptySchemasEnd
571581

572582
CREATE TABLE prot.FastaSequences
573583
(
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- These columns are unused and, due to data type differences, are problematic for SQL Server -> PostgreSQL migration
2+
ALTER TABLE prot.InfoSources DROP COLUMN Deleted;
3+
ALTER TABLE prot.AnnotationTypes DROP COLUMN Deleted;
4+
ALTER TABLE prot.IdentTypes DROP COLUMN Deleted;
5+
ALTER TABLE prot.Organisms DROP COLUMN Deleted;
6+
ALTER TABLE prot.Sequences DROP COLUMN Deleted;
7+
ALTER TABLE prot.Identifiers DROP COLUMN Deleted;
8+
ALTER TABLE prot.Annotations DROP COLUMN Deleted;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- These columns are unused and, due to data type differences, are problematic for SQL Server -> PostgreSQL migration
2+
EXEC core.fn_dropifexists 'InfoSources', 'prot', 'COLUMN', 'Deleted';
3+
EXEC core.fn_dropifexists 'AnnotationTypes', 'prot', 'COLUMN', 'Deleted';
4+
EXEC core.fn_dropifexists 'IdentTypes', 'prot', 'COLUMN', 'Deleted';
5+
EXEC core.fn_dropifexists 'Organisms', 'prot', 'COLUMN', 'Deleted';
6+
EXEC core.fn_dropifexists 'Sequences', 'prot', 'COLUMN', 'Deleted';
7+
EXEC core.fn_dropifexists 'Identifiers', 'prot', 'COLUMN', 'Deleted';
8+
EXEC core.fn_dropifexists 'Annotations', 'prot', 'COLUMN', 'Deleted';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- Move foreign key to the correct table. Issue 53523.
2+
ALTER TABLE prot.Organisms DROP CONSTRAINT FK_ProtSequences_ProtOrganisms;
3+
ALTER TABLE prot.Sequences ADD CONSTRAINT FK_ProtSequences_ProtOrganisms FOREIGN KEY (OrgId) REFERENCES prot.Organisms (OrgId);

protein/resources/schemas/prot.xml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
</column>
3939
<column columnName="StartPos"/>
4040
<column columnName="EndPos"/>
41-
<column columnName="Deleted">
42-
<isHidden>true</isHidden>
43-
</column>
4441
</columns>
4542
</table>
4643
<table tableName="AnnotationTypes" tableDbType="TABLE">
@@ -53,7 +50,6 @@
5350
<column columnName="Description"/>
5451
<column columnName="EntryDate"/>
5552
<column columnName="ModDate"/>
56-
<column columnName="Deleted"/>
5753
</columns>
5854
</table>
5955
<table tableName="AnnotInsertions" tableDbType="TABLE">
@@ -135,9 +131,6 @@
135131
<column columnName="SourceVersion">
136132
<isHidden>true</isHidden>
137133
</column>
138-
<column columnName="Deleted">
139-
<isHidden>true</isHidden>
140-
</column>
141134
</columns>
142135
</table>
143136
<table tableName="IdentTypes" tableDbType="TABLE">
@@ -151,9 +144,6 @@
151144
</column>
152145
<column columnName="EntryDate"/>
153146
<column columnName="Description"/>
154-
<column columnName="Deleted">
155-
<isHidden>true</isHidden>
156-
</column>
157147
</columns>
158148
</table>
159149
<table tableName="InfoSources" tableDbType="TABLE">
@@ -169,7 +159,6 @@
169159
<column columnName="LastUpdate"/>
170160
<column columnName="InsertDate"/>
171161
<column columnName="ModDate"/>
172-
<column columnName="Deleted"/>
173162
</columns>
174163
</table>
175164
<table tableName="Organisms" tableDbType="TABLE">
@@ -185,9 +174,6 @@
185174
<column columnName="IdentId">
186175
<isHidden>true</isHidden>
187176
</column>
188-
<column columnName="Deleted">
189-
<isHidden>true</isHidden>
190-
</column>
191177
</columns>
192178
</table>
193179
<table tableName="Sequences" tableDbType="TABLE">
@@ -229,9 +215,6 @@
229215
<column columnName="BestName"/>
230216
<column columnName="BestGeneName"/>
231217
<column columnName="Length"/>
232-
<column columnName="Deleted">
233-
<isHidden>true</isHidden>
234-
</column>
235218
</columns>
236219
<description>Contains a row per protein known to this server installation.</description>
237220
</table>

protein/src/org/labkey/protein/ProteinModule.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
import org.jetbrains.annotations.Nullable;
2121
import org.labkey.api.data.Container;
2222
import org.labkey.api.data.ContainerManager;
23+
import org.labkey.api.data.DbSchema;
24+
import org.labkey.api.data.SqlExecutor;
2325
import org.labkey.api.data.TableSelector;
2426
import org.labkey.api.files.FileContentService;
2527
import org.labkey.api.files.TableUpdaterFileListener;
28+
import org.labkey.api.module.DatabaseMigration;
29+
import org.labkey.api.module.DatabaseMigration.DefaultMigrationHandler;
2630
import org.labkey.api.module.DefaultModule;
2731
import org.labkey.api.module.ModuleContext;
2832
import org.labkey.api.pipeline.PipelineService;
@@ -62,7 +66,7 @@ public String getName()
6266
@Override
6367
public @Nullable Double getSchemaVersion()
6468
{
65-
return 25.000;
69+
return 25.001;
6670
}
6771

6872
@Override
@@ -125,6 +129,20 @@ public void doStartup(ModuleContext moduleContext)
125129
}
126130

127131
ProteinService.get().registerProteinSearchView(new ProteinSearchViewProvider());
132+
DatabaseMigration.registerHandler(ProteinSchema.getSchema(), new DefaultMigrationHandler()
133+
{
134+
@Override
135+
public void beforeSchema(DbSchema targetSchema)
136+
{
137+
new SqlExecutor(targetSchema).execute("ALTER TABLE prot.Organisms DROP CONSTRAINT FK_ProtOrganisms_ProtIdentifiers");
138+
}
139+
140+
@Override
141+
public void afterSchema(DbSchema targetSchema)
142+
{
143+
new SqlExecutor(targetSchema).execute("ALTER TABLE prot.Organisms ADD CONSTRAINT FK_ProtOrganisms_ProtIdentifiers FOREIGN KEY (IdentId) REFERENCES prot.Identifiers (IdentId)");
144+
}
145+
});
128146
}
129147

130148
@Override

0 commit comments

Comments
 (0)