. Net migration tool

Source: Internet
Author: User

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/

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.