Skip to content

Commit 5840b52

Browse files
dragonpooludomikula
authored andcommitted
create migration
1 parent 0dfebdd commit 5840b52

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/authentication/util/AdvancedMapUtils.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.lowcoder.api.authentication.util;
22

3+
import org.bson.Document;
4+
5+
import java.util.HashMap;
36
import java.util.Map;
47

58
public class AdvancedMapUtils {
@@ -52,4 +55,23 @@ public static String getString(Map<String, Object> map, String key) {
5255

5356
return current!=null?current.toString():null;
5457
}
58+
59+
public static Map<String, Object> documentToMap(Document document) {
60+
if (document == null) {
61+
return new HashMap<>();
62+
}
63+
64+
Map<String, Object> map = new HashMap<>();
65+
for (Map.Entry<String, Object> entry : document.entrySet()) {
66+
Object value = entry.getValue();
67+
if (value instanceof Document) {
68+
// Recursively convert nested Document
69+
map.put(entry.getKey(), documentToMap((Document) value));
70+
} else {
71+
map.put(entry.getKey(), value);
72+
}
73+
}
74+
return map;
75+
}
76+
5577
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
import com.mongodb.client.result.DeleteResult;
1010
import lombok.extern.slf4j.Slf4j;
1111
import org.bson.Document;
12+
import org.bson.types.ObjectId;
1213
import org.lowcoder.domain.application.model.Application;
1314
import org.lowcoder.domain.application.model.ApplicationHistorySnapshot;
1415
import org.lowcoder.domain.application.model.ApplicationHistorySnapshotTS;
16+
import org.lowcoder.domain.application.model.ApplicationRecord;
1517
import org.lowcoder.domain.bundle.model.Bundle;
1618
import org.lowcoder.domain.datasource.model.Datasource;
1719
import org.lowcoder.domain.datasource.model.DatasourceStructureDO;
@@ -49,8 +51,10 @@
4951
import java.time.temporal.ChronoUnit;
5052
import java.util.Arrays;
5153
import java.util.List;
54+
import java.util.Map;
5255
import java.util.Set;
5356

57+
import static org.lowcoder.api.authentication.util.AdvancedMapUtils.documentToMap;
5458
import static org.lowcoder.domain.util.QueryDslUtils.fieldName;
5559
import static org.lowcoder.sdk.util.IDUtils.generate;
5660

@@ -422,6 +426,31 @@ public void populateEmailInUserConnections(MongockTemplate mongoTemplate, Common
422426

423427
}
424428

429+
@ChangeSet(order = "028", id = "published-to-record", author = "Thomas")
430+
public void publishedToRecord(MongockTemplate mongoTemplate, CommonConfig commonConfig) {
431+
Query query = new Query(Criteria.where("publishedApplicationDSL").exists(true));
432+
433+
MongoCursor<Document> cursor = mongoTemplate.getCollection("application").find(query.getQueryObject()).iterator();
434+
435+
while (cursor.hasNext()) {
436+
Document document = cursor.next();
437+
Document dsl = (Document) document.get("publishedApplicationDSL");
438+
ObjectId id = document.getObjectId("_id");
439+
String createdBy = document.getString("createdBy");
440+
Map<String, Object> dslMap = documentToMap(dsl);
441+
ApplicationRecord record = ApplicationRecord.builder()
442+
.applicationId(id.toHexString())
443+
.applicationDSL(dslMap)
444+
.commitMessage("")
445+
.tag("1.0.0")
446+
.createdBy(createdBy)
447+
.modifiedBy(createdBy)
448+
.createdAt(Instant.now())
449+
.updatedAt(Instant.now())
450+
.build();
451+
mongoTemplate.insert(record);
452+
}
453+
}
425454

426455
private void addGidField(MongockTemplate mongoTemplate, String collectionName) {
427456
// Create a query to match all documents

0 commit comments

Comments
 (0)