我正在尝试将先前创建的 ID 转移到 mongock 中的其他变更集。这是我的解决方案,但我不知道它是否正确。如果您能分享您的建议,我将不胜感激。
@ChangeLog(order = "001")
public class DatabaseChangelock {
private Map<String, ObjectId> myIdMap = new HashMap<>();
@ChangeSet(order = "001", id = "logs001", author = "Me")
public void userTest(UserEntityRepo user) {
UserEntity userEntity = new UserEntity;
userEntity.setName("Mike");
userEntity.setSurname("Smith");
user.save(userEntity);
myIdMap.put("test",userEntity.getId());
}
@ChangeSet(order = "002", id = "logs002", author = "Me")
public void factoryTest(FactoryEntityRepo factory) {
FactoryEntity factoryEntity = new FactoryEntity;
factoryEntity.setName("BigCompany");
factoryEntity.setBossId(myIdMap.get("test"));
factory.save(factoryEntity);
}
}