Migration is a Database Synchronization tool in a distributed environment. It appears in the Ruby on rail framework. migratordotnet is A. NET database version system similar to migrations of Ruby on rail. Supported databases include MySQL (5.0, 5.1), PostgreSQL, SQLite, SQL Server (2000,200 5), and Oracle (not well tested). You can use nanttask, msbuildtarget, console Application can be used in three ways.
The migrations class is a subclass of migration. The migration mainly has two methods: The up method defines what to do in this version, and the down method defines how to roll back the version.
Each migration should be a very small incremental modification in the database. The common dimension is to create a table and add one or more fields to the table, modify Table data and execute an executequery custom query on the table. Keep migration as small as possible to facilitate migration between versions, just like SVN and TFs in the version control system. The migration example is as follows:
// Version 1
[Migration (1)]
Public class createusertable: Migration
{
Public void up ()
{
Database. createtable ("user ",
New column ("userid", dbtype. int32, columnproperties. primarykeywithidentity ),
New column ("username", dbtype. ansistring, 25)
);
}
Public void down ()
{
Database. removetable ("user ");
}
}
The migration attribute uses an integer to represent the current database version. The tool determines the migration between databases through this attribute. If you use the ConsoleProgramThe version number is passed as a parameter to the console program. You can also use the Nant script or msbuild script.
The following is an Nant compilation script:
<? XML version = "1.0"?>
<Project default = "migrate">
<Property name = "project. dir" value = "."/>
<Property name = "output. dir" value = "$ {project. dir} \ output"/>
<Loadtasks Assembly = "$ {project. dir} \ Lib \ migrator. Nant. dll"/>
<Target name = "clean" Description = "deletes the previusly built directories">
<Delete dir = "$ {output. dir}" failonerror = "false"/>
</Target>
<Target name = "build" Description = "builds migration project" depends = "clean">
<Msbuild project = "$ {project. dir} \ SRC \ migrations. Project \ migrations. Project. csproj">
<Property name = "configuration" value = "debug"/>
<Property name = "outdir" value = "$ {output. dir} \"/>
</Msbuild>
</Target>
<! -- Database migrations task -->
<Target name = "migrate" Description = "migrate the Database" depends = "build">
<! -- Using a version of-1 will cause the migration to migrate to the latest version -->
<Property name = "version" value = "-1" Overwrite = "false"/>
<Migrate
Provider = "MySQL"
Connectionstring = "database = mydb; Data Source = localhost; user id = mysqluser; Password = mysqlpassword ;"
Migrations = "$ {output. dir} \ migrations. Project. dll"
To = "$ {version}"/>
</Target>
</Project>
For details about how to write migrate, see writingmigrations. In addition, the migrate function is also added to subsonic 2.1 RC1. For more information, see subsonic: Using migrations.
Database migration references:
Http://api.rubyonrails.com/classes/ActiveRecord/Migration.html
Http://wiki.rubyonrails.org/rails/pages/UnderstandingMigrations
Http://wiki.rubyonrails.org/rails/pages/UsingMigrations
Getting started with migrator. net
Http://www.lostechies.com/blogs/sean_chambers/archive/2008/06/04/getting-started-with-migrator-net-and-database-refactorings.aspx
(Outdated) http://macournoyer.wordpress.com/2006/09/20/database-migration-for-net
Where did migrator. Net come from
Http://macournoyer.wordpress.com/2007/09/18/the-migrations-for-net-project-is-not-dead-yet
Migrator. Net good practices
Http://macournoyer.wordpress.com/2007/02/11/agile-database-fun-with-the-migrator
Migrate Nant task
Http://macournoyer.wordpress.com/2006/10/15/migrate-nant-task
Database migrations for. net
Http://www.zorched.net/2008/04/20/database-migrations-for-net/