feat(state): replace in-memory Map with SQLite-backed stateService (#59)

- Create src/services/stateService.js with get/set/delete/has API
- Create migration 004_user_states.js (chat_id PK, state_data JSON, updated_at)
- TTL of 24 hours — expired states auto-deleted
- Cleanup job runs every hour (setInterval)
- Replace src/context/userStates.js Map with async stateService proxy
- Add await to all 45 userStates.get/set/delete/has calls across 13 files
- Add initStates() call in index.js startup sequence
- All state survives bot restarts now

18 files changed, 172 insertions, 46 deletions
This commit is contained in:
NW
2026-06-22 10:02:57 +01:00
parent ce1b6003cb
commit a04e60d751
18 changed files with 172 additions and 46 deletions

View File

@@ -38,6 +38,7 @@ export async function runMigrations() {
(await import('./001_initial_schema.js')).default,
(await import('./002_add_columns.js')).default,
(await import('./003_add_indexes.js')).default,
(await import('./004_user_states.js')).default,
];
for (let i = currentVersion; i < migrations.length; i++) {