This guide details the process for initializing the PostgreSQL database, ensuring all necessary extensions (pg_trgm, uuid-ossp) and user permissions are correctly configured before the TypeORM application migrations begin.
This process separates the high-privilege administrative tasks from the standard application schema tasks, which is the best practice for robust deployment.
Before running any setup scripts, ensure the following tools are installed and configured:
-
PostgreSQL: Database server is running and accessible.
-
psql: PostgreSQL command-line client is installed and available in your environment's PATH. -
Node.js/npm: Node.js and npm are installed to run TypeORM migrations.
The setup scripts rely on the following environment variables, which should be sourced from your environment file or deployment pipeline:
| Variable | Value (Example) | Used By | Description |
|---|---|---|---|
DATABASE_HOST |
localhost |
init.sh |
The hostname or IP address of the PostgreSQL server. |
DATABASE_NAME |
sellerswift |
init.sh |
The target database name. |
SUPERUSER |
postgres |
init.sh |
The highly privileged user used to install extensions and grant permissions. |
DATABASE_USERNAME |
myuser |
TypeORM | The application user that TypeORM will use for standard operations. |
The setup uses the files located in the db_setup/ directory: db_setup.sql (administrative commands) and init.sh (execution script).
The db_setup.sql file contains the high-privilege commands that must be run by the Superuser (postgres):