This README provides instructions for setting up the database, configuring users, and connecting the client and server in development mode.
First, clone the repository and navigate to the project directory.
git clone org-184059057@github.com:hellowhorl/whorl-server.gitHere you will utilize venv, which is short for virtual environment, specific for your client.
-
Create a Virtual Environment
-
In the root of the
whorl-serverrepository, run the following command:python -m venv .venv
-
-
Activate the Virtual Environment
-
Activate your virtual environment with the command:
source .venv/bin/activate
-
Once your virtual environment is set up, perform a development install by running the following command:
python -m pip install -e .If you are part of the whorl organization, you can find the keys in the .env file. If you are not, you can create your own .env file in the root of the whorl-server repository.
-
The
.envfile should contain the following variables:API_URL=localhost API_DB_HOST=localhost API_DB_USER=<your_api_db_user_name> API_DB_PASS=<your_api_db_pass> API_HOST=<your_api_host> OPEN_AI_KEY=<your_openai_key> OPENWEATHER_API=<your_openweather_key> OPENWEATHER_LAT=<your_openweather_latitude> OPENWEATHER_LON=<your_openweather_longitude>
- Install PostgreSQL
- Make sure PostgreSQL is installed on your machine.
- If not installed, you can download it from PostgreSQL Downloads and follow the installation instructions for your operating system.
-
Start the services
-
Start the PostgreSQL service:
brew services start postgresql
-
-
Access the PostgreSQL Shell
-
Open a terminal and log into the PostgreSQL shell:
psql postgres
-
-
To stop the service
-
To stop the PostgreSQL service
brew services stop postgresql
-
-
Start the services
-
Start the PostgreSQL service:
sudo systemctl start postgresql -
Verify if PostgreSQL is running:
sudo systemctl status postgresql -
Stop PostgreSQL when needed:
sudo systemctl stop postgresql
-
-
Access the PostgreSQL Shell
-
Open a terminal and log into the PostgreSQL shell:
sudo -i -u postgres psql
-
- Start the services
-
Start the PostgreSQL service using the Services Manager:
-
press Win + R, type services.msc, and press Enter.
-
Locate the PostgreSQL service in the list.
-
Right-click on it and choose start.
-
If wanted to run alternatively you can start the service in the terminal using the command prompt:
start postgresql-x64-<version>
-
Access the PostgreSQL Shell
-
Open a terminal and log into the PostgreSQL shell:
-
navigate to the PostgreSQL bin directory (e.g., C:\Program Files\PostgreSQL<version>\bin).
-
log into the PostgreSQL shell:
psql -U postgres
-
-
To Stop the Services:
-
To stop the service:
stop postgresql-x64-<version>
-
- Ensure PostgreSQL shell is running
- Make sure you do the above instrsuctions because none of the database steps are doable without a PostgreSQL shell
-
Create the Database
-
Run the following SQL command to create the
<database>database:CREATE DATABASE "<database>";
-
-
Create the User
-
Run the following SQL command to create the user with password (reference the
.env filefor the password):CREATE USER 'user' WITH PASSWORD '<password>';
PS: 'user' doesn't need quotes, but 'password' does.
-
-
Grant User Permissions
- Grant all privileges on the
<database>database to the user:
GRANT ALL PRIVILEGES ON DATABASE "<database>" TO <user>;
- Grant all privileges on the
-
Verify Ownership
-
Use the
\lcommand to list databases and check if user owns the<database>database. -
If not, update the owner with this command:
ALTER DATABASE "<database>" OWNER TO <user>;
-
-
Exit the PostgreSQL Shell
- Type
\qto exit.
- Type
-
Client Configuration
-
Open the
.envfile in the client directory. -
Set the
API_URLto:http://localhost
-
-
Start the Server
-
Navigate to the server directory.
cd src -
Run the following command to start the server:
python manage.py runserver
-
-
Run the Client
-
In the client directory, run the command to see if output is displayed:
climate
-