Status: Current. Where this is implemented names the code.
An application has a command-line tool that creates, fills, saves, loads and upgrades its
database. This page describes the tool of the sample application,
sample/Database/Commands, which takes three of its commands from Core. Run it from the root of
the platform’s repository, after ./build.sh SampleGenerate:
dotnet run --project sample/Database/Commands -- <command> [options]Usage: Commands [command] [options]| Option | Meaning |
|---|---|
-t | The command timeout of the database, in seconds. It precedes the command: -t 300 upgrade. |
-?, -h, --help | Show the help of the tool, or of the command that precedes it. |
Without a command the tool shows its help and exits with code 1.
Settings
Section titled “Settings”The tool reads the file custom/appsettings.json below the
configuration root, and environment variables, which
override the file.
| Setting | Meaning |
|---|---|
adapter | Required: snapshot, sqlclient or npgsql. |
ConnectionStrings:DefaultConnection | Required with sqlclient and npgsql. |
populationFile | The file of save, load and upgrade when the option -f is absent. Without the setting the file is population.xml. |
A command stops with exit code 1 without a configuration root, and when a required setting has
no value. Without ALLORS_CONFIG_ROOT the message is:
ALLORS_CONFIG_ROOT is not set. Set it to the folder that holds 'custom/appsettings.json'.init also uses the admin connection of the server;
Admin connections describes it.
Commands
Section titled “Commands”| Command | From | What it does | Option |
|---|---|---|---|
init | The application | Drops and creates the database of the connection string, through the admin connection; Admin connections says what it does with the login of the connection string. With the Snapshot adapter it logs that there is nothing to drop or create. | |
populate | The application | Empties the database with Init() and runs the setup, which builds a new population. | |
user | The application | Creates a person who can sign in and adds that person to a user group. | --name (-n), either --group (-g) or --group-id, and optionally --password-stdin. |
save | Core | Writes the population to a file. | -f the file |
load | Core | Replaces the population with the one in a file. | -f the file |
upgrade | The application | Loads a population that an earlier version saved and brings it up to date; Upgrade a population describes its steps. | -f the file |
index | Core | On SQL Server and PostgreSQL, creates missing indexes and tries to drop obsolete indexes of the adapter. If a drop fails, the index can remain after a successful run. Run index at deployment when the model’s indexes change and the population is to be kept. A database object checks for missing indexes before its first transaction. The SQL adapters also maintain the indexes during Init() and after a load. On the Snapshot adapter the command logs that there are no indexes to maintain. See Indexes. |
A relative file name is relative to the working directory, and the tool logs the full path of the file that it saves or loads.
Create a user
Section titled “Create a user”After populating the database, run the command and enter the password at the masked prompt. Core’s password rule requires at least 12 characters with at least four distinct characters.
dotnet run --project sample/Database/Commands -- user --name worker@example.com --group WorkersSupply exactly one group selector. If several groups have the same name, the error lists their
UniqueId values. Repeat the command with --group-id <UniqueId>. An existing user name
(including a case variant), an invalid group selection or a rejected password leaves the
population unchanged.
For automation, pipe the password into the command and add --password-stdin. It reads one
line, preserving leading and trailing spaces. To sign in as the new user, follow
Run the server and sign in on Windows, or
Host a server from bash.
Output and exit codes
Section titled “Output and exit codes”The tool logs to the console, from the level Info up, one line per message:
13:19:57 INFO Begin13:19:57 INFO Saving /home/user/allors3/population.xml13:19:57 INFO End| Exit code | Meaning |
|---|---|
| 0 | The command succeeded. |
| 1 | The command failed, its arguments were not recognized, or no command was given. The tool logs the message at the level Error, except when no command was given: then it shows its help. |
Adapters
Section titled “Adapters”The database adapters compares the adapters. On the Snapshot adapter the
population ends with the process, so each run starts with an empty database: save then writes a
population without objects, and load or upgrade holds the loaded population only until the run
ends. A sequence of commands, such as populate followed by save, needs SQL Server or
PostgreSQL. The tests of the sample call the commands in one process instead, on the Snapshot
adapter.
What an application writes
Section titled “What an application writes”Core provides save, load and index, in dotnet/Core/Database/Commands/Core; the project of
the tool includes them with a glob, as the projects of an application
include Core. The application writes the rest:
Program, which lists the commands with[Subcommand], reads the configuration of the application’s domain,AddAllorsConfiguration("custom")in the sample, and builds the database with the application’s rules. Core’s commands ask it forConfigurationandDatabase.ExitCode, withSuccessandError, which Core’s commands return.populate,userandupgrade, which depend on the application’s setup and model, andinit, which Core keeps in its folderCustom; the sample’s is a copy of it.nlog.config, which the build copies next to the tool.
Where this is implemented
Section titled “Where this is implemented”- The sample’s tool is in
sample/Database/Commands:Program.cs,ExitCode.cs,nlog.configand the commands inCustom. Its tests are insample/Database/Commands.Tests. - Core’s commands are in
dotnet/Core/Database/Commands/Core.DatabaseBuilderandDatabaseProvisioning, which build the database and serveinit, are indotnet/System/Database/Adapters/Allors.Database.Builder.