Database Synchronization
Sunschool’s database sync feature allows parents to replicate their account data and all associated learner information to an external PostgreSQL database. This provides data ownership, backup, and integration capabilities.What is Database Sync?
Database sync creates a complete copy of your Sunschool data in a PostgreSQL database that you control. This includes:- User accounts (parent and all learners)
- Learner profiles and settings
- Complete lesson history
- Achievements and progress
- Points and rewards data
- All relationships and metadata
Access Requirements
Fromdatabase-sync-page.tsx:222-232:
Creating a Sync Configuration
Required Information
You need a PostgreSQL connection string in this format:The Configuration Form
Fromdatabase-sync-page.tsx:242-295:
URL Validation
The form validates your database URL before submitting: Fromdatabase-sync-page.tsx:161-172:
Enter Database URL
Provide the connection string for your PostgreSQL database
The database must be accessible from Sunschool’s server. Use public hostnames or IPs, not localhost.
Choose Sync Mode
Manual Sync - You trigger syncs when neededContinuous Sync - Automatic syncs at regular intervals
Sync Modes
Manual Sync
With manual sync (continuousSync = false):- You control when data is replicated
- Click the refresh icon to initiate a sync
- Useful for periodic backups
- No automatic updates
database-sync-page.tsx:156-158:
Continuous Sync
With continuous sync enabled:- Automatic synchronization runs periodically
- Your data is always up-to-date
- Ideal for real-time integration
- Minimal manual intervention
Sync Status
Configurations have four possible statuses:IDLE
Gray badgeNo sync in progress, waiting for trigger
IN_PROGRESS
Blue badgeSync currently running, data being replicated
COMPLETED
Green badgeLast sync finished successfully
FAILED
Red badgeLast sync encountered an error
database-sync-page.tsx:185-214:
Running a Sync
Manual Trigger
Click the refresh icon on any configuration card to start a sync: Fromdatabase-sync-page.tsx:87-124:
What Gets Synced
Fromserver/sync-utils.ts (referenced in routes), the sync process:
- Establishes connection to target database
- Creates schema if it doesn’t exist
- Replicates tables:
- Users (parent and learners)
- Learner profiles
- Lessons
- Achievements
- Points transactions
- Rewards and redemptions
- Maintains relationships (foreign keys)
- Updates sync timestamp and status
Syncs are incremental when possible, only copying new or changed data to reduce transfer time.
Monitoring Sync Progress
The UI shows detailed sync information: Fromdatabase-sync-page.tsx:306-357:
Managing Configurations
Editing
Click the edit icon to modify:- Database URL
- Continuous sync setting
database-sync-page.tsx:135-141:
Deleting
Remove a configuration after confirmation: Fromdatabase-sync-page.tsx:143-153:
Server-Side Implementation
Fromserver/routes.ts:1413-1455, the sync endpoints:
Get All Configurations
Create Configuration
Push Sync
Use Cases
Data Backup
Data Backup
Maintain a complete backup of your Sunschool data:
- Protect against accidental deletion
- Preserve learning history
- Enable data recovery
- Comply with data retention policies
Data Integration
Data Integration
Connect Sunschool data with other systems:
- Import into business intelligence tools
- Integrate with school management systems
- Build custom reports and dashboards
- Analyze learning patterns
Data Ownership
Data Ownership
Maintain full control of your data:
- Keep data on your infrastructure
- Meet organizational data policies
- Enable compliance audits
- Support data portability requirements
Advanced Analytics
Advanced Analytics
Perform complex analysis:
- Run custom SQL queries
- Build machine learning models
- Generate specialized reports
- Track long-term trends
Best Practices
Test First
Create a test database first to verify your configuration works before using production databases.
Secure Connections
Use SSL/TLS for database connections:
Monitor Status
Check sync status regularly, especially for continuous sync configurations.
Backup Credentials
Store your database credentials securely. Sunschool encrypts them but keep a backup.
Troubleshooting
Sync fails immediately
Sync fails immediately
Check:
- Database URL format is correct
- Database is accessible from Sunschool server
- Credentials are valid
- Database exists and you have write permissions
- Firewall allows connections
Sync hangs at IN_PROGRESS
Sync hangs at IN_PROGRESS
This might indicate:
- Network connectivity issues
- Very large dataset (first sync takes longer)
- Database performance problems
- Connection timeout
Error: schema mismatch
Error: schema mismatch
The target database schema doesn’t match expected structure:
- Let Sunschool create the schema automatically
- Or manually create tables using provided schema
- Don’t modify table structures in target database
Continuous sync not updating
Continuous sync not updating
Verify:
- Continuous sync is actually enabled
- Last sync shows recent timestamp
- No error messages in configuration
- Database is still accessible