Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate code-first migration management tool like EntityFramework, Django-South

TL;DR is there any tool for managing (auto-creating, executing) migrations (using native .NET language) for NHibernate?

I come from Django background which encourages to develop Code-First. There's also the de-facto "industry standard" library for migrations, called South. The typical workflow for changing the schema is following:

  1. change the model code (that is, add/remove/modify classes and/or properties) [of course, model code is in native app language - here: python]
  2. run schemamigration command which auto-generates migration code [migration code is python] and writes it to "migrations" subdirectory.
  3. if necessary, tune up the auto-generated code. the auto-generator is pretty smart, but not smart enough to handle column renaming for example.
  4. run migrate command, which looks up the "migrations" directory and executes all the migrations that were not yet executed (this one is figured out using migration history table)

this is very convenient not only for development (even SCRUM where things change so fast) but also for updating production - just make sure to keep the migrations on dev-machines and production-server separate. It is also quite safe for production, since you can review and optionally modify the migration before applying it.

While evaluating ORMs for .NET, I've tried Entity Framework 5 which - as I found out - has very similar functionality to the Django-South's one. There's a Package-Manager Console command for creating migration code which might be modified before executing, there's a separate command which executes all the not-yet-executed migrations, and marks them as executed in migration history.

Is there any tool like this for NHibernate?

I am aware of SchemaUpdate functionality, but AFAIK it just updates all the things which need to be updated in one step. I wouldn't use that in production, neither during development where data loss is not a disaster but still some pain. I am also aware SchemaUpdate might be used for exporting the SQL statements to a file instead of executing them, but it's not that convenient as there's no auto-management of history migration. Plus, one have to write SQL by hand ;)

like image 957
migajek Avatar asked Oct 21 '22 00:10

migajek


1 Answers

Don't know if this really answers your question but to automate schema changes and update your mappings or even designing your mappings, it is a good idea to use tooling for that. Especially if you have a very big database/domain model.

I'm currently working with the entity developer from devart.

We compared multiple similar tools which are out there, but this one really rocks. It just has so many features and also provides the feature to add custom T4 templates to generate whatever you want out of your models and even add custom attributes to the model designer which then can be used within the code generator part...

You can also rename your entities/properties to something more readable manually and the tool will preserve this even after updates from the database schema...

And of course it supports both, model or database first approach...

You can download a trial version of cause to figure out if this would fit your needs...

like image 168
MichaC Avatar answered Oct 24 '22 04:10

MichaC