一对一关系到多对关系的核心数据迁移
我有一个部署的应用程序,可以对传感器的测量结果进行采样(例如,温度 °C、压力 kPa)。用户可以创建实验并收集样本。每个样本都存储为一次运行,因此实验与运行之间存在一对多关系。出于性能考虑,Run 与 Data 实体(这是实际原始数据存储的位置)具有一对一的关系;这允许加载一些运行属性,而不必加载大量数据。
我们的大多数传感器都有多个测量值,因此最好存储实际采样的所有数据。但这意味着 Run <--->数据关系需要变成Run <-->>数据(使用 Xcode 的约定)。
我面临着尝试将数据从旧的“运行对一”数据模型迁移到新的“运行对多”数据模型。这可以使用映射模型来完成吗?如果是这样,有人有任何例子吗?如果没有,有没有人有任何关于如何做到这一点的示例的指示?
感谢您的任何指示或建议。
I have a deployed app that samples measurements from sensors (e.g., Temp °C, Pressure kPa). The user can create Experiments and collect samples. Each sample is stored as a Run, such that there is a one-to-many relationship from Experiment to Run. In the interest of performance, Run has a to-one relationship with Data entity (which is where the actual raw data is stored); this allows some Run attributes to be loaded without necessarily loading lots of data.
Most of our sensors have multiple measurements, so it would be nice to store all the data that is actually being sampled. But this means that the Run <---> Data relationship needs to become Run <-->> Data (to use Xcode's convention).
I am faced with trying to migrate data from old Run to-one Data model to new Run to-many Data model. Can this be done using Mapping Models? If so, does anyone have any pointers to examples? If not, does anyone have any pointers to examples of how to do that?
Thanks for any pointers or advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该迁移应该足够简单,自动迁移就可以工作。最糟糕的情况是它需要一个映射模型,但我怀疑它会通过打开自动迁移“正常工作”。
That migration should be easy enough that automatic migration will work. Worst case is that it would require a mapping model but I suspect it will "just work" by turning on auto migration.
我最终需要多次子类化 NSEntityMigrationPolicy 。这是必要的,因为属性在不同的实体之间移动,并且添加了多个抽象级别以支持更通用的模型。同样重要的是映射模型中实体映射的顺序。
最终,我必须将 -addPersistentStoreType:configuration:URL:options:error: to: 的选项设置为:
从而省略 NSInferMappingModelAutomaticallyOption。
I ended up needing to subclass NSEntityMigrationPolicy several times. This was necessary because properties were moving from/to different entities with several levels of abstraction being added to support a considerably more general model. Also important was the ordering of entity mappings within the mapping model.
Ultimately, I had to set options for -addPersistentStoreType:configuration:URL:options:error: to:
thus omitting NSInferMappingModelAutomaticallyOption.