From f3f5d0b6deebcc666aa331cabbf589bc6074b94d Mon Sep 17 00:00:00 2001 From: David Montero Crespo Date: Wed, 13 May 2026 03:21:51 -0300 Subject: [PATCH] feat(user): add plan_id column for agent quota tier management --- backend/app/main.py | 5 +++++ backend/app/models/user.py | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/backend/app/main.py b/backend/app/main.py index 6bea73c1..29b8a13f 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -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: diff --git a/backend/app/models/user.py b/backend/app/models/user.py index 66185993..2c61db10 100644 --- a/backend/app/models/user.py +++ b/backend/app/models/user.py @@ -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