migrate_timers.sql 774 B

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