General Usage Guide
DotNetMigrations is a command line utility for tracking and migrating database versions. In order to use it's compiled binaries, please follow the the steps below:
- Download the binaries from the Downloads section of this project.
- Unzip the files into a directory.
- Update the db.exe.config file
- Update the appSettings - migrateFolder value if you wish for migration scripts to be saved in a different location.
- Update the appSettings - PlugInDirectory value if you wish to store custom plug-ins that extend DotNetMigrations in a different location.
- Update the connectionString section with the migration name you wish to use as the key.
- Update the dnm.logs section if you are using additional log classes than the default.
- Open a command window and navigate to the directory that contains db.exe.
- Generate a new Migration Script (see examples below)
- Open the created file and write the setup and teardown sql scripts that'll be used when the database migrates to the version.
- Migrate the database.
Command Syntax
db.exe <command name> <migration name> <command arguments> "{[connection string]"}
- In the above statement...
- ...<command name> represents the name of the command you wish to run.
- ...<migration name> represents the name of the migration - should be the same name as your connection string key in the configuration file.
- ...<command arguments> represents any additional arguments required by the command (i.e. a specific version number to migrate to).
- ...[connection string] represents an optional argument where you can directly enter the connection string instead of referring to the one found in the configuration file.
Examples:
In the below examples, we'll assume we have named our migrations as TestDb.
Generating a new Generation Script
db.exe generate TestDb
Migrate to the Latest Script Version
db.exe migrate TestDb
Migrate to the original version
db.exe migrate TestDb 0
Migrate to a specific version
db.exe migrate TestDb 201001291432
Examine what the current version of database and script
db.exe version TestDb
Rllback one database version
db.exe rollback TestDb