170 lines
6.2 KiB
Python
170 lines
6.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Script to initialize default pricing plans in the database.
|
|
This should be run on a MASTER instance only.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
from app import app, db
|
|
from models import PricingPlan, User
|
|
|
|
def init_pricing_plans():
|
|
"""Initialize default pricing plans"""
|
|
|
|
# Check if this is a MASTER instance
|
|
if os.environ.get('MASTER', 'false').lower() != 'true':
|
|
print("Error: This script should only be run on a MASTER instance.")
|
|
print("Set MASTER=true environment variable to run this script.")
|
|
sys.exit(1)
|
|
|
|
with app.app_context():
|
|
# Check if pricing plans already exist
|
|
existing_plans = PricingPlan.query.count()
|
|
if existing_plans > 0:
|
|
print(f"Found {existing_plans} existing pricing plans. Skipping initialization.")
|
|
return
|
|
|
|
# Get the first admin user
|
|
admin_user = User.query.filter_by(is_admin=True).first()
|
|
if not admin_user:
|
|
print("Error: No admin user found. Please create an admin user first.")
|
|
sys.exit(1)
|
|
|
|
# Default pricing plans
|
|
default_plans = [
|
|
{
|
|
'name': 'Starter',
|
|
'description': 'Perfect for small teams getting started',
|
|
'monthly_price': 29.0,
|
|
'annual_price': 23.0,
|
|
'features': [
|
|
'Up to 5 rooms',
|
|
'Up to 10 conversations',
|
|
'10GB storage',
|
|
'Up to 10 managers',
|
|
'Email support'
|
|
],
|
|
'button_text': 'Get Started',
|
|
'button_url': '#',
|
|
'is_popular': False,
|
|
'is_custom': False,
|
|
'is_active': True,
|
|
'order_index': 1,
|
|
'room_quota': 5,
|
|
'conversation_quota': 10,
|
|
'storage_quota_gb': 10,
|
|
'manager_quota': 10,
|
|
'admin_quota': 1
|
|
},
|
|
{
|
|
'name': 'Professional',
|
|
'description': 'Ideal for growing businesses',
|
|
'monthly_price': 99.0,
|
|
'annual_price': 79.0,
|
|
'features': [
|
|
'Up to 25 rooms',
|
|
'Up to 50 conversations',
|
|
'100GB storage',
|
|
'Up to 50 managers',
|
|
'Priority support'
|
|
],
|
|
'button_text': 'Get Started',
|
|
'button_url': '#',
|
|
'is_popular': True,
|
|
'is_custom': False,
|
|
'is_active': True,
|
|
'order_index': 2,
|
|
'room_quota': 25,
|
|
'conversation_quota': 50,
|
|
'storage_quota_gb': 100,
|
|
'manager_quota': 50,
|
|
'admin_quota': 3
|
|
},
|
|
{
|
|
'name': 'Enterprise',
|
|
'description': 'For large organizations with advanced needs',
|
|
'monthly_price': 299.0,
|
|
'annual_price': 239.0,
|
|
'features': [
|
|
'Up to 100 rooms',
|
|
'Up to 200 conversations',
|
|
'500GB storage',
|
|
'Up to 200 managers',
|
|
'24/7 dedicated support'
|
|
],
|
|
'button_text': 'Get Started',
|
|
'button_url': '#',
|
|
'is_popular': False,
|
|
'is_custom': False,
|
|
'is_active': True,
|
|
'order_index': 3,
|
|
'room_quota': 100,
|
|
'conversation_quota': 200,
|
|
'storage_quota_gb': 500,
|
|
'manager_quota': 200,
|
|
'admin_quota': 10
|
|
},
|
|
{
|
|
'name': 'Custom',
|
|
'description': 'Tailored solutions for enterprise customers',
|
|
'monthly_price': 0.0,
|
|
'annual_price': 0.0,
|
|
'features': [
|
|
'Unlimited rooms',
|
|
'Unlimited conversations',
|
|
'Unlimited storage',
|
|
'Unlimited users',
|
|
'Custom integrations',
|
|
'Dedicated account manager'
|
|
],
|
|
'button_text': 'Contact Sales',
|
|
'button_url': '#',
|
|
'is_popular': False,
|
|
'is_custom': True,
|
|
'is_active': True,
|
|
'order_index': 4,
|
|
'room_quota': 0,
|
|
'conversation_quota': 0,
|
|
'storage_quota_gb': 0,
|
|
'manager_quota': 0,
|
|
'admin_quota': 0
|
|
}
|
|
]
|
|
|
|
# Create pricing plans
|
|
for plan_data in default_plans:
|
|
plan = PricingPlan(
|
|
name=plan_data['name'],
|
|
description=plan_data['description'],
|
|
monthly_price=plan_data['monthly_price'],
|
|
annual_price=plan_data['annual_price'],
|
|
features=plan_data['features'],
|
|
button_text=plan_data['button_text'],
|
|
button_url=plan_data['button_url'],
|
|
is_popular=plan_data['is_popular'],
|
|
is_custom=plan_data['is_custom'],
|
|
is_active=plan_data['is_active'],
|
|
order_index=plan_data['order_index'],
|
|
room_quota=plan_data['room_quota'],
|
|
conversation_quota=plan_data['conversation_quota'],
|
|
storage_quota_gb=plan_data['storage_quota_gb'],
|
|
manager_quota=plan_data['manager_quota'],
|
|
admin_quota=plan_data['admin_quota'],
|
|
created_by=admin_user.id
|
|
)
|
|
db.session.add(plan)
|
|
|
|
try:
|
|
db.session.commit()
|
|
print("Successfully created default pricing plans:")
|
|
for plan_data in default_plans:
|
|
print(f" - {plan_data['name']}: €{plan_data['monthly_price']}/month")
|
|
print("\nYou can now configure these plans in the admin settings.")
|
|
except Exception as e:
|
|
db.session.rollback()
|
|
print(f"Error creating pricing plans: {e}")
|
|
sys.exit(1)
|
|
|
|
if __name__ == '__main__':
|
|
init_pricing_plans() |