Migration for createdAt and updatedAt field for userCollection if not present (#5249)
This commit is contained in:
parent
e6adc27b7e
commit
598a48cea7
|
|
@ -2562,5 +2562,27 @@ public class DatabaseChangelog {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
@ChangeSet(order = "074", id = "ensure-user-created-and-updated-at-fields", author = "")
|
||||||
|
public void ensureUserCreatedAndUpdatedAt(MongoTemplate mongoTemplate) {
|
||||||
|
final List<User> missingCreatedAt = mongoTemplate.find(
|
||||||
|
query(where("createdAt").exists(false)),
|
||||||
|
User.class
|
||||||
|
);
|
||||||
|
|
||||||
|
for (User user : missingCreatedAt) {
|
||||||
|
user.setCreatedAt(Instant.parse("2019-01-07T00:00:00.00Z"));
|
||||||
|
mongoTemplate.save(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<User> missingUpdatedAt = mongoTemplate.find(
|
||||||
|
query(where("updatedAt").exists(false)),
|
||||||
|
User.class
|
||||||
|
);
|
||||||
|
|
||||||
|
for (User user : missingUpdatedAt) {
|
||||||
|
user.setUpdatedAt(Instant.now());
|
||||||
|
mongoTemplate.save(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user