Skip to content

main · v3.2 (unreleased)

The command-line tool

Users · Reference · CurrentMarkdownAgent index

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:

Terminal window
dotnet run --project sample/Database/Commands -- <command> [options]
Usage: Commands [command] [options]
OptionMeaning
-tThe command timeout of the database, in seconds. It precedes the command: -t 300 upgrade.
-?, -h, --helpShow 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.

The tool reads the file custom/appsettings.json below the configuration root, and environment variables, which override the file.

SettingMeaning
adapterRequired: snapshot, sqlclient or npgsql.
ConnectionStrings:DefaultConnectionRequired with sqlclient and npgsql.
populationFileThe 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.

CommandFromWhat it doesOption
initThe applicationDrops 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.
populateThe applicationEmpties the database with Init() and runs the setup, which builds a new population.
userThe applicationCreates 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.
saveCoreWrites the population to a file.-f the file
loadCoreReplaces the population with the one in a file.-f the file
upgradeThe applicationLoads a population that an earlier version saved and brings it up to date; Upgrade a population describes its steps.-f the file
indexCoreOn 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.

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.

Terminal window
dotnet run --project sample/Database/Commands -- user --name worker@example.com --group Workers

Supply 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.

The tool logs to the console, from the level Info up, one line per message:

13:19:57 INFO Begin
13:19:57 INFO Saving /home/user/allors3/population.xml
13:19:57 INFO End
Exit codeMeaning
0The command succeeded.
1The 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.

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.

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 for Configuration and Database.
  • ExitCode, with Success and Error, which Core’s commands return.
  • populate, user and upgrade, which depend on the application’s setup and model, and init, which Core keeps in its folder Custom; the sample’s is a copy of it.
  • nlog.config, which the build copies next to the tool.
  • The sample’s tool is in sample/Database/Commands: Program.cs, ExitCode.cs, nlog.config and the commands in Custom. Its tests are in sample/Database/Commands.Tests.
  • Core’s commands are in dotnet/Core/Database/Commands/Core. DatabaseBuilder and DatabaseProvisioning, which build the database and serve init, are in dotnet/System/Database/Adapters/Allors.Database.Builder.