📜 ⬆️ ⬇️

Database Migrations for .NET

In the already difficult process of developing software products from time to time there are very very unpleasant questions. One of them is what to do with the database structure, how to store version information, how to update copies of the database on servers, and how to organize collaboration.


Problem


Database is an integral part of your application. If you deploy version 2.0 of this application on the database version 1.0, then, in general, you end up with an inoperative program. That is why the database should be in the version control system directly next to the program source.

The whole point of the problem lies in the fact that the “immediately next” condition in the case of a database is rather difficult to accomplish. The question is what exactly to store in the version control system. Whole database? Totally pointless exercise. All scripted database schema? How then to make incremental changes to existing structures? Scripts with incremental changes? Obviously, this will be the most correct solution, but how to make sure that the scripts are applied in the correct sequence, exactly as many times as required, and exactly on those databases on which this is necessary?

Decision


Here at this moment special means appear on the scene.
')
One of them (unscrupulous PR begins, for the sake of which everything was started) is octalforty Wizardby. This tool allows you to automate the bringing of the database schema “to the standard”, reducing all the necessary manipulations to two things: writing migrations and working with the console application that processes the mentioned migrations.

In essence, “migration” is an instruction that tells how to make a version N + 1 schema from a database schema of version N. In other (very different) words:

migration "Oxite" revision => 1: <br> version 20090323103239:<br> add table oxite_Language:<br> add column LanguageID type => Guid, nullable => false , primary - key => true <br> add column LanguageName type => AnsiString, length => 8, nullable => false <br> add column LanguageDisplayName type => String, length => 50, nullable => false <br><br> * This source code was highlighted with Source Code Highlighter .


and further:



then in the end:



But if then:

version 20090330170528:<br> oxite_User:<br> UserID type => PK, primary - key => true <br> Username type => LongName, unique => true <br> DisplayName type => LongName<br> Email type => LongName<br> HashedEmail type => ShortName<br> Password type => MediumName<br> PasswordSalt type => MediumName<br> DefaultLanguageID references => oxite_Language<br> Status type => Byte, nullable => false <br> <br> oxite_UserLanguage:<br> UserID references => oxite_User<br> LanguageID references => oxite_Language<br><br> index "" columns => [UserID, LanguageID], unique => true , clustered => true <br> <br> * This source code was highlighted with Source Code Highlighter .


Wizardby will do it all the same by itself:


Project


The project page (licensed under the MIT License) is here . The source code is available either as a zip archive or in the SVN repository . In addition, there is a ZIP archive with an already compiled version . The documentation (in English) is here . And here you can see how Wizardby is used in “real life”.

Source: https://habr.com/ru/post/56175/


All Articles