2023-05-21 01:50:44 +01:00
|
|
|
"""This module defines the SQL data model for users."""
|
|
|
|
|
2023-05-31 16:37:56 +01:00
|
|
|
from sqlalchemy import Column, Integer, String, DateTime, Boolean
|
2023-05-21 01:50:44 +01:00
|
|
|
from sqlalchemy.sql.functions import now
|
|
|
|
from sqlalchemy.orm import relationship
|
|
|
|
|
|
|
|
from todo.database.engine import Base
|
|
|
|
|
|
|
|
|
|
|
|
class User(Base):
|
|
|
|
"""Model for the users table."""
|
|
|
|
|
|
|
|
__tablename__ = "users"
|
|
|
|
|
|
|
|
id = Column('id', Integer, primary_key=True, autoincrement=True, index=True)
|
2023-05-22 12:44:10 +01:00
|
|
|
email = Column('email', String, unique=True, nullable=False, index=True)
|
2023-05-21 01:50:44 +01:00
|
|
|
password = Column('password', String, nullable=False)
|
|
|
|
created = Column('created', DateTime(timezone=True), nullable=False, server_default=now())
|
|
|
|
updated = Column('updated', DateTime(timezone=True), nullable=False, server_default=now(), onupdate=now())
|
|
|
|
first_name = Column('first_name', String, nullable=False)
|
2023-05-22 12:44:10 +01:00
|
|
|
last_name = Column('last_name', String, nullable=False, index=True)
|
2023-05-31 16:37:56 +01:00
|
|
|
is_admin = Column('is_admin', Boolean, nullable=False, default=False, index=True)
|
2023-05-21 01:50:44 +01:00
|
|
|
|
|
|
|
todo_items = relationship("TodoItem", back_populates="user", uselist=True, cascade="all, delete")
|