Spaces:
Sleeping
Sleeping
File size: 1,097 Bytes
868b252 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
from typing import List
from sqlalchemy import DateTime, ForeignKey, Index, String, text
from sqlalchemy.orm import Mapped, mapped_column, relationship
from reworkd_platform.db.base import Base
class UserSession(Base):
__tablename__ = "Session"
session_token = mapped_column(String, unique=True, name="sessionToken")
user_id = mapped_column(
String, ForeignKey("User.id", ondelete="CASCADE"), name="userId"
)
expires = mapped_column(DateTime)
user = relationship("User")
__table_args__ = (Index("user_id"),)
class User(Base):
__tablename__ = "User"
name = mapped_column(String, nullable=True)
email = mapped_column(String, nullable=True, unique=True)
email_verified = mapped_column(DateTime, nullable=True, name="emailVerified")
image = mapped_column(String, nullable=True)
create_date = mapped_column(
DateTime, server_default=text("(now())"), name="createDate"
)
sessions: Mapped[List["UserSession"]] = relationship(
"UserSession", back_populates="user"
)
__table_args__ = (Index("email"),)
|