Add database initialization and seeding documentation

- Add comprehensive "Database Initialization & Seeding" section to CLAUDE.md
- Document all 10 steps for fresh database setup
- Include Activepieces platform initialization steps
- Document seed commands for billing, demo data, automation templates
- Add quick reference section with all commands
- Update Activepieces platform/project IDs after fresh setup

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
poduck
2025-12-26 02:34:12 -05:00
parent 2cf156ad36
commit da508da398
2 changed files with 212 additions and 2 deletions

210
CLAUDE.md
View File

@@ -539,6 +539,216 @@ docker compose -f docker-compose.local.yml logs django --tail=100
curl -s "http://lvh.me:8000/api/resources/" | jq curl -s "http://lvh.me:8000/api/resources/" | jq
``` ```
## Database Initialization & Seeding
When resetting the database or setting up a fresh environment, follow these steps in order.
### Step 1: Reset Database (if needed)
```bash
cd /home/poduck/Desktop/smoothschedule/smoothschedule
# Stop all containers and remove volumes (DESTRUCTIVE - removes all data)
docker compose -f docker-compose.local.yml down -v
# Start services fresh
docker compose -f docker-compose.local.yml up -d
```
### Step 2: Create Activepieces Database
The Activepieces service requires its own database:
```bash
docker compose -f docker-compose.local.yml exec postgres psql -U FDuVLuQjfpYzGizTmaTavMcaimqpCMRM -d postgres -c "CREATE DATABASE activepieces;"
```
### Step 3: Initialize Activepieces Platform
Create the initial Activepieces admin user (this auto-creates the platform):
```bash
curl -s -X POST http://localhost:8090/api/v1/authentication/sign-up \
-H "Content-Type: application/json" \
-d '{"email":"admin@smoothschedule.com","password":"Admin123!","firstName":"Admin","lastName":"User","newsLetter":false,"trackEvents":false}'
```
**IMPORTANT:** Update `.envs/.local/.activepieces` with the returned IDs:
- `AP_PLATFORM_ID` - from the `platformId` field in response
- `AP_DEFAULT_PROJECT_ID` - from the `projectId` field in response
Then restart containers to pick up new IDs:
```bash
docker compose -f docker-compose.local.yml restart activepieces django
```
### Step 4: Run Django Migrations
```bash
docker compose -f docker-compose.local.yml exec django python manage.py migrate
```
### Step 5: Seed Billing Catalog
Creates subscription plans (free, starter, growth, pro, enterprise):
```bash
docker compose -f docker-compose.local.yml exec django python manage.py billing_seed_catalog
```
### Step 6: Seed Demo Data
Run the reseed_demo command to create the demo tenant with sample data:
```bash
docker compose -f docker-compose.local.yml exec django python manage.py reseed_demo
```
This creates:
- **Tenant:** "Serenity Salon & Spa" (subdomain: `demo`)
- **Pro subscription** with pink theme branding
- **Staff:** 6 stylists/therapists with salon/spa themed names
- **Services:** 12 salon/spa services (haircuts, coloring, massages, facials, etc.)
- **Resources:** 4 treatment rooms
- **Customers:** 20 sample customers
- **Appointments:** 100 appointments respecting business hours (9am-5pm Mon-Fri)
### Step 7: Create Platform Test Users
The DevQuickLogin component expects these users with password `test123`:
```bash
docker compose -f docker-compose.local.yml exec django python manage.py shell -c "
from smoothschedule.identity.users.models import User
# Platform users (public schema)
users_data = [
('superuser@platform.com', 'Super User', 'superuser', True, True),
('manager@platform.com', 'Platform Manager', 'platform_manager', True, False),
('sales@platform.com', 'Sales Rep', 'platform_sales', True, False),
('support@platform.com', 'Support Agent', 'platform_support', True, False),
]
for email, name, role, is_staff, is_superuser in users_data:
user, created = User.objects.get_or_create(
email=email,
defaults={
'username': email,
'name': name,
'role': role,
'is_staff': is_staff,
'is_superuser': is_superuser,
'is_active': True,
}
)
if created:
user.set_password('test123')
user.save()
print(f'Created: {email}')
else:
print(f'Exists: {email}')
"
```
### Step 8: Seed Automation Templates
Seeds 8 automation templates to the Activepieces template gallery:
```bash
docker compose -f docker-compose.local.yml exec django python manage.py seed_automation_templates
```
Templates created:
- Appointment Confirmation Email
- SMS Appointment Reminder
- Staff Notification - New Booking
- Cancellation Confirmation Email
- Thank You + Google Review Request
- Win-back Email Campaign
- Google Calendar Sync
- Webhook Notification
### Step 9: Provision Activepieces Connections
Creates SmoothSchedule connections in Activepieces for all tenants:
```bash
docker compose -f docker-compose.local.yml exec django python manage.py provision_ap_connections --force
```
### Step 10: Provision Default Flows
Creates the default email automation flows for each tenant:
```bash
docker compose -f docker-compose.local.yml exec django python manage.py shell -c "
from smoothschedule.identity.core.models import Tenant
from smoothschedule.identity.core.signals import _provision_default_flows_for_tenant
for tenant in Tenant.objects.exclude(schema_name='public'):
print(f'Provisioning default flows for: {tenant.name}')
_provision_default_flows_for_tenant(tenant.id)
print('Done!')
"
```
Default flows created per tenant:
- `appointment_confirmation` - Confirmation email when appointment is booked
- `appointment_reminder` - Reminder based on service settings
- `thank_you` - Thank you email after final payment
- `payment_deposit` - Deposit payment confirmation
- `payment_final` - Final payment confirmation
### Quick Reference: All Seed Commands
```bash
cd /home/poduck/Desktop/smoothschedule/smoothschedule
# 1. Create Activepieces database
docker compose -f docker-compose.local.yml exec postgres psql -U FDuVLuQjfpYzGizTmaTavMcaimqpCMRM -d postgres -c "CREATE DATABASE activepieces;"
# 2. Run migrations
docker compose -f docker-compose.local.yml exec django python manage.py migrate
# 3. Seed billing plans
docker compose -f docker-compose.local.yml exec django python manage.py billing_seed_catalog
# 4. Seed demo tenant with data
docker compose -f docker-compose.local.yml exec django python manage.py reseed_demo
# 5. Seed automation templates
docker compose -f docker-compose.local.yml exec django python manage.py seed_automation_templates
# 6. Provision Activepieces connections
docker compose -f docker-compose.local.yml exec django python manage.py provision_ap_connections --force
# 7. Provision default flows (run in Django shell - see Step 10 above)
```
### Verifying Setup
After seeding, verify everything is working:
```bash
# Check all services are running
docker compose -f docker-compose.local.yml ps
# Check Activepieces health
curl -s http://localhost:8090/api/v1/health
# Test login
curl -s http://api.lvh.me:8000/auth/login/ -X POST \
-H "Content-Type: application/json" \
-d '{"email":"owner@demo.com","password":"test123"}'
# Check flows exist in Activepieces
docker compose -f docker-compose.local.yml exec postgres psql -U FDuVLuQjfpYzGizTmaTavMcaimqpCMRM -d activepieces -c "SELECT id, status FROM flow;"
```
Access the application at:
- **Demo tenant:** http://demo.lvh.me:5173
- **Platform:** http://platform.lvh.me:5173
## Git Branch ## Git Branch
Currently on: `feature/platform-superuser-ui` Currently on: `feature/platform-superuser-ui`
Main branch: `main` Main branch: `main`

View File

@@ -10,8 +10,8 @@ AP_JWT_SECRET=aa8b396f27cee3d5d07961ca194e69889db699000bd998317b18402ad3358429
AP_ENCRYPTION_KEY=623d1d2592c77b81d16b060446288b32 AP_ENCRYPTION_KEY=623d1d2592c77b81d16b060446288b32
# Project/Platform IDs (from Activepieces setup - visible in URL when logged in) # Project/Platform IDs (from Activepieces setup - visible in URL when logged in)
AP_DEFAULT_PROJECT_ID=bbwbSJskSKWTVSIJvvmrQ AP_DEFAULT_PROJECT_ID=gbbRHAUGBSXj9tzTxg6in
AP_PLATFORM_ID=oOtq0ptJzbmMgzGn0RcU8 AP_PLATFORM_ID=gEUao9SVJyQZtWX1Mu8Rz
# Database (using same PostgreSQL as SmoothSchedule) # Database (using same PostgreSQL as SmoothSchedule)
AP_POSTGRES_HOST=postgres AP_POSTGRES_HOST=postgres