CBV01 commited on
Commit
91381bf
·
1 Parent(s): 633cebc

Fix internal server error on plan update and sync tier limits with user request

Browse files
Files changed (1) hide show
  1. backend/database.py +16 -3
backend/database.py CHANGED
@@ -405,17 +405,30 @@ def init_db():
405
  except:
406
  pass
407
 
408
- # Seed default plans
 
 
 
 
 
 
 
 
 
 
 
 
409
  default_plans = [
410
  ("free", "Free Starter", 0, 20, 1, 5, 50, 1, 0, json.dumps(["20 Daily Campaigns", "1 Template", "5 Scrape Keywords", "Basic Support"])),
411
  ("basic", "Growth Basic", 3000, 50, 2, 10, 100, 1, 1, json.dumps(["50 Daily Campaigns", "1 Template", "10 Scrape Keywords", "Priority Support"])),
412
  ("standard", "Pro Standard", 7500, 150, 5, 25, 250, 2, 1, json.dumps(["150 Daily Campaigns", "2 Templates", "25 Scrape Keywords", "24/7 Support", "Ad-Free Experience"])),
413
- ("premium", "Enterprise Premium", 15000, 300, 10, 50, 500, 3, 1, json.dumps(["300 Daily Campaigns", "3 Templates", "Unlimited Keywords", "Dedicated Manager"])),
414
  ("unlimited", "Owner Unlimited", 0, 999999, 99, 999999, 1000, 999, 1, json.dumps(["Absolute Control", "999 Templates", "Admin Privilege"]))
415
  ]
416
  for p in default_plans:
 
417
  conn.execute(
418
- "INSERT OR IGNORE INTO plans (key, name, price, max_daily_campaigns, max_accounts, max_daily_keywords, scrape_limit, max_templates, has_premium_access, perks) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
419
  p
420
  )
421
 
 
405
  except:
406
  pass
407
 
408
+ # Migration for plans table: max_templates
409
+ try:
410
+ conn.execute("ALTER TABLE plans ADD COLUMN max_templates INTEGER DEFAULT 1")
411
+ except:
412
+ pass
413
+
414
+ # Migration for users table: max_templates
415
+ try:
416
+ conn.execute("ALTER TABLE users ADD COLUMN max_templates INTEGER DEFAULT 1")
417
+ except:
418
+ pass
419
+
420
+ # Update seeding to match user's explicit request: Free(1), Basic(1), Standard(2), Premium(2), Unlimited(999)
421
  default_plans = [
422
  ("free", "Free Starter", 0, 20, 1, 5, 50, 1, 0, json.dumps(["20 Daily Campaigns", "1 Template", "5 Scrape Keywords", "Basic Support"])),
423
  ("basic", "Growth Basic", 3000, 50, 2, 10, 100, 1, 1, json.dumps(["50 Daily Campaigns", "1 Template", "10 Scrape Keywords", "Priority Support"])),
424
  ("standard", "Pro Standard", 7500, 150, 5, 25, 250, 2, 1, json.dumps(["150 Daily Campaigns", "2 Templates", "25 Scrape Keywords", "24/7 Support", "Ad-Free Experience"])),
425
+ ("premium", "Enterprise Premium", 15000, 300, 10, 50, 500, 2, 1, json.dumps(["300 Daily Campaigns", "2 Templates", "Unlimited Keywords", "Dedicated Manager"])),
426
  ("unlimited", "Owner Unlimited", 0, 999999, 99, 999999, 1000, 999, 1, json.dumps(["Absolute Control", "999 Templates", "Admin Privilege"]))
427
  ]
428
  for p in default_plans:
429
+ # Use INSERT OR REPLACE if the key matches, to force update existing seeds
430
  conn.execute(
431
+ "INSERT OR REPLACE INTO plans (key, name, price, max_daily_campaigns, max_accounts, max_daily_keywords, scrape_limit, max_templates, has_premium_access, perks) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
432
  p
433
  )
434