new database system
This commit is contained in:
parent
039b877241
commit
bf71979982
8 changed files with 92 additions and 124 deletions
|
|
@ -1,21 +1,22 @@
|
|||
from enum import Enum
|
||||
import random
|
||||
import smtplib
|
||||
from backend.config import SECRET_KEY, ALGORITHM, ACCESS_TOKEN_EXPIRE_MINUTES ,pwd_context, get_session_db, Base
|
||||
from backend.config import SECRET_KEY, ALGORITHM, ACCESS_TOKEN_EXPIRE_MINUTES ,pwd_context, get_session_db, Base, user_collection
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pydantic import BaseModel
|
||||
from fastapi import Depends, HTTPException
|
||||
from typing import Annotated
|
||||
from fastapi.security import OAuth2PasswordBearer
|
||||
from pydantic.networks import EmailStr
|
||||
from sqlalchemy import Integer, DateTime
|
||||
from sqlalchemy import Integer, DateTime, ForeignKey
|
||||
from sqlalchemy.orm import Session, relationship, mapped_column, Mapped
|
||||
from sqlalchemy.dialects.postgresql import ARRAY
|
||||
from email.message import EmailMessage
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..items.models import Items
|
||||
from ..collectionObj.models import CollectionsDB #iç içe import döngüsünü önlemek için TYPE_CHECKING kullanıyoruz
|
||||
|
||||
|
||||
import jwt
|
||||
|
|
@ -66,6 +67,7 @@ class DBUser(Base):
|
|||
__tablename__ = "users_table"
|
||||
|
||||
user_id: Mapped[int] = mapped_column(primary_key=True, index=True, autoincrement=True)
|
||||
#collection_id : Mapped[list[int]] = mapped_column(Integer, ForeignKey("collections_table.collection_id"), nullable=True) # collection_id ile ilişki
|
||||
username : Mapped[str] = mapped_column(unique=True, index=True, nullable=False)
|
||||
email : Mapped[str] = mapped_column(unique=True, index=True, nullable=False)
|
||||
hashed_password : Mapped[str] = mapped_column(nullable=False)
|
||||
|
|
@ -75,8 +77,13 @@ class DBUser(Base):
|
|||
bio : Mapped[str] = mapped_column(default="No bio")
|
||||
follow_users : Mapped[list[int]] = mapped_column(ARRAY(Integer), default=[]) # takip edilen kullanıcılar
|
||||
# -> buralar diğer tablolar ile olan ilişkiler
|
||||
items : Mapped[list['Items']] = relationship("Items", back_populates="user", cascade="all, delete-orphan")
|
||||
collections : Mapped[int] = mapped_column(default=0) # hat vermesin diye eklendi collections aktif değil
|
||||
#items : Mapped[list['Items']] = relationship("Items", back_populates="user", cascade="all, delete-orphan") items'e direk değil collection üzerinden erişiyoruz
|
||||
collections : Mapped[list['CollectionsDB']] = relationship(
|
||||
"CollectionsDB",
|
||||
secondary=user_collection,
|
||||
back_populates="users",
|
||||
lazy='select'
|
||||
) # collection'lar ile olan ilişki
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue