Spaces:
Sleeping
Sleeping
Download src/models/user.py from arimatch1/crewhub-worker: direct link, hf CLI and curl.
- Browser
- Download file 4.24 kB
-
https://huggingface.co/spaces/arimatch1/crewhub-worker/resolve/main/src/models/user.py
- Command line
-
hf download hf://spaces/arimatch1/crewhub-worker/src/models/user.py
-
curl -L -o user.py https://huggingface.co/spaces/arimatch1/crewhub-worker/resolve/main/src/models/user.py
4.24 kB
| # Copyright (c) 2026 CrewHub. All rights reserved. | |
| # Proprietary and confidential. See LICENSE for details. | |
| import uuid | |
| from datetime import datetime | |
| from typing import Optional | |
| import sqlalchemy as sa | |
| from sqlalchemy import JSON, Boolean, DateTime, String, Uuid, func | |
| from sqlalchemy.orm import Mapped, mapped_column, relationship | |
| from src.database import Base | |
| class User(Base): | |
| __tablename__ = "users" | |
| id: Mapped[uuid.UUID] = mapped_column( | |
| Uuid, primary_key=True, default=uuid.uuid4 | |
| ) | |
| email: Mapped[str] = mapped_column(String(255), unique=True, nullable=False, index=True) | |
| hashed_password: Mapped[str] = mapped_column(String(255), nullable=False) | |
| name: Mapped[str] = mapped_column(String(255), nullable=False) | |
| firebase_uid: Mapped[Optional[str]] = mapped_column( | |
| String(128), unique=True, nullable=True, index=True | |
| ) | |
| # Account tier: "free" (rate-limited) or "premium" (unlimited) | |
| account_tier: Mapped[str] = mapped_column( | |
| String(20), nullable=False, default="free", server_default="free" | |
| ) | |
| # Stripe billing | |
| stripe_customer_id: Mapped[Optional[str]] = mapped_column( | |
| String(255), unique=True, nullable=True, index=True | |
| ) | |
| stripe_subscription_id: Mapped[Optional[str]] = mapped_column( | |
| String(255), nullable=True | |
| ) | |
| # Stripe Connect (developer payouts) | |
| stripe_connect_account_id: Mapped[Optional[str]] = mapped_column( | |
| String(255), unique=True, nullable=True, index=True | |
| ) | |
| stripe_connect_onboarded: Mapped[bool] = mapped_column( | |
| Boolean, default=False, server_default=sa.false() | |
| ) | |
| stripe_connect_payouts_enabled: Mapped[bool] = mapped_column( | |
| Boolean, default=False, server_default=sa.false() | |
| ) | |
| api_key_hash: Mapped[Optional[str]] = mapped_column( | |
| String(64), unique=True, nullable=True, index=True | |
| ) | |
| api_key_revoked_at: Mapped[Optional[datetime]] = mapped_column( | |
| DateTime(timezone=True), nullable=True, default=None | |
| ) | |
| # User's LLM API keys (encrypted), keyed by provider name. | |
| # Format: {"openai": "<encrypted>", "gemini": "<encrypted>", ...} | |
| llm_api_keys: Mapped[Optional[dict]] = mapped_column(JSON, nullable=True, default=dict) | |
| is_active: Mapped[bool] = mapped_column(Boolean, default=True, server_default=sa.true()) | |
| is_admin: Mapped[bool] = mapped_column(Boolean, default=False, server_default=sa.false()) | |
| admin_role: Mapped[Optional[str]] = mapped_column( | |
| String(20), nullable=True, default=None, | |
| comment="super_admin | ops_admin | billing_admin | NULL" | |
| ) | |
| onboarding_completed: Mapped[bool] = mapped_column(Boolean, default=False, server_default=sa.false()) | |
| daily_spend_limit: Mapped[Optional[float]] = mapped_column( | |
| sa.Float, nullable=True, default=None, | |
| comment="Max credits per day (NULL = unlimited)" | |
| ) | |
| interests: Mapped[list | None] = mapped_column(JSON, nullable=True, default=list) | |
| deletion_requested_at: Mapped[Optional[datetime]] = mapped_column( | |
| DateTime(timezone=True), nullable=True, default=None | |
| ) | |
| consent_version: Mapped[Optional[str]] = mapped_column( | |
| String(20), nullable=True, default=None | |
| ) | |
| consent_given_at: Mapped[Optional[datetime]] = mapped_column( | |
| DateTime(timezone=True), nullable=True, default=None | |
| ) | |
| consent_ip: Mapped[Optional[str]] = mapped_column( | |
| String(45), nullable=True, default=None | |
| ) | |
| created_at: Mapped[datetime] = mapped_column( | |
| DateTime(timezone=True), server_default=func.now(), nullable=False | |
| ) | |
| updated_at: Mapped[datetime] = mapped_column( | |
| DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False | |
| ) | |
| # Relationships | |
| agents: Mapped[list["Agent"]] = relationship("Agent", back_populates="owner", lazy="selectin") | |
| account: Mapped["Account"] = relationship("Account", back_populates="owner", uselist=False, lazy="selectin") | |
| memberships: Mapped[list["Membership"]] = relationship( | |
| "Membership", back_populates="user", lazy="noload", cascade="all, delete-orphan" | |
| ) | |
| def __repr__(self) -> str: | |
| return f"<User(id={self.id}, email={self.email}, name={self.name})>" | |