fix: Prevent duplicate subscription creation on admin register
Some checks failed
CI / Frontend Lint & Type Check (push) Has been cancelled
CI / Frontend Build (push) Has been cancelled
CI / Backend Lint (push) Has been cancelled
CI / Backend Tests (push) Has been cancelled
CI / Docker Build (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
Deploy / Build & Push Images (push) Has been cancelled
Deploy / Deploy to Server (push) Has been cancelled
Deploy / Notify (push) Has been cancelled
Some checks failed
CI / Frontend Lint & Type Check (push) Has been cancelled
CI / Frontend Build (push) Has been cancelled
CI / Backend Lint (push) Has been cancelled
CI / Backend Tests (push) Has been cancelled
CI / Docker Build (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
Deploy / Build & Push Images (push) Has been cancelled
Deploy / Deploy to Server (push) Has been cancelled
Deploy / Notify (push) Has been cancelled
- Check if subscription already exists before creating Tycoon subscription for admin users - Fixes UNIQUE constraint failed: subscriptions.user_id error
This commit is contained in:
@ -106,8 +106,15 @@ async def register(
|
|||||||
user.is_verified = True # Auto-verify admins
|
user.is_verified = True # Auto-verify admins
|
||||||
await db.commit()
|
await db.commit()
|
||||||
|
|
||||||
# Give admin Tycoon subscription
|
# Give admin Tycoon subscription (only if no subscription exists)
|
||||||
from app.models.subscription import Subscription, SubscriptionTier, SubscriptionStatus, TIER_CONFIG
|
from app.models.subscription import Subscription, SubscriptionTier, SubscriptionStatus, TIER_CONFIG
|
||||||
|
from sqlalchemy import select
|
||||||
|
|
||||||
|
# Check if subscription already exists
|
||||||
|
existing_sub = await db.execute(
|
||||||
|
select(Subscription).where(Subscription.user_id == user.id)
|
||||||
|
)
|
||||||
|
if not existing_sub.scalar_one_or_none():
|
||||||
tycoon_config = TIER_CONFIG.get(SubscriptionTier.TYCOON, {})
|
tycoon_config = TIER_CONFIG.get(SubscriptionTier.TYCOON, {})
|
||||||
subscription = Subscription(
|
subscription = Subscription(
|
||||||
user_id=user.id,
|
user_id=user.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user