- 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
27 lines
834 B
SQL
27 lines
834 B
SQL
CREATE TABLE IF NOT EXISTS events (
|
|
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_chat_occurred
|
|
ON events(chat_id, occurred_at);
|
|
|
|
CREATE TABLE IF NOT EXISTS settings (
|
|
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 (
|
|
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()),
|
|
PRIMARY KEY (chat_id, date)
|
|
);
|