This guide will walk you through setting up and deploying the Combat Log Analyzer.
pnpm installFirst, create a new D1 database:
pnpm wrangler d1 create combat-logs-dbYou'll see output like this:
✅ Successfully created DB 'combat-logs-db'!
[[d1_databases]]
binding = "DB"
database_name = "combat-logs-db"
database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
Important: Copy the database_id value!
Open wrangler.jsonc and replace YOUR_DATABASE_ID with your actual database ID:
Migrations are auto-generated from the Drizzle schema. Apply them:
For production database:
pnpm db:migrateFor local development database:
pnpm db:migrate:localRecommendation: Run both commands to set up both local and production databases.
Note: If you need to regenerate migrations after schema changes:
pnpm db:generatepnpm cf-typegenThis generates the cloudflare-env.d.ts file with proper types for your D1 binding.
pnpm devVisit http://localhost:3000 to see your app.
Note: In local development mode, the D1 database binding may not work exactly as in production. The app will still function for log analysis, but data won't persist to the database.
- Click "Load Sample 1" or "Load Sample 2" to load example combat logs
- Click "Analyze Combat Log" to see the analysis
- Explore the charts and statistics
pnpm previewThis builds your app and runs it with Wrangler, which provides a more accurate simulation of the Cloudflare Workers environment, including D1 bindings.
pnpm deployThis command will:
- Build your Next.js application
- Adapt it for Cloudflare Workers using OpenNext
- Deploy to Cloudflare's global network
If this is your first deployment, you may need to:
-
Login to Wrangler:
pnpm wrangler login
-
Verify your account: Follow the browser prompts to authenticate
-
Deploy:
pnpm deploy
After the first deployment, simply run:
pnpm deployAfter deployment, you'll see output like:
Uploaded combat-log-analyzer (X.XX sec)
Published combat-log-analyzer (X.XX sec)
https://combat-log-analyzer.your-subdomain.workers.dev
Current Deployment ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Visit the URL to see your live application!
To query your production database:
pnpm wrangler d1 execute combat-logs-db --command="SELECT * FROM combat_sessions LIMIT 10"To query your local database:
pnpm wrangler d1 execute combat-logs-db --local --command="SELECT * FROM combat_sessions LIMIT 10"pnpm wrangler d1 backup create combat-logs-dbpnpm wrangler d1 backup list combat-logs-dbSolution: Make sure you've:
- Created the D1 database
- Updated
wrangler.jsoncwith the correctdatabase_id - Run the schema initialization
- Generated types with
pnpm cf-typegen
Solution: Drop and recreate the database:
# For local
pnpm wrangler d1 execute combat-logs-db --local --command="DROP TABLE IF EXISTS combat_sessions; DROP TABLE IF EXISTS combat_events; DROP TABLE IF EXISTS player_stats; DROP TABLE IF EXISTS item_usage;"
pnpm wrangler d1 execute combat-logs-db --local --file=./schema.sql
# For production
pnpm wrangler d1 execute combat-logs-db --command="DROP TABLE IF EXISTS combat_sessions; DROP TABLE IF EXISTS combat_events; DROP TABLE IF EXISTS player_stats; DROP TABLE IF EXISTS item_usage;"
pnpm wrangler d1 execute combat-logs-db --file=./schema.sqlSolution:
- Clear Next.js cache:
rm -rf .next - Clear OpenNext output:
rm -rf .open-next - Rebuild:
pnpm build - Deploy again:
pnpm deploy
Solution: Ensure AG Charts packages are installed:
pnpm install ag-charts-community ag-charts-reactFor local development, you can create a .dev.vars file in the project root:
# Add environment variables here if needed
# Example:
# API_KEY=your-api-key
For production, set secrets using Wrangler:
pnpm wrangler secret put API_KEY-
Enable Smart Placement - Uncomment in
wrangler.jsonc:"placement": { "mode": "smart" }
-
Monitor Usage - Check your Cloudflare dashboard for:
- Request counts
- D1 query performance
- Error rates
-
Database Indexing - The schema includes indexes for common queries. Monitor slow queries and add indexes as needed.
- Customize the UI styling in
src/app/globals.css - Add more chart types in
src/components/ - Extend the log parser for additional game events
- Add user authentication
- Implement session history browsing
- Add export functionality (PDF, CSV)
For issues or questions:
- Check the README.md for more details
- Review Cloudflare D1 documentation: https://developers.cloudflare.com/d1/
- Review OpenNext documentation: https://opennext.js.org/cloudflare
Happy analyzing! ⚔️