Skip to content

Database migrations for .NET. Based on the idea of Rails ActiveRecord Migrations. This fork aims to improve support for having a single set of migrations applied to 4/5 DB vendors simultaneously (Including addressing issues around data types like Guids, and lots of little tweaks to deal with things like reserved word differences between database…

Notifications You must be signed in to change notification settings

dotnetprojects/Migrator.NET

 
 

Repository files navigation

Info

This Project includes most of the changes from all forks on GitHub!

But has also a few changes:

  • SQLite support is better (Schema Reading, multiple Primary Keys, and much more)
  • Remove direct References to the Dataproviders
  • Dump Indexes from SQLServer
  • Different Migration Scopes in one Database

NuGet

https://www.nuget.org/packages/DotNetProjects.Migrator/

Introduction

This project is a fork of "ye olde trusty" Migrator.Net - the original project can be found here on google code, and has since moved to github

Usage Example

M_001_InitialSchema.cs

[Migration(1)]
public class M_001_InitialSchema : Migration
{
	public override void Up()
	{
		Database.AddTable(
			"Users",
			new Column("Id", DbType.Guid, ColumnProperty.NotNull | ColumnProperty.PrimaryKey),
			new Column("CreationDate", DbType.DateTime, ColumnProperty.NotNull),
			new Column("ModificationDate", DbType.DateTime, ColumnProperty.NotNull),
			new Column("Name", DbType.String, 255),
			new Column("Password", DbType.String, 255),
			new Column("ExplicitRoles", DbType.String, int.MaxValue));
	}

	public override void Down()
	{
	}
}

Code to Apply Migration:

using (var p = ProviderFactory.Create(ProviderTypes.SQLite, connection, null))
{
	var migrator = new Migrator(p, typeof(M_001_InitialSchema).Assembly, false));

	if (migrator.LastAppliedMigrationVersion != null && migrator.LastAppliedMigrationVersion.Value > migrator.AssemblyLastMigrationVersion)
	{
		throw new Exception("Database has newer Migrations applied then the Software supports");
	}
	else
	{
		migrator.MigrateToLastVersion();
	}
}

What's different in the fork

In this fork the main changes are:

  • Now targets .Net Framework 4.0 instead of 2.0/3.5.
  • NetStandart 2.0 will be supported when released
  • Support for reserved words.
  • Support for guid types across all databases.
  • Utility classes for removing all tables etc. from a database (to support migration integration tests).
  • Warnings in Oracle when attempting to create column/table/key names that are over-length.
  • Removed reliance on deprecated SqlServer views such as Sysconstraints (to support Azure Sql Server deployment).

About

Database migrations for .NET. Based on the idea of Rails ActiveRecord Migrations. This fork aims to improve support for having a single set of migrations applied to 4/5 DB vendors simultaneously (Including addressing issues around data types like Guids, and lots of little tweaks to deal with things like reserved word differences between database…

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 69.2%
  • HTML 15.3%
  • Rich Text Format 10.4%
  • XSLT 4.9%
  • Other 0.2%