diff --git a/backend/app/__pycache__/db_engine.cpython-313.pyc b/backend/app/__pycache__/db_engine.cpython-313.pyc new file mode 100644 index 0000000..9301b60 Binary files /dev/null and b/backend/app/__pycache__/db_engine.cpython-313.pyc differ diff --git a/backend/app/__pycache__/init_db.cpython-313.pyc b/backend/app/__pycache__/init_db.cpython-313.pyc new file mode 100644 index 0000000..4394728 Binary files /dev/null and b/backend/app/__pycache__/init_db.cpython-313.pyc differ diff --git a/backend/app/db_engine.py b/backend/app/db_engine.py index e576a86..79ddf58 100644 --- a/backend/app/db_engine.py +++ b/backend/app/db_engine.py @@ -5,11 +5,11 @@ import os dotenv.load_dotenv() -PG_USER = dotenv.get_key(".env", "PG_USER") -PG_PASSWORD = dotenv.get_key(".env", "PG_PASSWORD") -PG_HOST = dotenv.get_key(".env", "PG_HOST") -PG_PORT = dotenv.get_key(".env", "PG_PORT") -PG_DB = dotenv.get_key(".env", "PG_DB") +PG_USER = dotenv.get_key(".env", "POSTGRES_USER") +PG_PASSWORD = dotenv.get_key(".env", "POSTGRES_PASSWORD") +PG_HOST = dotenv.get_key(".env", "POSTGRES_HOST") +PG_PORT = dotenv.get_key(".env", "POSTGRES_PORT") +PG_DB = dotenv.get_key(".env", "POSTGRES_DB") DATABASE_URL = ( f"postgresql+asyncpg://{PG_USER}:{PG_PASSWORD}@{PG_HOST}:{PG_PORT}/{PG_DB}" @@ -17,7 +17,7 @@ DATABASE_URL = ( engine = create_async_engine( DATABASE_URL, - echo=False, + echo=False, future=True, ) @@ -31,6 +31,7 @@ async_session_maker = async_sessionmaker( class Base(DeclarativeBase): pass + async def get_async_session(): async with async_session_maker() as session: yield session @@ -39,4 +40,3 @@ async def get_async_session(): async def init_db(): async with engine.begin() as conn: await conn.run_sync(Base.metadata.create_all) - diff --git a/backend/app/init_db.py b/backend/app/init_db.py new file mode 100644 index 0000000..d49ac06 --- /dev/null +++ b/backend/app/init_db.py @@ -0,0 +1,9 @@ +from app.db_engine import init_db + +from app.models.posts import Post + + +if __name__ == "__main__": + import asyncio + + asyncio.run(init_db()) diff --git a/backend/app/models/__init__.py b/backend/app/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/app/models/__pycache__/__init__.cpython-313.pyc b/backend/app/models/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 0000000..bcc9114 Binary files /dev/null and b/backend/app/models/__pycache__/__init__.cpython-313.pyc differ diff --git a/backend/app/models/__pycache__/posts.cpython-313.pyc b/backend/app/models/__pycache__/posts.cpython-313.pyc new file mode 100644 index 0000000..575f418 Binary files /dev/null and b/backend/app/models/__pycache__/posts.cpython-313.pyc differ diff --git a/backend/app/schemas/__init__.py b/backend/app/schemas/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/app/schemas/guestbook.py b/backend/app/schemas/guestbook.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/app/schemas/posts.py b/backend/app/schemas/posts.py new file mode 100644 index 0000000..154db42 --- /dev/null +++ b/backend/app/schemas/posts.py @@ -0,0 +1,30 @@ +from pydantic import BaseModel, Field +from typing import Optional + + +class PostCreate(BaseModel): + title: str = Field(min_length=3, max_length=150) + content: str = Field(min_length=10) + images: Optional[str] = Field() + + class Config: + orm_mode = True + + +class PostRead(BaseModel): + id: int = Field() + title: str = Field(min_length=3, max_length=150) + content: str = Field(min_length=10) + images: str = Field() + + class Config: + orm_mode = True + + +class PostUpdate(BaseModel): + title: str = Field(min_length=3, max_length=150) + content: str = Field(min_length=10) + images: Optional[str] = Field() + + class Config: + orm_mode = True diff --git a/backend/docker-compose.yml b/backend/docker-compose.yml index a2e7d61..3ac78f0 100644 --- a/backend/docker-compose.yml +++ b/backend/docker-compose.yml @@ -1,8 +1,9 @@ services: postgres: image: postgres:18-alpine3.22 + restart: always ports: - - "5432:5432" + - "5432:5432" environment: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}