Skip to content

Commit 1500c55

Browse files
authored
Merge pull request #1383 from lowcoder-org/fix/byuser
organization/byuser endpoint issue fixed
2 parents a55bd38 + 8bfb6c1 commit 1500c55

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

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

+26
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,32 @@ public void addTimeSeriesSnapshotHistory(MongockTemplate mongoTemplate, CommonCo
396396
makeIndex("createdAt"));
397397
}
398398

399+
@ChangeSet(order = "027", id = "populate-email-in-user-connections", author = "Thomas")
400+
public void populateEmailInUserConnections(MongockTemplate mongoTemplate, CommonConfig commonConfig) {
401+
Query query = new Query(Criteria.where("connections.authId").is("EMAIL")
402+
.and("connections.email").is(null));
403+
404+
// Get the collection directly and use a cursor for manual iteration
405+
MongoCursor<Document> cursor = mongoTemplate.getCollection("user").find(query.getQueryObject()).iterator();
406+
407+
while (cursor.hasNext()) {
408+
Document document = cursor.next();
409+
410+
// Retrieve connections array
411+
List<Document> connections = (List<Document>) document.get("connections");
412+
for (Document connection : connections) {
413+
if ("EMAIL".equals(connection.getString("authId")) && !connection.containsKey("email")) {
414+
// Set the email field with the value of the name field
415+
connection.put("email", connection.getString("name"));
416+
}
417+
}
418+
419+
// Save the updated document back to the collection
420+
mongoTemplate.getCollection("user").replaceOne(new Document("_id", document.get("_id")), document);
421+
}
422+
423+
}
424+
399425

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

0 commit comments

Comments
 (0)