Skip to content

Commit

Permalink
remove items router and table from database
Browse files Browse the repository at this point in the history
  • Loading branch information
swelborn committed Aug 22, 2024
1 parent ce2b5f6 commit 6607ff5
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 388 deletions.
34 changes: 34 additions & 0 deletions backend/app/app/alembic/versions/516457e800b5_remove_items.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Remove items
Revision ID: 516457e800b5
Revises: ac46c9f37d67
Create Date: 2024-08-22 14:06:51.334874
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = '516457e800b5'
down_revision = 'ac46c9f37d67'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('item')
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('item',
sa.Column('description', sa.VARCHAR(length=255), autoincrement=False, nullable=True),
sa.Column('title', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
sa.Column('id', sa.UUID(), autoincrement=False, nullable=False),
sa.Column('owner_id', sa.UUID(), autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(['owner_id'], ['user.id'], name='item_owner_id_fkey', ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id', name='item_pkey')
)
# ### end Alembic commands ###
3 changes: 1 addition & 2 deletions backend/app/app/api/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from fastapi import APIRouter

from app.api.routes import items, login, pipelines, users, utils
from app.api.routes import login, pipelines, users, utils

api_router = APIRouter()
api_router.include_router(login.router, tags=["login"])
api_router.include_router(users.router, prefix="/users", tags=["users"])
api_router.include_router(utils.router, prefix="/utils", tags=["utils"])
api_router.include_router(items.router, prefix="/items", tags=["items"])
api_router.include_router(pipelines.router, prefix="/pipelines", tags=["pipelines"])
109 changes: 0 additions & 109 deletions backend/app/app/api/routes/items.py

This file was deleted.

6 changes: 3 additions & 3 deletions backend/app/app/api/routes/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from app.core.config import settings
from app.core.security import get_password_hash, verify_password
from app.models import (
Item,
Message,
Pipeline,
UpdatePassword,
User,
UserCreate,
Expand Down Expand Up @@ -130,7 +130,7 @@ def delete_user_me(session: SessionDep, current_user: CurrentUser) -> Any:
raise HTTPException(
status_code=403, detail="Super users are not allowed to delete themselves"
)
statement = delete(Item).where(col(Item.owner_id) == current_user.id)
statement = delete(Pipeline).where(col(Pipeline.owner_id) == current_user.id)
session.exec(statement) # type: ignore
session.delete(current_user)
session.commit()
Expand Down Expand Up @@ -217,7 +217,7 @@ def delete_user(
raise HTTPException(
status_code=403, detail="Super users are not allowed to delete themselves"
)
statement = delete(Item).where(col(Item.owner_id) == user_id)
statement = delete(Pipeline).where(col(Pipeline.owner_id) == user_id)
session.exec(statement) # type: ignore
session.delete(user)
session.commit()
Expand Down
11 changes: 1 addition & 10 deletions backend/app/app/crud.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import uuid
from typing import Any

from sqlmodel import Session, select

from app.core.security import get_password_hash, verify_password
from app.models import Item, ItemCreate, User, UserCreate, UserUpdate
from app.models import User, UserCreate, UserUpdate


def create_user(*, session: Session, user_create: UserCreate) -> User:
Expand Down Expand Up @@ -44,11 +43,3 @@ def authenticate(*, session: Session, email: str, password: str) -> User | None:
if not verify_password(password, db_user.hashed_password):
return None
return db_user


def create_item(*, session: Session, item_in: ItemCreate, owner_id: uuid.UUID) -> Item:
db_item = Item.model_validate(item_in, update={"owner_id": owner_id})
session.add(db_item)
session.commit()
session.refresh(db_item)
return db_item
71 changes: 0 additions & 71 deletions backend/app/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class UpdatePassword(SQLModel):
class User(UserBase, table=True):
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
hashed_password: str
items: list["Item"] = Relationship(back_populates="owner", cascade_delete=True)
pipelines: list["Pipeline"] = Relationship(
back_populates="owner", cascade_delete=True
)
Expand All @@ -60,43 +59,6 @@ class UsersPublic(SQLModel):
count: int


# Shared properties
class ItemBase(SQLModel):
title: str = Field(min_length=1, max_length=255)
description: str | None = Field(default=None, max_length=255)


# Properties to receive on item creation
class ItemCreate(ItemBase):
title: str = Field(min_length=1, max_length=255)


# Properties to receive on item update
class ItemUpdate(ItemBase):
title: str | None = Field(default=None, min_length=1, max_length=255) # type: ignore


# Database model, database table inferred from class name
class Item(ItemBase, table=True):
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
title: str = Field(max_length=255)
owner_id: uuid.UUID = Field(
foreign_key="user.id", nullable=False, ondelete="CASCADE"
)
owner: User | None = Relationship(back_populates="items")


# Properties to return via API, id is always required
class ItemPublic(ItemBase):
id: uuid.UUID
owner_id: uuid.UUID


class ItemsPublic(SQLModel):
data: list[ItemPublic]
count: int


# Generic message
class Message(SQLModel):
message: str
Expand Down Expand Up @@ -143,36 +105,3 @@ class PipelinePublic(PipelineBase):
class PipelinesPublic(SQLModel):
data: list[PipelinePublic]
count: int


# PortKeyType = str


# class PortType(str, Enum):
# input = "input"
# output = "output"


# class DataType(str, Enum):
# array = "array"


# class Port(SQLModel):
# id: uuid.UUID | None = Field(default=uuid.uuid4(), default_factory=uuid.uuid4)
# portkey: str
# port_type: PortType
# data_type: DataType


# class OperatorBase(SQLModel):
# image: str
# params: list[str] | None = None
# default_params: JSON = Field(default=JSON(), default_factory=JSON)
# inputs: list[Port] | None = None
# outputs: list[Port] | None = None


# class Operator(OperatorBase, table=True):
# id: uuid.UUID | None = Field(
# default=None, default_factory=uuid.uuid4, primary_key=True
# )
9 changes: 0 additions & 9 deletions backend/app/app/tests/api/routes/test.http
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ Content-Type: application/x-www-form-urlencoded

[email protected]&password=changethis

###
POST http://localhost:80/api/v1/items
Content-Type: application/json
Authorization: bearer put_the_access_token_here

{
"title": "test"
}

###

POST http://localhost:80/api/v1/pipelines
Expand Down
Loading

0 comments on commit 6607ff5

Please sign in to comment.