.. _production_database: ******************* Production Database ******************* **Last Updated:** May 2020 In this part of the production deployment guide, you will learn how to initialize and configure the Tethys Portal database for production. 1. Set Database Settings ======================== Set the database settings in the :file:`portal_config.yml` using the ``tethys settings`` command: .. code-block:: bash tethys settings --set DATABASES.default.NAME tethys_platform --set DATABASES.default.USER --set DATABASES.default.PASSWORD --set DATABASES.default.HOST --set DATABASES.default.PORT .. note:: Replace ```` and ```` with the values you determined during the :ref:`production_preparation` step. Replace ```` and ```` with the host and port of your database. If you installed the database on the same server as your Tethys Portal, these would be ``localhost`` and ``5432``, respectively. .. important:: **DO NOT USE DEFAULT USERNAMES OR PASSWORDS FOR PRODUCTION DATABASE ACCOUNTS** 2. Create Tethys Database and Database Users ============================================ Use the ``tethys db create`` command to create the database users and tables required by Tethys Portal: .. code-block:: bash PGPASSWORD= tethys db create --username --password --superuser-name --superuser-password .. note:: Replace ````, ````, ````, ````, and ```` with the values you determined during the :ref:`production_preparation` step. The ``tethys db create`` command uses the :file:`portal_config.yml` to get the normal database user credentials, host, and port. .. important:: **DO NOT USE DEFAULT USERNAMES OR PASSWORDS FOR PRODUCTION DATABASE ACCOUNTS** 3. Create Tethys Database Tables ================================ Run the following command to create the Tethys database tables: .. code-block:: bash tethys db migrate 4. Create Portal Admin User =========================== You will need to create at least one Portal Admin account to allow you to login to your Tethys Portal. Create the account as follows: .. code-block:: bash tethys db createsuperuser --portal-superuser-name --portal-superuser-email '' --portal-superuser-pass .. note:: Replace ````, ````, and ```` with the values you determined during the :ref:`production_preparation` step. .. important:: **DO NOT USE DEFAULT USERNAMES OR PASSWORDS FOR PRODUCTION PORTAL ADMIN ACCOUNTS** Tip: One Command ================ You can accomplish the three steps above using the ``tethys db configure`` command. It is equivalent of running the following commands: * ``tethys db init`` (skipped if using a Docker or system database) * ``tethys db start`` (skipped if using a Docker or system database) * ``tethys db create --username --password --superuser-name --superuser-password `` * ``tethys db migrate`` * ``tethys db createsuperuser --portal-superuser-name --portal-superuser-email '' --portal-superuser-pass `` Simply pass all arguments to the command: .. code-block:: bash tethys db configure --username --password --superuser-name --superuser-password --portal-superuser-name --portal-superuser-email '' --portal-superuser-pass