3.1 KiB
3.1 KiB
Database Migration: MongoDB to SQLite
✅ Migration Complete!
Your Deathwatch roller application has been successfully migrated from MongoDB to SQLite.
What Was Done
- Data Export: All player data was exported from MongoDB to a backup file
- SQLite Setup: Created SQLite database with proper schema
- Data Migration: Transferred all players and their data to SQLite
- API Update: Updated server routes to use SQLite instead of MongoDB
Migration Results
- Total players migrated: 3
- Players: christoffer, claes, phillip
- Data preserved: All player info, requisition points, inventory data
- Backup created:
mongo-backup.json(safely stores original data)
Files Created/Modified
New Files:
sqlite-db.js- SQLite database handlerroutes/playerRoutes-sqlite.js- Updated API routes for SQLiteserver-sqlite.js- SQLite server configurationmigrate-to-sqlite.js- Migration scriptswitch-db.sh- Database switching utilitymongo-backup.json- Complete backup of MongoDB datasqlite/deathwatch.db- SQLite database file
Modified Files:
server.js- Now uses SQLite (MongoDB version backed up asserver-mongo-backup.js)package.json- Added convenience scripts
Usage
Current Status
- ✅ SQLite is active
- ✅ Server running on port 3005 (or PORT env variable)
- ✅ All data migrated successfully
New NPM Scripts
npm run server # Start the server
npm run db:sqlite # Switch to SQLite (current)
npm run db:mongo # Switch back to MongoDB
npm run db:migrate # Re-run migration
npm run db:export # Export MongoDB data only
Manual Operations
# Switch to SQLite
cd database && ./switch-db.sh sqlite
# Switch to MongoDB
cd database && ./switch-db.sh mongo
# Re-run migration
cd database && node migrate-to-sqlite.js
# Start server
cd database && node server.js
Benefits of SQLite
- Simpler Deployment: No separate database service needed
- Single File Database: Easy backups and transfers
- Better for Small Apps: Perfect for gaming groups
- Zero Configuration: Works out of the box
- ACID Compliant: Reliable data integrity
Data Structure
The SQLite database maintains the same structure as MongoDB:
playerstable with JSON columns forrollerInfo,shopInfo,tabInfo- All existing player data preserved
- Password hashing maintained
- Timestamps added for better tracking
Rollback
If you need to go back to MongoDB:
npm run db:mongo
This will restore your original MongoDB configuration. Your MongoDB data is unchanged.
File Locations
- SQLite Database:
database/sqlite/deathwatch.db - MongoDB Backup:
database/mongo-backup.json - Server Logs:
database/backend.log
API Compatibility
The API endpoints remain exactly the same:
GET /api/players- List all playersGET /api/players/:name- Get specific playerPUT /api/players/:name- Update playerPOST /api/players- Create playerDELETE /api/players/:name- Delete player
Your frontend (React app) requires no changes.