feat: Add turtle state persistence table for reconnect recovery

This commit is contained in:
MayaTheShy
2026-02-20 02:26:31 -05:00
parent 6e05efa2f0
commit b9023758a6

View File

@@ -7,6 +7,9 @@ const __dirname = path.dirname(__filename);
const db = new Database(path.join(__dirname, 'turtle_control.db'));
// Enable WAL journal mode for better concurrent read/write performance
db.pragma('journal_mode = WAL');
// Initialize database schema
export function initializeDatabase() {
// Turtle homes table
@@ -185,6 +188,16 @@ export function initializeDatabase() {
ON chunks(x, z);
`);
// Turtle state persistence table (for reconnect recovery)
db.exec(`
CREATE TABLE IF NOT EXISTS turtle_state (
turtle_id INTEGER PRIMARY KEY,
state_name TEXT NOT NULL,
state_data TEXT DEFAULT '{}',
updated_at INTEGER NOT NULL
)
`);
console.log('✅ Database initialized');
}