Skip to content
Mike Schenk edited this page May 6, 2017 · 5 revisions

Basics

The Migrator object needs three things:

  1. A deployment journal

    This object keeps track of the migrations that have been deployed to the target data store

  2. A migrations provider

    This object provides the lists of migrations and stored code definitions that are included in the current version of the system being deployed

  3. A progress reporter

    This object accepts progress messages and start/end block calls and formats and provides them to the user via some user interface. ConsoleProgressReporter and TeamCityProgressReporter are avaialble in the base package.

The Migrator object is used to

  • EnsureJournal
  • EnsureBaseline
  • Plan a deployment
  • DeployOffline
  • DeployOnline

Simple Deployment

Create an executable or include code such as the following in some part of your application that can run during installation or deployment:

    // create an appropriate progressReporter
    var progressReporter = new ConsoleProgressReporter();

    // create SQL connection info
    var connectionInfo = new ConnectionProperties(DatabaseServer, DatabaseName, useWindowsIntegratedSecurity: true);

    // create our deployment journal and have it open its connection
    journal = new SingleTableJournal(connectionInfo, progressReporter);
    journal.Open();

    // create our script runner and have it open its connection
    runner = new ScriptRunner(connectionInfo);
    runner.Open();

    var scriptMigrationsProvider = new FileSystemScriptsMigrationProvider(
        Path.Combine(SqlScriptsPath, "scripts"), "*.sql",
        Path.Combine(SqlScriptsPath, "objects"), "*.sql",
        runner
    );

    migrator = new Migrator(journal, scriptMigrationsProvider, progressReporter, includeOnlineMigrationsDuringOffline: true);

    migrator.DeployOffline();

Check for Changes before deploying

Deploy Offline followed by Online Migrations

Prepare a new database for deployments

Baseline an existing database