改变“模式”在 RavenDB 中
只是为了扩展我的知识,我开始研究各种 NoSQL 选项。我访问的第一个是 RavenDB,它看起来很有趣。我仍在尝试打破我根深蒂固的关系思维,以及典型的 RDBMS 维护例程。
在我日常处理实体框架时,我们会经历编写数据库更改脚本、刷新 EF 映射模型等例程。它在 NoSQL 中(尤其是 RavenDB)如何工作?一旦应用程序上线,如何更改各种 POCO 对象等并将其部署到生产环境?存储在旧 POCO 类中的数据会发生什么情况?
我还没有深入研究或愤怒地使用Raven DB。一旦我这样做了,这可能是显而易见的,但我很想事先知道,这样我就不会把自己编码到角落里。
谢谢, D .
Just for the interest of expanding my knowledge I have started looking at various NoSQL options. The first one I visited is RavenDB and it looks interesting. I am still trying to break my deep-seated relational thinking, along with the typical RDBMS maintenance routines.
In my day-to-day dealing with Entity Framework we go through the routine of scripting DB changes, refreshing the EF mapping model, etc. How does it work in NoSQL stuff, especially RavenDB? Once an app has gone life how does one make changes to the various POCO objects, etc. and deploy it to production? What happens to data stored in the old POCO classes?
I haven't delved deep or used Raven DB in anger yet. This may be obvious once I do but would love to know before hand so I don't code myself into a corner.
Thanks,
D.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它们保持原样 - 加载时不再存在的属性将被忽略(并在更改时丢失),并且丢失的属性将返回为 null,
建议您使用基于集合的操作来保持数据与对象模型的检查。
哦,看看我,我现在在计算机上!
基本上,在迁移到文档存储时,您正确地认识到您失去了一些功能并在数据库中获得了一些自由您已经定义了预先架构,并且尝试上传与该架构不匹配的数据将导致错误。
然而,重要的是要认识到无模式和无结构之间存在差异,因为您的文档都包含自己的结构(表示属性名称和属性值的键/值对)。
这使得它对于编写一些代码并保存数据的整个“刚刚开始”的因素很有用 - 但是当很容易改变代码结构时,很难将其与已经保存的数据相协调。
此时会出现一些策略:
第三个显然是一个坏主意,因为它会导致无法维护的代码,如果您只是存储事件或其他此类数据,但对大多数情况来说并不适合,那么版本控制您的类可以工作,所以您'剩下中间的选项。
我建议这样做,并遵循一些简单的规则,这些规则与处理关系数据库中的预先模式时遵循的规则相同。
等。
我希望这更有帮助:-)
They stay as they are - properties not existing anymore will be ignored when loading (and lost on change), and missing properties will come back as null,
Recommend you use set based operations to keep data in check with object model.
Oh, look at me, I'm on a computer now!
Right so basically, in moving to a document store you are right in recognising that you lose some functionality and gain some freedom in that in a database you have an up-front schema defined and trying to upload data that doesn't match that schema will result in an error.
It is important to recognise however, that there is a difference between schema-less and structure-less, in that your documents all contain their own structure (key/value pairs denoting property name and property value).
This makes it useful for the whole "just getting on" factor of writing some code and having your data persisted - but when being so easy to go around changing your code structure it can be harder to reconcile that with your already persisted data.
A few strategies present themselves at this point:
The third one is clearly a bad idea as it will lead to unmaintainable code, versioning your classes can work if you're just storing events or other such data but isn't really appropriate for most scenarios, so you're left with the middle option.
I'd recommend doing just that, and following a few simple rules along the same lines as you'd follow when dealing with an up-front schema in a relational database.
Etc.
I hope this is more helpful :-)
RavenDB 将您的 .NET 对象序列化为 JSON 格式。没有架构。
如果将一些对象添加到数据库中,它们将被序列化。如果向要序列化的类型添加一些属性,则已存储的对象将缺少这些属性。
RavenDB serializes your .NET objects to JSON format. There is no schema.
If you add some objects to your database, they will get serialized. If you add some properties to the type you are serializing, the objects you have already stored will be missing those properties.
Ayende 撰写的这篇文章介绍了如何执行从版本 1 到版本 2 的迁移(在本例中将“Name”属性更改为“FirstName”和“LastName”属性。
http://ayende.com/blog/66563/ravendb-migrations-rolling-updates
基本上,监听器是在 DocumentStore 中注册的:
示例实现摘自上述文章:
This article by Ayende describes how to perform a migration from 1 to version 2 (in this case changing a "Name" property to "FirstName" and "LastName" properties.
http://ayende.com/blog/66563/ravendb-migrations-rolling-updates
Basically a listener is registered in the DocumentStore:
Sample impementation taken from the article mentioned above:
与其说没有架构管理,不如将其移至代码中,这样代码中的对象与数据库中的对象之间永远不会不匹配。
处理更改的第一部分是确保您使用可以处理缺失/额外值的序列化程序 - 如果数据中未定义字段,请将其设置为 null。如果数据中的字段与对象的属性不匹配,请忽略它。
大多数更改都可以处理,无需更多操作 - 要么有一个新字段,并且您无论如何都需要为现有记录设置默认值,要么有一个您不再关心的旧字段。
对于更复杂的更改,例如重命名/组合字段或更改数据格式,请向对象添加新字段而不删除旧字段,并让您的加载方法从旧字段传输数据。当您保存记录时,它将采用新格式。该代码可以永久保留在适当的位置,根据需要更新数据,也可以设置一次性流程来为所有现有对象调用相同的代码。请注意,与 SQL 脚本不同,即使在大型数据集上运行需要很长时间,这种类型的更新也不需要停机,因为代码可以处理旧格式和新格式。
You don't so much have no schema management as move it into your code so there is never a mismatch between the objects in your code and those in your database.
The first part of handling changes is to make sure that you use a serializer that can handle missing/extra values - if a field isn't defined in the data, set it to null. If a field in the data doesn't match a property on your object, ignore it.
Most changes can be handled without any more than that - either there is a new field and you need to have a default value for existing records anyway, or there is an old field you don't care about any more.
For more complex changes such as renaming/combining fields or changing data format, add a new field to your object without removing the old ones and have your load method transfer data from the old fields. When you save the record it will be in the new format. This code can either be left in place permanently, updating data as needed, or you can set up a one time process to call the same code for all existing objects. Note that unlike a sql script there is no downtime required for this type of update even if it takes a long time to run on a large dataset, because the code can handle both old and new formats.