timers_schema.sql 644 B

1234567891011121314151617
  1. -- Create timers table
  2. CREATE TABLE IF NOT EXISTS timers (
  3. id INT AUTO_INCREMENT PRIMARY KEY,
  4. task_id INT NULL,
  5. user_id INT NOT NULL,
  6. start_time DATETIME NOT NULL,
  7. end_time DATETIME NULL,
  8. duration VARCHAR(20) NULL,
  9. description TEXT,
  10. created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  11. updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  12. FOREIGN KEY (task_id) REFERENCES tasks(id) ON DELETE SET NULL,
  13. FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
  14. INDEX idx_user_start (user_id, start_time),
  15. INDEX idx_task_id (task_id),
  16. INDEX idx_end_time (end_time)
  17. );