Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making changes to domain-model using code-first (ORM) while in production

While code-first is great for deployment and while in development I fail to see how you can push through changes made to your domain-model in a code-first way after going in production.

What do I do with the data accumulated while we were in production?

Am I supposed to manually migrate the data from the Version A schema to Version B schema. Do I need to code around the schema to prevent breaking changes? Do I say goodbye to code-first after the initial deployment and switch to database-first?

What am I missing?

like image 369
ndsc Avatar asked Apr 14 '26 06:04

ndsc


1 Answers

First a disclaimer, I don't have much experience with EF and I would assume it is similar in this regard to nHibernate. I answered similar question here. The bottom line is that EF and NHibernate are just an ORM frameworks. They have intimate knowledge of your domain but only in its current state, they don't know history. ORM can generate database schema, but this feature is only usefully for initial rollouts and integration testing. You can not rely on it in a production application that evolves and need upgrades (to both schema and data).

In my experience there is no magic tool that will write upgrade scripts, they have to be written manually or at least reviewed by developer. Tools can provide you a framework for executing these scripts, like RoundhouseE. Scott Allen has an excellent series about 'forward-only, run-once' approach.

like image 166
Dmitry Avatar answered Apr 16 '26 11:04

Dmitry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!