Skip to content

Setup & Integration

Weasel provides database CLI commands through the JasperFx command line framework. These commands let you apply migrations, validate schema state, generate patch files, and dump DDL from the command line.

Enabling the CLI

To enable the Weasel CLI commands, make two changes to your Program.cs:

cs
var builder = WebApplication.CreateBuilder(args);

// 1. Add this call to enable JasperFx extensions
builder.Host.ApplyJasperFxExtensions();

// ... configure services as usual ...

var app = builder.Build();

// 2. Replace app.Run() with this:
return await app.RunJasperFxCommands(args);

snippet source | anchor

RunJasperFxCommands(args) will intercept any recognized CLI commands and run them instead of starting the web host. If no CLI command is detected, the application starts normally.

Available Commands

Run dotnet run -- help to see all available commands:

CommandDescription
db-applyApplies all outstanding changes to the database(s)
db-assertAsserts that the existing database(s) match the current configuration
db-patchExports a SQL patch and rollback file for pending changes
db-dumpDumps the entire DDL for the configured database(s)
db-listLists all configured databases

Common Flags

All database commands support the following flags:

FlagDescription
--database / -dFilter to a specific database by partial URI match
--conn / -cOverride the connection string
--logRecord command output to a file
--verboseEnable verbose output
--log-levelOverride the log level
--environmentOverride the hosting environment name

Database Discovery

Weasel discovers databases through dependency injection. Register your databases as IDatabase or IDatabaseSource implementations in the DI container, and the CLI commands will find them automatically.

Integration Testing

If you need the host to start automatically during integration testing (without CLI arguments), set:

cs
JasperFxEnvironment.AutoStartHost = true;

snippet source | anchor

This bypasses the CLI argument check and starts the host directly.

Released under the MIT License.