mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-12 22:42:13 +02:00
feat: enhance credit management and user experience
- Updated database queries to check for column existence with schema context. - Modified credit purchase quantity limits to allow up to 10,000 credits. - Improved user interface for credit purchases, enabling custom amounts and clamping input values. - Adjusted FAQ content to clarify credit purchasing process.
This commit is contained in:
parent
a7407502d3
commit
65e511f77b
6 changed files with 70 additions and 23 deletions
|
|
@ -55,7 +55,8 @@ def _column_exists(conn, table: str, column: str) -> bool:
|
|||
conn.execute(
|
||||
sa.text(
|
||||
"SELECT 1 FROM information_schema.columns "
|
||||
"WHERE table_name = :tbl AND column_name = :col"
|
||||
"WHERE table_name = :tbl AND column_name = :col "
|
||||
"AND table_schema = current_schema()"
|
||||
),
|
||||
{"tbl": table, "col": column},
|
||||
).fetchone()
|
||||
|
|
@ -107,11 +108,17 @@ def upgrade() -> None:
|
|||
),
|
||||
)
|
||||
|
||||
# Backfill only when the legacy source columns are present (fresh DBs
|
||||
# Backfill only when ALL legacy source columns are present (fresh DBs
|
||||
# created from current models won't have them).
|
||||
if _column_exists(
|
||||
conn, "user", "premium_credit_micros_limit"
|
||||
) and _column_exists(conn, "user", "pages_limit"):
|
||||
if all(
|
||||
_column_exists(conn, "user", col)
|
||||
for col in (
|
||||
"premium_credit_micros_limit",
|
||||
"premium_credit_micros_used",
|
||||
"pages_limit",
|
||||
"pages_used",
|
||||
)
|
||||
):
|
||||
conn.execute(
|
||||
sa.text(
|
||||
'UPDATE "user" SET credit_micros_balance = '
|
||||
|
|
@ -163,8 +170,18 @@ def upgrade() -> None:
|
|||
"""
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (SELECT 1 FROM pg_type WHERE typname = 'premiumtokenpurchasestatus')
|
||||
AND NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'creditpurchasestatus')
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM pg_type t
|
||||
JOIN pg_namespace n ON n.oid = t.typnamespace
|
||||
WHERE t.typname = 'premiumtokenpurchasestatus'
|
||||
AND n.nspname = current_schema()
|
||||
)
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM pg_type t
|
||||
JOIN pg_namespace n ON n.oid = t.typnamespace
|
||||
WHERE t.typname = 'creditpurchasestatus'
|
||||
AND n.nspname = current_schema()
|
||||
)
|
||||
THEN
|
||||
ALTER TYPE premiumtokenpurchasestatus RENAME TO creditpurchasestatus;
|
||||
END IF;
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@ def _column_exists(conn, table: str, column: str) -> bool:
|
|||
conn.execute(
|
||||
sa.text(
|
||||
"SELECT 1 FROM information_schema.columns "
|
||||
"WHERE table_name = :tbl AND column_name = :col"
|
||||
"WHERE table_name = :tbl AND column_name = :col "
|
||||
"AND table_schema = current_schema()"
|
||||
),
|
||||
{"tbl": table, "col": column},
|
||||
).fetchone()
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ from app.db import PagePurchaseStatus
|
|||
class CreateCreditCheckoutSessionRequest(BaseModel):
|
||||
"""Request body for creating a credit-purchase checkout session."""
|
||||
|
||||
quantity: int = Field(ge=1, le=100)
|
||||
quantity: int = Field(ge=1, le=10_000)
|
||||
search_space_id: int = Field(ge=1)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue