Skip to content

Latest commit

 

History

History
68 lines (41 loc) · 3.85 KB

File metadata and controls

68 lines (41 loc) · 3.85 KB

Important

If you already have PostgreSQL (PostgresSQL.exe) and PgAdmin (PgAdmin4.exe) software installed on your local computer, you have two options:

  • Option 1: Keep using your existing installation (credentials like username, password) without using our Docker containers. In this case, you might NEED to change the database connection settings in the .env file to match your existing installation if there is any error. You can skip the following steps and go to the next section.
  • Option 2: Use our Docker containers for PostgreSQL and PgAdmin. In this case, you NEED to stop your existing PostgreSQL.exe and PgAdmin.exe services to avoid port conflicts. For example, with the PostgreSQL service, use net stop postgresql-x64-14 for Windows or sudo service postgresql stop for Linux/Mac. This will prevent the .exe and Docker services from using the same 5432 port, which could lead to unexpected behaviors.

Running PostgreSQL and PgAdmin with Docker

The Postgres database and PgAdmin (to manage the database with GUI) are run in Docker containers. If you only need to run the database services with docker-compose, REMEMBER to comment out the backend and frontend services in the docker-compose.yml file to avoid starting the backend and frontend services.

Then run this command in the root directory of the project to start the Docker containers:

docker-compose up -d

The -d flag is for detached mode, which means the containers will run in the background. If you want to see the logs, you can remove the -d flag.

Wait a few seconds for Docker to initialize everything.

Initializing the Database

Once Docker has started, you need to run the backend to initialize the database. This will:

  • Connect to the database.

  • Create necessary tables.

  • Seed the database with initial data.

To do this, navigate to the backend directory and run:

cd app/backend
yarn install # to install the dependencies
yarn start # to start the server

Warning

In the development environment, whenever the backend server starts, it will automatically DROP ALL EXISTING TABLES in the database and CREATE NEW TABLES with the initial data. This is useful for development purposes, but be careful not to run this in production as it will delete all existing data.

Managing the Database with PgAdmin

Once everything is set up, you can log in to PgAdmin to manage the database by accessing the URL http://localhost:5050. You can use PgAdmin to create, modify, and delete tables, as well as run SQL queries against the database.

To log in to PgAdmin, enter credentials based on the fields PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD defined inside .env. After that, set up the server connection to the PostgreSQL database by following these steps:

  1. On the left panel, right-click on "Servers" and select "Register" -> "Server...".

PgAdmin_1

  1. Enter the name of the server as you wish:

PgAdmin_2

  1. Change to the "Connection" tab, and enter the following information:

PgAdmin_3

  • Host name/address: postgres (must use the same as the PostgreSQL service name as defined in the docker-compose.yml file)
  • Port: see the DB_PORT field in the .env file
  • Username: see the DB_USER field in the .env file
  • Password: see the DB_PASSWORD field in the .env file

Click "Save" to save the server configuration. After that, you should see your database viewable in the left panel. Click on the database name to see the tables inside.

PgAdmin_4

  1. To stop the database, run docker-compose down in the root directory of the project or docker-compose down -v to remove the volumes as well. The -v flag will remove the database and all data inside it, so be careful with this command.