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.

40 lines
1.1 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 NOT NULL
);
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 (
phone_number TEXT PRIMARY KEY,
wa_id TEXT NOT NULL, -- WhatsApp's @s.whatsapp.net ID
name TEXT,
last_seen TIMESTAMP
);
CREATE TABLE IF NOT EXISTS groups (
id TEXT PRIMARY KEY,
community_id TEXT NOT NULL,
name TEXT
);
`);
}