(feat): Added PostgreSQL connection string encoding.

This commit is contained in:
Blake Ridgway 2025-02-15 18:58:48 -06:00
parent 32dcace985
commit 51f154ab73
5 changed files with 45 additions and 32 deletions

View file

@ -1,5 +1,22 @@
import os
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from dotenv import load_dotenv
from urllib.parse import quote_plus
load_dotenv()
PG_USER = quote_plus(os.getenv('PG_USER'))
PG_PASSWORD = quote_plus(os.getenv('PG_PASSWORD'))
PG_HOST = os.getenv('PG_HOST')
PG_PORT = os.getenv('PG_PORT')
PG_DATABASE = os.getenv('PG_DATABASE')
DATABASE_URI = f"postgresql+psycopg2://{PG_USER}:{PG_PASSWORD}@{PG_HOST}:{PG_PORT}/{PG_DATABASE}"
db = SQLAlchemy()
bcrypt = Bcrypt()
def init_db(app):
"""Initialize the SQLAlchemy app with the configuration."""
app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URI
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)