-
Notifications
You must be signed in to change notification settings - Fork 1
Dealing with Multiple Database Types
FluentMigrator allows you to target multiple database types from the same migration project. Every FluentMigrator project is database agnostic and can be run against any of the supported database types.
However, there are times when only some migrations in a project need to be executed against one of the database types. For supporting that scenario FluentMigrator includes the IfDatabaseType expression.
Suppose you have a migration that executes a script file to create a view:
public class CreateViewsMigration : Migration
{
public override void Up()
{
Execute.Script("CreateViewsMigrationUp.sql");
}
public override void Down()
{
Execute.Script("CreateViewsMigrationDown.sql");
}
}
However the project needs to create some views in an SqlServer database and others in an Oracle database, but you want both tasks to be part of the same migration, sharing the same migration number in both databases. You handle this by creating scripts for each database and specifying which one needs to be executed:
public class CreateViewsMigration : Migration
{
public override void Up()
{
IfDatabaseType("oracle").Execute.Script("CreateViewsOracleMigrationUp.sql");
IfDatabaseType("sqlserver").Execute.Script("CreateViewsSqlServerMigrationUp.sql");
}
public override void Down()
{
IfDatabaseType("oracle").Execute.Script("CreateViewsOracleMigrationDown.sql");
IfDatabaseType("sqlserver").Execute.Script("CreateViewsSqlServerMigrationDown.sql");
}
}
The current database types supported are:
- SqlServer (this includes Sql Server 2005 and Sql Server 2008)
- SqlServer2000
- SqlServerCe
- Postgres
- MySql
- Oracle
- Jet
- Sqlite
- Getting FluentMigrator
- How to create a Migration
- Fluent Interface
- Migration Runners
- Use inbuilt database functions when setting the default value
- Sql Server Specific Extensions
- Raw Sql Helper for inserting data
- Auto Reversing Migrations
- Resharper File Template
- Transaction Modes for the Migration Runner
- ApplicationContext: Passing parameters to Migrations
- Dealing with Multiple Database Types
- Filter migrations run based on Tags
- Enforce migration version numbering rules
- Create custom metadata for the VersionInfo table