-- ============================================================
--  Break the Locks — Part 7 (Habits & Triggers) Schema
--  Run once in phpMyAdmin on the admin_btlc database.
-- ============================================================

CREATE TABLE IF NOT EXISTS `user_lock_habits` (
  `id`         INT AUTO_INCREMENT PRIMARY KEY,
  `user_id`    INT NOT NULL,
  `lock_id`    INT NOT NULL,
  `text`       VARCHAR(500) NOT NULL,
  `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  INDEX `idx_user_lock` (`user_id`, `lock_id`),
  INDEX `idx_user` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


CREATE TABLE IF NOT EXISTS `user_lock_habit_triggers` (
  `id`         INT AUTO_INCREMENT PRIMARY KEY,
  `habit_id`   INT NOT NULL,
  `user_id`    INT NOT NULL,  -- redundant but cheap; keeps ownership checks easy
  `text`       VARCHAR(500) NOT NULL,
  `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  INDEX `idx_habit` (`habit_id`),
  INDEX `idx_user` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
