Make reseed_demo environment-aware for demo domain
- Use settings.DEBUG to detect production vs local environment - Production: demo.smoothschedule.com (https) - Local: demo.lvh.me:5173 (http) - Update existing domain if it doesn't match expected environment 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import random
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
@@ -44,6 +45,20 @@ from smoothschedule.scheduling.schedule.models import (
|
|||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = "Reseed demo tenant with fresh salon/spa data for sales demonstrations"
|
help = "Reseed demo tenant with fresh salon/spa data for sales demonstrations"
|
||||||
|
|
||||||
|
def get_demo_domain(self):
|
||||||
|
"""Get the appropriate demo domain based on environment."""
|
||||||
|
# Check if running in production
|
||||||
|
if hasattr(settings, 'DEBUG') and not settings.DEBUG:
|
||||||
|
return "demo.smoothschedule.com"
|
||||||
|
return "demo.lvh.me"
|
||||||
|
|
||||||
|
def get_demo_url(self):
|
||||||
|
"""Get the full demo URL based on environment."""
|
||||||
|
domain = self.get_demo_domain()
|
||||||
|
if "smoothschedule.com" in domain:
|
||||||
|
return f"https://{domain}"
|
||||||
|
return f"http://{domain}:5173"
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--quiet",
|
"--quiet",
|
||||||
@@ -109,7 +124,7 @@ class Command(BaseCommand):
|
|||||||
self.stdout.write("\n" + "=" * 70)
|
self.stdout.write("\n" + "=" * 70)
|
||||||
self.stdout.write(self.style.SUCCESS(" DEMO RESEED COMPLETE!"))
|
self.stdout.write(self.style.SUCCESS(" DEMO RESEED COMPLETE!"))
|
||||||
self.stdout.write("=" * 70)
|
self.stdout.write("=" * 70)
|
||||||
self.stdout.write("\nAccess URL: http://demo.lvh.me:5173")
|
self.stdout.write(f"\nAccess URL: {self.get_demo_url()}")
|
||||||
self.stdout.write("All passwords: test123\n")
|
self.stdout.write("All passwords: test123\n")
|
||||||
|
|
||||||
def setup_tenant(self):
|
def setup_tenant(self):
|
||||||
@@ -140,13 +155,24 @@ class Command(BaseCommand):
|
|||||||
if not self.quiet:
|
if not self.quiet:
|
||||||
self.stdout.write(f" {self.style.SUCCESS('CREATED')} Demo tenant")
|
self.stdout.write(f" {self.style.SUCCESS('CREATED')} Demo tenant")
|
||||||
|
|
||||||
# Create domain
|
# Create/update domain based on environment
|
||||||
domain, created = Domain.objects.get_or_create(
|
demo_domain = self.get_demo_domain()
|
||||||
domain="demo.lvh.me",
|
|
||||||
defaults={"tenant": tenant, "is_primary": True},
|
# First, check if there's an existing primary domain that needs updating
|
||||||
|
existing_primary = Domain.objects.filter(tenant=tenant, is_primary=True).first()
|
||||||
|
if existing_primary and existing_primary.domain != demo_domain:
|
||||||
|
existing_primary.domain = demo_domain
|
||||||
|
existing_primary.save()
|
||||||
|
if not self.quiet:
|
||||||
|
self.stdout.write(f" {self.style.WARNING('UPDATED')} Domain: {demo_domain}")
|
||||||
|
elif not existing_primary:
|
||||||
|
Domain.objects.create(
|
||||||
|
domain=demo_domain,
|
||||||
|
tenant=tenant,
|
||||||
|
is_primary=True,
|
||||||
)
|
)
|
||||||
if created and not self.quiet:
|
if not self.quiet:
|
||||||
self.stdout.write(f" {self.style.SUCCESS('CREATED')} Domain: demo.lvh.me")
|
self.stdout.write(f" {self.style.SUCCESS('CREATED')} Domain: {demo_domain}")
|
||||||
|
|
||||||
return tenant
|
return tenant
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user