feat: multi-user isolation and graceful shutdown
- Add chat_id to events, settings, and days_off for per-user data - Add proper graceful shutdown (signal handling, WaitGroup) - Separate polling and webhook modes with goroutine management - Add schema migration from single-user to multi-user schema - Refactor handlers with shared actionFunc pattern (msg + callback) - Fix schema path for Docker deployment (/app/db/schema.sql) - Remove emoji from output text for cleaner formatting
This commit is contained in:
@@ -1,26 +1,26 @@
|
||||
CREATE TABLE IF NOT EXISTS events (
|
||||
id INTEGER PRIMARY KEY,
|
||||
event_type TEXT NOT NULL
|
||||
CHECK (event_type IN ('in', 'out')),
|
||||
occurred_at INTEGER NOT NULL UNIQUE
|
||||
CHECK (occurred_at > 0),
|
||||
note TEXT NOT NULL DEFAULT '',
|
||||
created_at INTEGER NOT NULL
|
||||
DEFAULT (unixepoch())
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
chat_id INTEGER NOT NULL,
|
||||
event_type TEXT NOT NULL CHECK (event_type IN ('in', 'out')),
|
||||
occurred_at INTEGER NOT NULL CHECK (occurred_at > 0),
|
||||
note TEXT NOT NULL DEFAULT '',
|
||||
created_at INTEGER NOT NULL DEFAULT (unixepoch())
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_events_occurred_at
|
||||
ON events(occurred_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_events_chat_occurred
|
||||
ON events(chat_id, occurred_at);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS settings (
|
||||
key TEXT PRIMARY KEY,
|
||||
value TEXT NOT NULL DEFAULT ''
|
||||
chat_id INTEGER NOT NULL,
|
||||
key TEXT NOT NULL,
|
||||
value TEXT NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (chat_id, key)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS days_off (
|
||||
date TEXT PRIMARY KEY
|
||||
CHECK (date = strftime('%Y-%m-%d', date)),
|
||||
chat_id INTEGER NOT NULL,
|
||||
date TEXT NOT NULL CHECK (date = strftime('%Y-%m-%d', date)),
|
||||
reason TEXT NOT NULL DEFAULT '',
|
||||
created_at INTEGER NOT NULL
|
||||
DEFAULT (unixepoch())
|
||||
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
||||
PRIMARY KEY (chat_id, date)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user