13
13
import java .util .Collection ;
14
14
import java .util .List ;
15
15
import java .util .TreeSet ;
16
- import java .util .function .Predicate ;
17
16
import java .util .stream .Collectors ;
18
17
19
18
import org .apache .ibatis .exceptions .PersistenceException ;
@@ -115,10 +114,9 @@ public void initIfNeeded() throws FileNotFoundException, IOException, InternalEx
115
114
+ "Please make sure you are updating Unity from the previous version"
116
115
+ " and check release notes." );
117
116
updateSchema (dbVersionAtServerStarup );
118
- }else
119
- {
120
- updateSchemaMinor (dbVersionOfSoftware );
121
117
}
118
+
119
+ hotFix ();
122
120
}
123
121
124
122
private void assertMigrationsAreMatchingApp ()
@@ -217,21 +215,30 @@ public static long dbVersion2Long(String version)
217
215
Integer .parseInt (components [2 ]);
218
216
}
219
217
220
- private void updateSchema ( long currentVersion )
218
+ private void hotFix ( )
221
219
{
222
- log .info ("Updating DB schema to the actual version" );
223
- updateSchema (schemaVersion -> schemaVersion > currentVersion );
224
- log .info ("Updated DB schema to the actual version " + AppDataSchemaVersion .CURRENT .getDbVersion ());
220
+ Collection <String > ops = new TreeSet <String >(db .getMyBatisConfiguration ().getMappedStatementNames ());
221
+ SqlSession session = db .getSqlSession (ExecutorType .BATCH , true );
222
+ try
223
+ {
224
+ for (String name : ops .stream ().filter (n -> n .startsWith ("hotfix" ))
225
+ .collect (Collectors .toList ()))
226
+ {
227
+
228
+ log .debug ("Run hotfix update db schema script " + name );
229
+ session .update (name );
230
+
231
+ }
232
+ session .commit ();
233
+ } finally
234
+ {
235
+ session .close ();
236
+ }
225
237
}
226
238
227
- private void updateSchemaMinor (long dbVersionOfSoftware )
228
- {
229
- log .debug ("Run minor update scripts on actual db schema" );
230
- updateSchema (schemaVersion -> dbVersionOfSoftware + 1 <= schemaVersion && schemaVersion < dbVersionOfSoftware + 99 );
231
- }
232
-
233
- private void updateSchema (Predicate <Long > checker )
239
+ private void updateSchema (long currentVersion )
234
240
{
241
+ log .info ("Updating DB schema to the actual version" );
235
242
Collection <String > ops = new TreeSet <String >(db .getMyBatisConfiguration ().getMappedStatementNames ());
236
243
SqlSession session = db .getSqlSession (ExecutorType .BATCH , true );
237
244
try
@@ -243,7 +250,7 @@ private void updateSchema(Predicate<Long> checker)
243
250
244
251
String [] version = name .substring (UPDATE_SCHEMA_PFX .length ()).split ("-" );
245
252
Long schemaVersion = Long .parseLong (version [0 ]);
246
- if (checker . test ( schemaVersion ) )
253
+ if (schemaVersion > currentVersion )
247
254
{
248
255
log .debug ("Run update db schema script " + name );
249
256
session .update (name );
@@ -254,6 +261,7 @@ private void updateSchema(Predicate<Long> checker)
254
261
{
255
262
session .close ();
256
263
}
264
+ log .info ("Updated DB schema to the actual version " + AppDataSchemaVersion .CURRENT .getDbVersion ());
257
265
}
258
266
259
267
public void updateContents () throws IOException , EngineException
0 commit comments