.. 4.0 International License.
.. http://creativecommons.org/licenses/by/4.0
+.. _policy-db-migrator-label:
+
Using Policy DB Migrator
########################
prepare_upgrade.sh
prepare_downgrade.sh
db-migrator
+ db-migrator-pg
``prepare_upgrade.sh`` is included as part of the docker image and is used
to copy the downgrade sql files to the run directory.
This script takes one parameter: <SCHEMA NAME>.
-``db-migrator`` is included as part of the docker image and is used
-to run either the upgrade or downgrade operation depending on user requirements.
-This script can take up to four parameters:
+``db-migrator`` and ``db-migrator-pg`` are included as part of the docker image
+and are used to run either the upgrade or downgrade operation for MariaDB or
+PostgresSQL depending on user requirements.
+These script can take up to four parameters:
.. list-table::
:widths: 20 20 20
- policy_user
* - POLICY_HOME
- /opt/app/policy
+ * - SCRIPT_DIRECTORY
+ - sql
+
+The following environment variables need to be set to enable ``db-migrator-pg``
+to run and connect to the database.
+
+.. list-table::
+ :widths: 20 20
+ :header-rows: 1
+
+ * - Name
+ - Value (example)
+ * - SQL_HOST
+ - postgres
+ * - SQL_DB
+ - policyadmin
+ * - SQL_USER
+ - policy_user
+ * - SQL_PASSWORD
+ - policy_user
+ * - POLICY_HOME
+ - /opt/app/policy
+ * - SCRIPT_DIRECTORY
+ - postgres
+ * - PGPASSWORD
+ - ${SQL_PASSWORD}
Prepare Upgrade
===============
/opt/app/policy/bin/prepare_upgrade.sh <SCHEMA NAME>
-This will copy the upgrade files from ``/home/policy/sql`` to ``$POLICY_HOME/etc/db/migration/<SCHEMA NAME>/sql/``
+This will copy the upgrade files from ``/home/policy/${SCRIPT_DIRECTORY}`` to ``$POLICY_HOME/etc/db/migration/<SCHEMA NAME>/${SCRIPT_DIRECTORY}/``
Each individual sql file that makes up that release will be run as part of the upgrade.
/opt/app/policy/bin/prepare_downgrade.sh <SCHEMA NAME>
-This will copy the downgrade files from ``/home/policy/sql`` to ``$POLICY_HOME/etc/db/migration/<SCHEMA NAME>/sql/``
+This will copy the downgrade files from ``/home/policy/${SCRIPT_DIRECTORY}`` to ``$POLICY_HOME/etc/db/migration/<SCHEMA NAME>/${SCRIPT_DIRECTORY}/``
Each individual sql file that makes up that release will be run as part of the downgrade.
/opt/app/policy/bin/db-migrator -s <SCHEMA NAME> -o upgrade -f 0800 -t 0900
+OR
+
+.. code::
+
+ /opt/app/policy/bin/db-migrator-pg -s <SCHEMA NAME> -o upgrade -f 0800 -t 0900
+
If the ``-f`` and ``-t`` flags are not specified, the script will attempt to run all available
sql files greater than the current version.
/opt/app/policy/bin/db-migrator -s <SCHEMA NAME> -o downgrade -f 0900 -t 0800
+OR
+
+.. code::
+
+ /opt/app/policy/bin/db-migrator-pg -s <SCHEMA NAME> -o downgrade -f 0900 -t 0800
+
If the ``-f`` and ``-t`` flags are not specified, the script will attempt to run all available
sql files less than the current version.
Logging
=======
-After every upgrade/downgrade ``db-migrator`` runs the report operation to show the
-contents of the db-migrator log table.
+After every upgrade/downgrade ``db-migrator`` or ``db-migrator-pg`` runs the report operation
+to show the contents of the db-migrator log table.
.. code::
/opt/app/policy/bin/db-migrator -s <SCHEMA NAME> -o report
+.. code::
+
+ /opt/app/policy/bin/db-migrator-pg -s <SCHEMA NAME> -o report
+
Console output will also show the sql script command as in the example below:
.. code::
/opt/app/policy/bin/db-migrator -s ${SQL_DB} -o report
exit $rc
+.. code::
+
+ /opt/app/policy/bin/prepare_upgrade.sh ${SQL_DB}
+ /opt/app/policy/bin/db-migrator-pg -s ${SQL_DB} -o upgrade
+ rc=$?
+ /opt/app/policy/bin/db-migrator-pg -s ${SQL_DB} -o report
+ exit $rc
+
The following table describes what each line does:
.. list-table::