feat: alembic migration added
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1
-1
@@ -10,7 +10,7 @@ def get_items(db: Session, skip: int = 0, limit: int = 10):
|
||||
return db.query(models.Item).offset(skip).limit(limit).all()
|
||||
|
||||
|
||||
def create_item(db: Session, item: schemas.ItemCreate):
|
||||
def create_item(db: Session, item: schemas.Item):
|
||||
db_item = models.Item(**item.model_dump())
|
||||
db.add(db_item)
|
||||
db.commit()
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker, declarative_base
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
DATABASE_URL = os.getenv(
|
||||
"DATABASE_URL", "postgresql://user:password@db:5432/mydatabase"
|
||||
)
|
||||
env = load_dotenv()
|
||||
DATABASE_URL = os.getenv("DATABASE_URL", "")
|
||||
|
||||
engine = create_engine(DATABASE_URL)
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ def health_check():
|
||||
|
||||
|
||||
@app.post("/items/", response_model=schemas.Item)
|
||||
def create_item(item: schemas.ItemCreate, db: Session = Depends(get_db)):
|
||||
def create_item(item: schemas.Item, db: Session = Depends(get_db)):
|
||||
return crud.create_item(db, item)
|
||||
|
||||
|
||||
|
||||
@@ -4,10 +4,7 @@ from pydantic import BaseModel
|
||||
class ItemBase(BaseModel):
|
||||
name: str
|
||||
description: str | None = None
|
||||
|
||||
|
||||
class ItemCreate(ItemBase):
|
||||
pass
|
||||
body: str
|
||||
|
||||
|
||||
class Item(ItemBase):
|
||||
|
||||
Reference in New Issue
Block a user