You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { Database } from 'bun:sqlite';
|
|
|
|
export const db = new Database('tasks.db');
|
|
|
|
export function initializeDatabase() {
|
|
db.exec(`
|
|
CREATE TABLE IF NOT EXISTS tasks (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
description TEXT NOT NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
due_date TIMESTAMP NULL,
|
|
completed BOOLEAN DEFAULT FALSE,
|
|
completed_at TIMESTAMP NULL,
|
|
group_id TEXT NULL,
|
|
created_by TEXT NOT NULL,
|
|
FOREIGN KEY (created_by) REFERENCES users(id)
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS task_assignments (
|
|
task_id INTEGER NOT NULL,
|
|
user_id TEXT NOT NULL,
|
|
assigned_by TEXT NOT NULL,
|
|
assigned_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (task_id, user_id),
|
|
FOREIGN KEY (task_id) REFERENCES tasks(id) ON DELETE CASCADE
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS users (
|
|
id TEXT PRIMARY KEY, -- WhatsApp user ID (normalized phone number without +)
|
|
first_seen TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
last_seen TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS groups (
|
|
id TEXT PRIMARY KEY,
|
|
community_id TEXT NOT NULL,
|
|
name TEXT,
|
|
last_verified TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
active BOOLEAN DEFAULT TRUE
|
|
);
|
|
`);
|
|
}
|