This document describes the migration from JSON-based command storage to SQLite database storage.
- Commands stored in individual JSON files in
commands/directory - User data stored in
userdb.json - Custom JSON library (
JsonStructureLib) used for parsing - No caching - files read on every command execution
- All data stored in
prod.dbSQLite database - Built-in caching system for improved performance
- Standard SQLite JDBC driver
- Automatic migration from existing JSON files
CREATE TABLE commands ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE NOT NULL, description TEXT, data TEXT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP );
CREATE TABLE aliases ( id INTEGER PRIMARY KEY AUTOINCREMENT, command_id INTEGER NOT NULL, alias TEXT UNIQUE NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (command_id) REFERENCES commands (id) ON DELETE CASCADE );
CREATE TABLE users ( user_id TEXT PRIMARY KEY, paste_site TEXT DEFAULT 'mclogs', created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP );
-
Automatic Migration: On first startup, the bot will automatically:
- Create the SQLite database (
prod.db) - Migrate all existing commands from JSON files
- Migrate user data from
userdb.json - Load everything into memory cache
- Create the SQLite database (
-
Backup: Original JSON files are preserved (not automatically backed up, but can be manually backed up)
- Caching: All commands and aliases are loaded into memory on startup
- Database Queries: Optimized SQL queries with proper indexing
- Reduced I/O: No more file system reads on every command execution
org.xerial:sqlite-jdbc:3.44.1.0- SQLite JDBC drivercom.google.code.gson:gson:2.10.1- For JSON migration (temporary)
DatabaseManager.java- New database management class with cachingCommandMigrator.java- Migration utility for JSON to database
CommandCache.java- Now uses database instead of JSON filesRegisterNewCommand.java- Creates commands in databaseAliasCommand.java- Manages aliases in databaseDeleteCommand.java- Deletes commands from databaseDescriptionCommand.java- Updates command descriptions in databaseUserDB.java- Now uses database for user data
build.gradle- Added SQLite and Gson dependenciesMain.java- Added migration initialization
The bot will work exactly the same as before from a user perspective. All existing commands will continue to work:
!register <name> <content>- Register new commands!alias <command> <alias1> <alias2>...- Add aliases to commands!delete <command>- Delete commands!description <command> "<description>"- Update command descriptions
The database file prod.db will be created in the project root directory. This file contains all command and user data and should be backed up regularly.
If you need to rollback to JSON-based storage:
- Stop the bot
- Delete
prod.db - Restore JSON files from backup
- Revert the code changes
- Restart the bot
- The database is self-contained in
prod.db - No external database server required
- Automatic indexing for optimal performance
- Foreign key constraints ensure data integrity