Do-It-Yourself CommandLine Interface for DbUp
dbup is a great library but requires some repeatable setup in code:
- Where are the scripts do run?
- Where is the destination database?
- How do I drop and recreate the database?
- Can I optionally run some seed data for developers/deployment?
-
Create a Console project (like
ConsoleApplication1
) -
Install-Package dbup-diy-cli
-
Add your SQL files as embedded resources
-
(optional) install db-specific package like
dbup-mysql
,dbup-sqlite
, and change the etc -
Modify your
Main
and pass the appropriate method toRun
:public static int Main(string[] args) { return new DbUp.Cli.Upgrader(args).Run(MySqlExtensions.MySqlDatabase); }
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.
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.
This way it's easier to use with database engines other that MS SQL, by installing dbup-X
package together with
dbup-diy-cli
.