-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cosmos: Data migration #11099
Comments
You should edit your initial post and either copy/paste some relevant data or summarize. People shouldn't need to jump back and forth to understand the issue. |
I've been keeping a close eye on the CosmosDb provider for EFCore and the migrations strategy is the only concern I have now about moving my projects to Cosmos. Just wanted to jump start this thread again to see if there has been progress on the topic - whether there will be tooling/code solution or a published best practice strategy to managing changes to the model. In my use cases, I have very large object models which represent self contained transactions (many hundreds of properties and lists of lists of objects). Currently we are using EFCore with Azure SQL Server, performance is pretty good, but it is clear that Cosmos will be significantly faster and handle scale much better. The main scenarios that I need to handle are:
With those scenarios handled, I would be able to move our apps over - more complex scenarios like relationship changes happen less frequently, perhaps just a documented best practice strategy for handling those is all that is needed for this phase. |
Currently in my project we use CosmosDB stored procedures, which are written using JS, to create data migrations. Each migration receives a mode param ( We are also running this migrations manually, and some kind of a script to run it is under development. We also have a document with an attribute |
Hi I am facing a similar kind of issue with data migration with Cosmos + EF Core 6.0. In my case, I have a few data in My Cosmos DB Collection. So when I add a new property to my data structure it throws me an error for the newly added property. The new property which is not yet in Cosmos Collection
The data in the collection is created based on the data model below.
Now I am changing the structure by adding one more property like
After the change in the data structure for an entity when I call to get the Quearyable from DbSet of the entity and try to convert it to ToList I am facing that Nullable object error. If I add the value of the field in all my documents in the collection it works fine without any error. |
@PAHeartBeat this issue is indeed about having the Cosmos provider modify all existing documents when a "schema" change occurs, i.e. a change is done in the CLR types compromising the model; in your case, the provider would automatically add JSON properties with default values (e.g. an empty string) when you add a property to a CLR type in the model. However, this isn't currently implemented, so you have two options:
|
Note: rather than having the Cosmos provider eagerly modify all existing documents on every schema change (which could be expensive), we could also think about applying schema changes lazily; in other words, when a schema change happens, we'd only apply the change when the document is next loaded (this probably requires having some sort of schema version in the Cosmos document). Other options here might be to treat missing properties as null; this would at least allow the standard "add nullable property" scenario to work correctly. |
At a minimum, can you please include the name of the offending property in the exception? I'm migrating an existing dataset to EF Core and, when I hit this error, I lose a lot of time trying to figure out where the problem is. Sometimes it's null values, other times it's names or capitalisation. It's especially painful because I can't attach a breakpoint to understand what the current state is. |
See #21006 for having a default value when reading missing properties, specifically for the (very common) scenario of adding a new property with existing documents. |
See #8443 (comment)
The text was updated successfully, but these errors were encountered: