feat(user): add plan_id column for agent quota tier management

This commit is contained in:
David Montero Crespo 2026-05-13 03:21:51 -03:00
parent 083e0df732
commit f3f5d0b6de
2 changed files with 11 additions and 0 deletions

View File

@ -82,6 +82,11 @@ async def lifespan(_app: FastAPI):
"ALTER TABLE users ADD COLUMN subscription_status VARCHAR(20)",
"ALTER TABLE users ADD COLUMN subscription_period_end DATETIME",
"ALTER TABLE users ADD COLUMN odoo_partner_id INTEGER",
# Agent quota tier — defaults to 'free' so existing rows that
# predate the quota system land in the free bucket. Admins +
# paid subs get bumped to 'pro' / 'pro_max' via the
# velxio_subscription Odoo webhook.
"ALTER TABLE users ADD COLUMN plan_id VARCHAR(20) NOT NULL DEFAULT 'free'",
]
for stmt in legacy_migrations:
try:

View File

@ -38,5 +38,11 @@ class User(Base):
subscription_status: Mapped[str | None] = mapped_column(String(20), nullable=True)
subscription_period_end: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
odoo_partner_id: Mapped[int | None] = mapped_column(Integer, nullable=True, index=True)
# Agent quota tier — drives /api/pro/agent/llm rate-limiting via the
# PLANS dict in pro/services/quota.py. Defaults to 'free' so anyone
# who registers can start using the chat panel right away (subject to
# the free-tier daily cap). Bumped to 'pro' / 'pro_max' on successful
# PayPal subscription via the velxio_subscription Odoo webhook.
plan_id: Mapped[str] = mapped_column(String(20), default="free", nullable=False, index=True)
projects: Mapped[list["Project"]] = relationship("Project", back_populates="owner", lazy="select") # noqa: F821