README.md 1.58 KB
Newer Older
1
## Migrator and Migrations
RWTH App's avatar
RWTH App committed
2

3
This project provides a library with the migrations based on Fluent Migrator and an executable to start the migrations.
RWTH App's avatar
RWTH App committed
4

5
The library (Migrations) can also be migrated by the official Fluent Migrator runner.
RWTH App's avatar
RWTH App committed
6

7
Our custom executable (Migrator.exe) also allows for the creation of the needed database.
RWTH App's avatar
RWTH App committed
8

9
10
11
12
Start a migration by calling `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.
RWTH App's avatar
RWTH App committed
13

14
15
16
You can revert a migration by calling `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.
RWTH App's avatar
RWTH App committed
17

18
19
20
21
22
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`
RWTH App's avatar
RWTH App committed
23
24


25
26
27
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:
RWTH App's avatar
RWTH App committed
28

29
30
31
32
33
34
```C#
// 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));
RWTH App's avatar
RWTH App committed
35

36
37
38
39
40
// Create the database if needed
migrator.EnsureDatabase(dbDatabase);
// Run the migrations on the database
migrator.MigrateUp();
```