Overview
RaidBot originally stored data in JSON files but now uses SQLite for better performance, reliability, and data integrity. This migration script automatically imports your existing data.Migration Script
The migration script is located atdb/migrate.js and handles the complete data transition.
Running the Migration
What Gets Migrated
The script migrates data from 11 JSON files to SQLite tables:Guild Configs
raid_channels.json, museum_channels.json, audit_channels.json, guild_settings.json → guilds tableActive Raids
active_raids.json → raids and signups tablesStatistics
raid_stats.json → user_stats and guild_user_stats tablesPermissions
admin_roles.json, command_permissions.json, signup_roles.json → permission tablesAvailability
availability.json → availability tableTemplates
template_overrides.json → template_overrides and custom_templates tablesMigration Process
Step 1: Schema Initialization
The script first initializes the SQLite schema:Step 2: Guild Configuration
Merges data from multiple JSON files into theguilds table:
Step 3: Active Raids & Signups
Migrates raid posts and all associated signups:The migration normalizes nested signup structures into flat database rows with foreign keys.
Step 4: User Statistics
Migrates both global and per-guild statistics:Step 5: Permissions
Migrates admin roles, command permissions, and signup requirements:Step 6: Availability
Migrates user availability schedules:Step 7: Templates
Migrates template overrides and custom templates:Step 8: Backup Original Files
After successful migration, JSON files are renamed:Transaction Safety
All migrations run inside a single transaction for atomicity:If any step fails, the entire migration is rolled back and the database remains unchanged.
Migration Output
Successful migration displays a detailed summary:Verification
After migration, verify data integrity:Check Record Counts
Query Sample Data
Compare Counts
Compare JSON record counts with database:Troubleshooting
Migration Fails Partway
Problem: Error during migration process Solution: The transaction ensures no partial data is committed. Fix the error and re-run:Missing JSON Files
Problem: Some JSON files don’t exist Solution: This is normal. The migration script handles missing files gracefully:Corrupted JSON
Problem: JSON parse error during migration Solution: Fix the corrupted JSON file manually or restore from backup before migrating.Data Loss Concerns
Problem: Want to verify no data was lost Solution: JSON files are preserved as.json.migrated backups. Compare record counts and spot-check critical data.
Reverting Migration
If you need to revert to JSON files:Post-Migration
After successful migration:- Test thoroughly - Verify all bot functionality works
- Monitor logs - Watch for any database-related errors
- Keep backups - Store
.json.migratedfiles safely for a few weeks - Update monitoring - Enable database performance monitoring
- Document changes - Note the migration date for your records
Best Practices
- Backup first - Always create backups before migrating
- Test migration - Run on a test server before production
- Verify data - Check critical records after migration
- Monitor performance - Watch database metrics post-migration
- Keep backups - Retain JSON backups for rollback capability
- Schedule downtime - Migrate during low-usage periods
See Also
- Database Architecture - Understanding the SQLite schema
- Configuration - Database configuration options
- Monitoring - Track migration performance