-- Run this if you already imported content_schema.sql before multi-user support

USE fiac_db;

ALTER TABLE notifications
  MODIFY target_type ENUM('all', 'role', 'user', 'users') NOT NULL DEFAULT 'all';

CREATE TABLE IF NOT EXISTS notification_recipients (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  notification_id INT UNSIGNED NOT NULL,
  user_id INT UNSIGNED NOT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  UNIQUE KEY uq_notification_recipient (notification_id, user_id),
  KEY idx_recipient_user (user_id),
  CONSTRAINT fk_recipient_notification FOREIGN KEY (notification_id) REFERENCES notifications (id) ON DELETE CASCADE,
  CONSTRAINT fk_recipient_user FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
