| import uuid |
| from sqlalchemy import Column, String, Boolean, DateTime, func, Index |
| from sqlalchemy.dialects.postgresql import UUID |
|
|
| from auth.database import Base |
|
|
|
|
| |
| |
| |
| class User(Base): |
| __tablename__ = "users" |
|
|
| |
| |
| |
| id = Column( |
| UUID(as_uuid=True), |
| primary_key=True, |
| default=uuid.uuid4, |
| nullable=False, |
| ) |
|
|
| |
| |
| |
| email = Column(String(255), unique=True, nullable=False, index=True) |
| username = Column(String(100), unique=True, nullable=True, index=True) |
|
|
| |
| |
| |
| |
| hashed_password = Column(String(255), nullable=False) |
|
|
| |
| |
| |
| is_active = Column(Boolean, default=True, nullable=False) |
| is_verified = Column(Boolean, default=False, nullable=False) |
|
|
| |
| |
| |
| created_at = Column( |
| DateTime(timezone=True), |
| server_default=func.now(), |
| nullable=False, |
| ) |
|
|
| updated_at = Column( |
| DateTime(timezone=True), |
| server_default=func.now(), |
| onupdate=func.now(), |
| nullable=False, |
| ) |
|
|
|
|
| |
| |
| |
| class ApiKey(Base): |
| __tablename__ = "api_keys" |
|
|
| id = Column( |
| UUID(as_uuid=True), |
| primary_key=True, |
| default=uuid.uuid4, |
| nullable=False, |
| ) |
|
|
| user_id = Column( |
| UUID(as_uuid=True), |
| nullable=False, |
| index=True, |
| ) |
|
|
| key_hash = Column(String(255), nullable=False, unique=True) |
|
|
| name = Column(String(120), nullable=True) |
|
|
| is_active = Column(Boolean, default=True, nullable=False) |
|
|
| created_at = Column( |
| DateTime(timezone=True), |
| server_default=func.now(), |
| nullable=False, |
| ) |
|
|
|
|
| |
| |
| |
| Index("idx_users_email", User.email) |
| Index("idx_users_username", User.username) |
| Index("idx_api_keys_user_id", ApiKey.user_id) |