Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ logs/
__pycache__/
*.pyc
.pytest_cache/
backups/
backups/
.env
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,30 @@ This template utilizes PostgreSQL as the database backend.
2. **Create and activate the conda environment**:

```sh
# Windows
conda env create -f environment.yml
# Mac
conda env create -f environment_mac.yml
conda activate justin_rl_api
```

3. **Configure the database**:
Setup a PostgreSQL database and create a new database for the application.
Update the database connection string in ```config.py```. For PostgreSQL, the string looks like:
Setup a PostgreSQL database ([download](https://www.postgresql.org/download/ )) and create a new database for the application.

Create a database
```sh
SQLALCHEMY_DATABASE_URI = "postgresql://<username>:<password>@<host>:<port>/<database>"
# in shell
psql -U postgres

# in psql
CREATE DATABASE your_db_name;

```

Create a file ".env" at the root folder of your project and add the database connection string. For PostgreSQL, the string looks like:

```sh
SQLALCHEMY_DATABASE_URI="postgresql://<username>:<password>@<host>:<port>/<database>"
```

4. **Initialize the database**:
Expand Down
4 changes: 3 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
from dotenv import load_dotenv

load_dotenv()

class Config:
# General Configuration
Expand All @@ -25,7 +27,7 @@ class Config:
# "DATABASE_URL", "postgresql://myuser:mypassword@localhost:5432/mydatabase"
# )
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_DATABASE_URI = "postgresql://zipingxu@localhost:5432/justin_rl_db"
SQLALCHEMY_DATABASE_URI = os.getenv('SQLALCHEMY_DATABASE_URI') or "postgresql://zipingxu@localhost:5432/justin_rl_db"
SQLALCHEMY_ENGINE_OPTIONS = {
"pool_recycle": 3600, # Recycle connections after 3600 seconds (1 hour)
}
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies:
- pip=24.2
- psycopg2=2.9.9
- python=3.11.11
- python-dotenv=1.1.0
- setuptools=75.1.0
- sqlalchemy=2.0.34
- sqlite=3.45.3
Expand Down
1 change: 1 addition & 0 deletions environment_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies:
- pip=24.2
- psycopg2=2.9.9
- python=3.11.11
- python-dotenv=1.1.0
- setuptools=75.1.0
- sqlalchemy=2.0.34
- sqlite=3.45.3
Expand Down