Skip to content

tpluscode/dbup-diy-cli

Repository files navigation

DbUp-DIY-CLI Build status NuGet version

Do-It-Yourself CommandLine Interface for DbUp

Introduction

dbup is a great library but requires some repeatable setup in code:

  1. Where are the scripts do run?
  2. Where is the destination database?
  3. How do I drop and recreate the database?
  4. Can I optionally run some seed data for developers/deployment?

Usage

Setup

  1. Create a Console project (like ConsoleApplication1)

  2. Install-Package dbup-diy-cli

  3. Add your SQL files as embedded resources

  4. (optional) install db-specific package like dbup-mysql, dbup-sqlite, and change the etc

  5. Modify your Main and pass the appropriate method to Run:

    public static int Main(string[] args)
    {
        return new DbUp.Cli.Upgrader(args).Run(MySqlExtensions.MySqlDatabase);
    }

Running

To upgrade a local instance (uses Windows auth) run ConsoleApplication1.exe local

-d, --database            Required. Database to upgrade

-s, --server              Required. Server name/address

--dev-seeds               Seed database with sample data

-r, --recreate            Completely recreate all database objects

-m, --mark-as-executed    Don't run ever run current migration scripts

--dev-seed-pattern        (Default: _dev_) Regular expression to match and
                          select developer seed script (case-insensitive)

--run-always-pattern      (Default: sp_) Regular expression to match and
                          scripts executed every time, such as stored
                          procedures and functions (case-insensitive)
                          
-t, --timeout             Timeout for each script in seconds                          

--help                    Display this help screen.

--version                 Display version information.

To upgrade an arbitrary server, use ConsoleApplication1.exe remote, with which you can provide a complete connectionstring (-c switch) or a name to find in app.config (-n switch)

-c, --connection-string         connection string

-n, --connection-string-name    connection string name

--dev-seeds                     Seed database with sample data

-r, --recreate                  Completely recreate all database objects

-m, --mark-as-executed          Don't run ever run current migration scripts

--dev-seed-pattern              (Default: _dev_) Regular expression to match
                                and select developer seed script (case-insensitive)

--run-always-pattern            (Default: sp_) Regular expression to match
                                and scripts executed every time, such as
                                stored procedures and functions (case-insensitive)
                                
-t, --timeout                   Timeout for each script in seconds                                

--help                          Display this help screen.

--version                       Display version information.

Running Entity Framework code

Install dbup-diy-cli.EntityFramework package from NuGet and implement EntityFrameworkScript<T> or EntityFrameworkUpdate<T>.

The former can be used to return a script dynamically based on some EF query. The latter is intended to be used to perform updates with Entity Framework.

Why not a ready-built CLI?

This way it's easier to use with database engines other that MS SQL, by installing dbup-X package together with dbup-diy-cli.