Skip to content

Commit a7a2491

Browse files
committed
UY-948 simplified to "hotfix" prefix in migration.xml
1 parent fd5eec1 commit a7a2491

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

storage/src/main/java/pl/edu/icm/unity/store/rdbms/InitDB.java

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.util.Collection;
1414
import java.util.List;
1515
import java.util.TreeSet;
16-
import java.util.function.Predicate;
1716
import java.util.stream.Collectors;
1817

1918
import org.apache.ibatis.exceptions.PersistenceException;
@@ -115,10 +114,9 @@ public void initIfNeeded() throws FileNotFoundException, IOException, InternalEx
115114
+ "Please make sure you are updating Unity from the previous version"
116115
+ " and check release notes.");
117116
updateSchema(dbVersionAtServerStarup);
118-
}else
119-
{
120-
updateSchemaMinor(dbVersionOfSoftware);
121117
}
118+
119+
hotFix();
122120
}
123121

124122
private void assertMigrationsAreMatchingApp()
@@ -217,21 +215,30 @@ public static long dbVersion2Long(String version)
217215
Integer.parseInt(components[2]);
218216
}
219217

220-
private void updateSchema(long currentVersion)
218+
private void hotFix()
221219
{
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+
}
225237
}
226238

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)
234240
{
241+
log.info("Updating DB schema to the actual version");
235242
Collection<String> ops = new TreeSet<String>(db.getMyBatisConfiguration().getMappedStatementNames());
236243
SqlSession session = db.getSqlSession(ExecutorType.BATCH, true);
237244
try
@@ -243,7 +250,7 @@ private void updateSchema(Predicate<Long> checker)
243250

244251
String[] version = name.substring(UPDATE_SCHEMA_PFX.length()).split("-");
245252
Long schemaVersion = Long.parseLong(version[0]);
246-
if (checker.test(schemaVersion))
253+
if (schemaVersion > currentVersion)
247254
{
248255
log.debug("Run update db schema script " + name);
249256
session.update(name);
@@ -254,6 +261,7 @@ private void updateSchema(Predicate<Long> checker)
254261
{
255262
session.close();
256263
}
264+
log.info("Updated DB schema to the actual version " + AppDataSchemaVersion.CURRENT.getDbVersion());
257265
}
258266

259267
public void updateContents() throws IOException, EngineException

storage/src/main/resources/pl/edu/icm/unity/store/rdbms/mapper/migration.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
UPDATE UVOS_FLAG SET VAL = '2_8_0'
4444
</update>
4545

46-
<update id="updateSchema-20801-00">
46+
<update id="hotfix-0">
4747
<include refid="pl.edu.icm.unity.store.rdbms.mapper.InitdbMapper.sql-files"/>
4848
</update>
4949

0 commit comments

Comments
 (0)