@@ -246,6 +246,10 @@ public void upgradeDatabase(boolean runScripts) throws StartupException {
246
246
upgradeTo520 (con , runScripts );
247
247
dbversion = 520 ;
248
248
}
249
+ if (dbversion < 610 ) {
250
+ upgradeTo610 (con , runScripts );
251
+ dbversion = 610 ;
252
+ }
249
253
250
254
// make sure the database version is the exact version
251
255
// we are upgrading too.
@@ -709,80 +713,56 @@ private void upgradeTo400(Connection con, boolean runScripts) throws StartupExce
709
713
* Upgrade database to Roller 5.0
710
714
*/
711
715
private void upgradeTo500 (Connection con , boolean runScripts ) throws StartupException {
712
-
713
- // first we need to run upgrade scripts
714
- SQLScriptRunner runner = null ;
715
- try {
716
- if (runScripts ) {
717
- String handle = getDatabaseHandle (con );
718
- String scriptPath = handle + "/400-to-500-migration.sql" ;
719
- successMessage ("Running database upgrade script: " +scriptPath );
720
- runner = new SQLScriptRunner (scripts .getDatabaseScript (scriptPath ));
721
- runner .runScript (con , true );
722
- messages .addAll (runner .getMessages ());
723
- }
724
- } catch (Exception ex ) {
725
- log .error ("ERROR running 500 database upgrade script" , ex );
726
- if (runner != null ) {
727
- messages .addAll (runner .getMessages ());
728
- }
729
-
730
- errorMessage ("Problem upgrading database to version 500" , ex );
731
- throw new StartupException ("Problem upgrading database to version 500" , ex );
732
- }
716
+ simpleUpgrade (con , 400 , 500 , runScripts );
733
717
}
734
718
735
719
/**
736
720
* Upgrade database to Roller 5.1
737
721
*/
738
722
private void upgradeTo510 (Connection con , boolean runScripts ) throws StartupException {
739
-
740
- // first we need to run upgrade scripts
741
- SQLScriptRunner runner = null ;
742
- try {
743
- if (runScripts ) {
744
- String handle = getDatabaseHandle (con );
745
- String scriptPath = handle + "/500-to-510-migration.sql" ;
746
- successMessage ("Running database upgrade script: " +scriptPath );
747
- runner = new SQLScriptRunner (scripts .getDatabaseScript (scriptPath ));
748
- runner .runScript (con , true );
749
- messages .addAll (runner .getMessages ());
750
- }
751
- } catch (Exception ex ) {
752
- log .error ("ERROR running 510 database upgrade script" , ex );
753
- if (runner != null ) {
754
- messages .addAll (runner .getMessages ());
755
- }
756
-
757
- errorMessage ("Problem upgrading database to version 510" , ex );
758
- throw new StartupException ("Problem upgrading database to version 510" , ex );
759
- }
723
+ simpleUpgrade (con , 500 , 510 , runScripts );
760
724
}
761
725
762
726
/**
763
727
* Upgrade database to Roller 5.2
764
728
*/
765
729
private void upgradeTo520 (Connection con , boolean runScripts ) throws StartupException {
730
+ simpleUpgrade (con , 510 , 520 , runScripts );
731
+ }
732
+
733
+ /**
734
+ * Upgrade database to Roller 6.1
735
+ */
736
+ private void upgradeTo610 (Connection con , boolean runScripts ) throws StartupException {
737
+ simpleUpgrade (con , 520 , 610 , runScripts );
738
+ }
739
+
740
+ /**
741
+ * Simple upgrade using single SQL migration script.
742
+ */
743
+ private void simpleUpgrade (Connection con , int fromVersion , int toVersion , boolean runScripts ) throws StartupException {
766
744
767
745
// first we need to run upgrade scripts
768
746
SQLScriptRunner runner = null ;
769
747
try {
770
748
if (runScripts ) {
771
749
String handle = getDatabaseHandle (con );
772
- String scriptPath = handle + "/510-to-520-migration.sql" ;
750
+ String scriptPath = handle + "/" +fromVersion +"-to-" +toVersion +"-migration.sql" ;
751
+
773
752
successMessage ("Running database upgrade script: " +scriptPath );
753
+
774
754
runner = new SQLScriptRunner (scripts .getDatabaseScript (scriptPath ));
775
755
runner .runScript (con , true );
776
756
messages .addAll (runner .getMessages ());
777
757
}
778
758
} catch (Exception ex ) {
779
- log .error ("ERROR running 520 database upgrade script" , ex );
759
+ log .error ("ERROR running " + fromVersion + "->" + toVersion + " database upgrade script" , ex );
780
760
if (runner != null ) {
781
761
messages .addAll (runner .getMessages ());
782
762
}
783
763
784
- errorMessage ("Problem upgrading database to version 520" , ex );
785
- throw new StartupException ("Problem upgrading database to version 520" , ex );
764
+ errorMessage ("Problem upgrading database to version " + toVersion , ex );
765
+ throw new StartupException ("Problem upgrading database to version " + toVersion , ex );
786
766
}
787
767
}
788
768
0 commit comments