add config defaults for postgres dev docker image, support setting POSTGRES_PASSWORD

This commit is contained in:
Andreas Köpf
2022-12-15 10:39:36 +01:00
parent 9742f6bd7b
commit c0e9f037c6
4 changed files with 23 additions and 8 deletions
+1
View File
@@ -1 +1,2 @@
.venv
*.pyc
+18 -2
View File
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
# touch
from typing import List, Optional, Union
from typing import Any, Dict, List, Optional, Union
from pydantic import AnyHttpUrl, BaseSettings, PostgresDsn, validator
@@ -8,8 +7,25 @@ from pydantic import AnyHttpUrl, BaseSettings, PostgresDsn, validator
class Settings(BaseSettings):
PROJECT_NAME: str = "open-chatGPT backend"
API_V1_STR: str = "/api/v1"
POSTGRES_SERVER: str = "localhost:5432"
POSTGRES_USER: str = "postgres"
POSTGRES_PASSWORD: str = "postgres"
POSTGRES_DB: str = "postgres"
DATABASE_URI: Optional[PostgresDsn] = None
@validator("DATABASE_URI", pre=True)
def assemble_db_connection(cls, v: Optional[str], values: Dict[str, Any]) -> Any:
if isinstance(v, str):
return v
return PostgresDsn.build(
scheme="postgresql",
user=values.get("POSTGRES_USER"),
password=values.get("POSTGRES_PASSWORD"),
host=values.get("POSTGRES_SERVER"),
path=f"/{values.get('POSTGRES_DB') or ''}",
)
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []
UPDATE_ALEMBIC: bool = True
+4 -4
View File
@@ -9,7 +9,7 @@ from pydantic import BaseModel
class TaskRequest(BaseModel):
"""The frontend asks the backend for a task."""
type: Literal
type: str
user_id: Optional[str] = None
@@ -21,14 +21,14 @@ class Task(BaseModel):
"""A task is a unit of work that the backend gives to the frontend."""
id: UUID = pydantic.Field(default_factory=UUID)
type: Literal
type: str
addressed_users: Optional[list[str]] = None
class TaskResponse(BaseModel):
"""A task response is a message from the frontend to acknowledge the given task."""
type: Literal
type: str
status: Literal["success", "failure"]
@@ -50,7 +50,7 @@ class TaskDone(Task):
class Interaction(BaseModel):
"""An interaction is a message from the frontend to the backend."""
type: Literal
type: str
user_id: str
-2
View File
@@ -1,5 +1,3 @@
#!/usr/bin/env bash
export DATABASE_URI=postgresql://postgres:postgres@localhost:5432/postgres
uvicorn app.main:app --reload