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
4 changes: 2 additions & 2 deletions electro/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Settings(BaseSettings):
BOT_LANGUAGE: str = "en" # Should mirror the `DEFAULT_LOCALE` setting. User in the Python code

# Postgres database credentials
DATABASE_URL: PostgresDsn | None
DATABASE_URL: PostgresDsn | None = None
# if the `DATABASE_URL` is not set, then use the following credentials:
POSTGRES_HOST: str | None = None
POSTGRES_USER: str | None = None
Expand All @@ -41,7 +41,7 @@ class Settings(BaseSettings):
ENABLE_DATABASE_SSL: bool = True

# Redis credentials
REDIS_URL: RedisDsn | None
REDIS_URL: RedisDsn | None = None
# if the `REDIS_URL` is not set, then use the following credentials:
REDIS_HOST: str | None = None
REDIS_PORT: int | None = 6379
Expand Down
6 changes: 4 additions & 2 deletions electro/toolkit/redis_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@

from ..settings import settings

if not (redis_url := settings.REDIS_URL):
if not settings.REDIS_URL:
redis_url = f"redis://{settings.REDIS_HOST}:{settings.REDIS_PORT}/{settings.REDIS_DB}"
else:
redis_url = str(settings.REDIS_URL)

redis_config: dict = dj_redis_url.config(default=str(redis_url))
redis_config: dict = dj_redis_url.config(default=redis_url)

STATE_KEY = "state"
STATE_DATA_KEY = "data"
Expand Down
5 changes: 4 additions & 1 deletion electro/toolkit/tortoise_orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ class Model(tortoise_Model, metaclass=ModelMeta):

def get_tortoise_config():
"""Get the configuration for the `tortoise-orm`."""
if not (database_url := str(settings.DATABASE_URL)):
if not settings.DATABASE_URL:
database_url = (
f"postgres://{settings.POSTGRES_USER}:{settings.POSTGRES_PASSWORD}@"
f"{settings.POSTGRES_HOST}:{settings.POSTGRES_PORT}/{settings.POSTGRES_DB}"
)
else:
database_url = str(settings.DATABASE_URL)

db = expand_db_url(database_url)
ctx = False
if settings.ENABLE_DATABASE_SSL:
Expand Down