Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9d42e1c

Browse files
Thomasrludomikula
Thomasr
authored andcommitted
check mongodb version
1 parenta05e43e commit9d42e1c

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

‎server/api-service/lowcoder-server/src/main/java/org/lowcoder/runner/migrations/DatabaseChangelog.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,29 @@ public void addGidIndexesUnique(MongockTemplate mongoTemplate) {
301301
ensureIndexes(mongoTemplate,LibraryQuery.class,makeIndex("gid").unique());
302302
}
303303

304+
privateintgetMongoDBVersion(MongockTemplatemongoTemplate) {
305+
DocumentbuildInfo =mongoTemplate.executeCommand(newDocument("buildInfo",1));
306+
StringversionString =buildInfo.getString("version");
307+
if(versionString ==null)return -1;
308+
String[]versionParts =versionString.split("\\.");
309+
intmajorVersion =Integer.parseInt(versionParts[0]);
310+
returnmajorVersion;
311+
}
312+
304313
@ChangeSet(order ="026",id ="add-time-series-snapshot-history",author ="")
305314
publicvoidaddTimeSeriesSnapshotHistory(MongockTemplatemongoTemplate,CommonConfigcommonConfig) {
315+
intmongoVersion =getMongoDBVersion(mongoTemplate);
316+
if (mongoVersion <5) {
317+
log.warn("MongoDB version is below 5. Time-series collections are not supported. Upgrade the MongoDB version.");
318+
}
319+
306320
// Create the time-series collection if it doesn't exist
307321
if (!mongoTemplate.collectionExists(ApplicationHistorySnapshotTS.class)) {
308-
mongoTemplate.createCollection(ApplicationHistorySnapshotTS.class,CollectionOptions.empty().timeSeries("createdAt"));
322+
if(mongoVersion <5) {
323+
mongoTemplate.createCollection(ApplicationHistorySnapshotTS.class,CollectionOptions.empty().timeSeries("createdAt"));
324+
}else {
325+
mongoTemplate.createCollection(ApplicationHistorySnapshotTS.class);
326+
}
309327
}
310328
InstantthresholdDate =Instant.now().minus(commonConfig.getQuery().getAppSnapshotKeepDuration(),ChronoUnit.DAYS);
311329
List<ApplicationHistorySnapshot>snapshots =mongoTemplate.find(newQuery().addCriteria(Criteria.where("createdAt").gte(thresholdDate)),ApplicationHistorySnapshot.class);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp