refactor: update database schema to use phone numbers and add timestamps

main
brobert (aider) 3 months ago
parent dc3b2482f2
commit 97c23f1833

@ -1,21 +1,33 @@
-- Tasks table
-- Groups table with participant caching
CREATE TABLE IF NOT EXISTS groups (
id TEXT PRIMARY KEY, -- WhatsApp group ID
name TEXT NOT NULL DEFAULT 'Unnamed group',
participants TEXT NOT NULL, -- JSON array of phone numbers
linked_parent TEXT, -- Parent community ID
last_updated TEXT -- ISO 8601 timestamp of last update
);
-- Tasks table with phone number assignments
CREATE TABLE IF NOT EXISTS tasks (
id INTEGER PRIMARY KEY AUTOINCREMENT,
description TEXT NOT NULL,
assigned_to TEXT, -- WhatsApp user ID or phone number
assigned_to TEXT NOT NULL, -- WhatsApp phone number
due_date TEXT, -- ISO 8601 date string (e.g., "2023-10-31")
completed BOOLEAN DEFAULT FALSE
completed BOOLEAN NOT NULL DEFAULT FALSE,
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- Groups table
CREATE TABLE IF NOT EXISTS groups (
id TEXT PRIMARY KEY, -- WhatsApp group ID
name TEXT NOT NULL DEFAULT 'Unnamed group',
linked_parent TEXT -- Parent community ID
);
-- Users table (optional, for future use)
-- Users table for name mapping
CREATE TABLE IF NOT EXISTS users (
id TEXT PRIMARY KEY, -- WhatsApp user ID or phone number
name TEXT NOT NULL
phone_number TEXT PRIMARY KEY, -- WhatsApp phone number
name TEXT NOT NULL,
last_seen TEXT -- ISO 8601 timestamp of last activity
);
-- Create triggers for task timestamps
CREATE TRIGGER IF NOT EXISTS update_task_timestamp
AFTER UPDATE ON tasks
BEGIN
UPDATE tasks SET updated_at = CURRENT_TIMESTAMP WHERE id = NEW.id;
END;

Loading…
Cancel
Save