Skip to content

The CLI

dbtest exposes the harness operations that are useful outside a test run: start a container with a schema applied, and inspect the result.

Terminal window
dotnet tool install --global DbTest.Cli

The CLI rolls forward, so it runs on whichever of .NET 8 or newer is installed. It needs Docker running, like the library.

Terminal window
dbtest engines # list the registered engines
dbtest up --engine postgres --schema Schema/postgres # start, apply, keep running until Ctrl+C
dbtest schema --engine mysql --schema Schema/mysql # apply a schema and list what it created

Lists the registered engines: mssql, postgres and mysql.

Starts a container, applies the schema, prints the connection string, and keeps the container running until you press Ctrl+C. A container that disappeared as soon as its connection string was printed would be of no use.

--engine is required. --schema is optional: without it no schema is applied.

Ctrl+C stops the command and removes the container. The exit code is 0.

Loads the schema directory, prints the scripts that will be applied and any excluded files, then starts a container, applies the schema, lists the objects it created, and removes the container.

Both --engine and --schema are required.

Example output shape:

2 script(s) will be applied:
001_tables.sql
002_procedures.sql
2 object(s) created:
Table public.customers (3 column(s))
...
Option Meaning
--engine <name> mssql, postgres or mysql.
--schema <dir> Directory holding the schema files.
--image <image> Override the container image.
--database <name> Database name inside the container. Default: dbtest.
--username <name> Login inside the container. Default: the engine’s own.
--password <pass> Password inside the container. Default: the engine’s own.

-h and --help print the usage text.

Every option takes a value. Parsing is strict: an unknown option such as --shema, or an option missing its value, is an error instead of being silently ignored.

Code Meaning
0 Success. This includes Ctrl+C on a running dbtest up, once its container is up.
1 A failure such as Docker not running, a broken schema or a bad image. Reported as one error: line, not a stack trace. dbtest with no arguments also exits 1: it prints the usage text to standard error, with no error: line.
2 Usage error: unknown command or option, a missing value or a missing required option. The usage text follows the message.
130 Cancelled with Ctrl+C before the command finished: while dbtest up is still starting the container or applying the schema, or while dbtest schema runs. The message is Cancelled..