Migrator and Migrations
This project provides a library with the migrations based on Fluent Migrator and an executable to start the migrations.
The library (Migrations) can also be migrated by the official Fluent Migrator runner.
Our custom executable (Coscine.Migrator.exe) also allows for the creation of the needed database.
Start a migration by calling Coscine.Migrator.exe --migrate_up
.
This will create the needed database and run all migrations.
You can run the command again at a later time, to install additional migrations.
Migrations already deployed will not be deployed again.
You can revert a migration by calling Coscine.Migrator.exe --roll_back 1
.
This will remove the most recent migration.
Replacing the 1 with a 2 will revert the two most recent migrations and so on.
The executable will create a connection string based on the Consul values:
- DbDataSourceKey:
coscine/global/db_data_source
- DbNameKey:
coscine/global/db_name
- DbUserIdKey:
coscine/global/db_user_id
- DbPasswordKey:
coscine/global/db_password
You can call the migrations from a diffrent project.
The connection string information from Consul (except db_name
) will be used.
Use the CoscineMigrations
class for this:
// Setup the migrator class
var targetAssembly = typeof(CoscineMigrations).Assembly;
var migrator = new CoscineMigrations();
var dbDatabase = "YOUR_DATABASE_NAME_HERE";
migrator.SetServiceProvider(targetAssembly, migrator.GetDatabaseConnectionStringFromConsul(dbDatabase));
// Create the database if needed
migrator.EnsureDatabase(dbDatabase);
// Run the migrations on the database
migrator.MigrateUp();