quartz/content/VCS-Documentation/server-install/Database Migration Scripts.md

3.8 KiB

This directory contains scripts for migrating an SQLite database to a PostgreSQL database as well as setting up a new database with the server ID.

Prerequisites

Setup

In /usr/vcs/docker/migration-scripts modify the .pgpass file in with the correct content: hostname:port:database:username:password

For example:

localhost:5432:postgres:vcs:vcs

Replace with the actual information of your Postgres database. If your password contains special characters, make sure to escape them with a backslash \

Make the scripts are executable and set the correct permissions for the .pgpass file:

chmod +x database_migration.sh
chmod +x disable_constraints.sh
chmod +x create_db_dump.sh
chmod +x transform_db_dump.sh
chmod +x consolidate.sh
chmod +x update_server_id.sh
chmod 600 .pgpass

Existing server upgrade only: For single server grab the vcs.db file, and rename it serverID.db(use the actual server id of the server, in case of vcs.db-wall and vcs.db-shm rename those with the server id as well) For multi server gather all the vcs.db files and rename as mentioned in the single server step

Move the database file(s) to the scripts directory(/usr/vcs/docker/migration-scripts)

Running the Migration

ServerID - server id for the server PSQL_PATH - path to Postgres psql Example: docker exec -i artsentry-services-postgres-1 psql

artsentry-services-postgres-1 - name of the Docker container which can be found by running docker ps (running services.png)

New Server Install

Run the update_server_id.sh script with the ServerID and the PSQL_PATH parameter:

Example of running the script with Docker instance of Postgres:

./update_server_id.sh 'server_id' 'docker exec -i artsentry-services-postgres-1 psql'

Example of running the script with local instance of Postgres:

./update_server_id.sh 'server_id' '/opt/homebrew/Cellar/postgresql@16/16.2_1/bin/psql'

If you want to redirect the output to a different file, use the following command:

./update_server_id.sh 'server_id' 'docker exec -i artsentry-services-postgres-1 psql' > migration.log

Existing Server Upgrade

To run the migration process, execute the database_migration.sh script with PSQL_PATH parameter:

Example of running the script with Docker instance of PostgreSQL:

./database_migration.sh 'docker exec -i artsentry-services-postgres-1 psql'

Example of running the script with local instance of PostgreSQL:

./database_migration.sh '/opt/homebrew/Cellar/postgresql@16/16.2_1/bin/psql'

If you want to redirect the output to a different file, use the following command:

./database_migration.sh 'docker exec -i artsentry-services-postgres-1 psql' > migration.log

Start VCS Server

After completing the required steps in Postgres + docker compose setup and executing the script(s) above, start the VCS Server

systemctl start vcs

Scripts Description(FYI)

  • database_migration.sh: Main script that orchestrates the migration process
  • disable_constraints.sh: Disables constraints in the PostgreSQL database to prevent conflicts during data import
  • create_db_dump.sh: Creates a dump of the SQLite database that can be imported into the PostgreSQL database
  • transform_db_dump.sh: Transforms the SQLite dump to be compatible with Postgres
  • consolidate.sh: Consolidates the transformed dump into the PostgreSQL database
  • update_server_id.sh: Updates the server ID in the Postgres database after the migration or at new setup