db command

Setup and manage a Tethys database.

Important

The default database configuration uses SQLite. Many of these commands are not applicable to SQLite databases and only support PostgreSQL databases. To use a PostgreSQL database be sure to set your settings accordingly. At the very least:

bash
tethys settings --set DATABASES.default.ENGINE django.db.backends.postgresql

For more details see database_configuration

Additionally, the PostgreSQL database and the psycopg2 library must be installed. Starting with Tethys 5.0 or if you are using micro-tethys-platform, you will need to install postgresql and psycopg2 using conda as follows:

bash
# conda: conda-forge channel strongly recommended
conda install -c conda-forge postgresql psycopg2
python
usage: tethys db [-h] [-d DB_ALIAS] [-n USERNAME] [-p PASSWORD]
                 [-N SUPERUSER_NAME] [-P SUPERUSER_PASSWORD]
                 [--portal-superuser-name PORTAL_SUPERUSER_NAME]
                 [--portal-superuser-email PORTAL_SUPERUSER_EMAIL]
                 [--portal-superuser-password PORTAL_SUPERUSER_PASSWORD] [-y]
                 {init,start,stop,status,create,migrate,createsuperuser,configure,sync,purge}

Positional Arguments

command

Possible choices: init, start, stop, status, create, migrate, createsuperuser, configure, sync, purge

Performs operations on the Tethys Database.
  • init - Creates a new, locally running PostgreSQL database server.

  • start - Starts a local PostgreSQL database server.

  • stop - Stops a local PostgreSQL database server.

  • status - Gets the current status of a local PostgreSQL database server.

  • create - Creates the Tethys Portal database on a PostgreSQL database server configured in the portal-config.yml (this could be local or remote).

  • migrate - Runs migrations on the Tethys Portal database.

  • createsuperuser - Creates a Tethys Portal superuser account.

  • configure - A shortcut for running: init, start, create, migrate, and createsuperuser (for PostgreSQL and SQLite databases).

    Note: if the DIR parameter is not defined in your DATABASES.default configuration in portal_config.yml then the init and start commands are skipped. If the database ENGINE is configured to use SQLite then only the migrate and createsuperuser commands are run.

  • sync - Syncs the Tethys Portal database with installed apps and extensions.

  • purge - Stops database server and removes the database file (SQLite) or the database cluster directory (locally running PostgreSQL).

Named Arguments

-d, --database

Name of the database options from portal_config.yml to use (e.g. 'default').

Default: "default"

-n, --username

Name of database user to add to database when creating.

Default: "tethys_default"

-p, --password

Password for the database user.

Default: "pass"

-N, --superuser-name

Name of database super user to add to database when creating.

Default: "tethys_super"

-P, --superuser-password

Password for the database super user.

Default: "pass"

--portal-superuser-name, --pn

Name for the Tethys portal super user.

Default: "admin"

--portal-superuser-email, --email, --pe

Email of the Tethys portal super user.

Default: ""

--portal-superuser-password, --pp

Password for the Tethys portal super user.

Default: "pass"

-y, --yes

Do not ask for confirmation. Applies only to the configure and the purge commands.

Default: False