CREATE TABLE IF NOT EXISTS atlas_accounts (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(190) NOT NULL,
  slug VARCHAR(190) NOT NULL UNIQUE,
  owner_user_id BIGINT UNSIGNED NULL,
  status ENUM('active','suspended','archived') NOT NULL DEFAULT 'active',
  timezone VARCHAR(80) NOT NULL DEFAULT 'Asia/Riyadh',
  language VARCHAR(10) NOT NULL DEFAULT 'ar',
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS atlas_users (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  account_id BIGINT UNSIGNED NOT NULL,
  name VARCHAR(190) NOT NULL,
  email VARCHAR(190) NOT NULL UNIQUE,
  password_hash VARCHAR(255) NOT NULL,
  role ENUM('super_admin','admin','manager','member','viewer') NOT NULL DEFAULT 'member',
  avatar VARCHAR(255) NULL,
  status ENUM('active','inactive','archived') NOT NULL DEFAULT 'active',
  last_login_at DATETIME NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  INDEX idx_users_account (account_id),
  CONSTRAINT fk_users_account FOREIGN KEY (account_id) REFERENCES atlas_accounts(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

ALTER TABLE atlas_accounts ADD CONSTRAINT fk_accounts_owner FOREIGN KEY (owner_user_id) REFERENCES atlas_users(id) ON DELETE SET NULL;

CREATE TABLE IF NOT EXISTS atlas_user_preferences (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  user_id BIGINT UNSIGNED NOT NULL,
  theme_mode VARCHAR(30) NOT NULL DEFAULT 'light',
  sidebar_state VARCHAR(30) NOT NULL DEFAULT 'expanded',
  default_workspace_id BIGINT UNSIGNED NULL,
  date_format VARCHAR(30) NOT NULL DEFAULT 'Y-m-d',
  time_format VARCHAR(30) NOT NULL DEFAULT 'H:i',
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY uq_user_preferences_user (user_id),
  CONSTRAINT fk_preferences_user FOREIGN KEY (user_id) REFERENCES atlas_users(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS atlas_workspaces (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  account_id BIGINT UNSIGNED NOT NULL,
  name VARCHAR(190) NOT NULL,
  slug VARCHAR(190) NOT NULL,
  description TEXT NULL,
  color VARCHAR(30) NULL,
  icon VARCHAR(80) NULL,
  status ENUM('active','paused','archived') NOT NULL DEFAULT 'active',
  sort_order INT NOT NULL DEFAULT 0,
  created_by BIGINT UNSIGNED NULL,
  archived_at DATETIME NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY uq_workspace_slug (account_id, slug),
  INDEX idx_workspaces_account (account_id),
  CONSTRAINT fk_workspaces_account FOREIGN KEY (account_id) REFERENCES atlas_accounts(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS atlas_goals (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  account_id BIGINT UNSIGNED NOT NULL,
  workspace_id BIGINT UNSIGNED NULL,
  title VARCHAR(220) NOT NULL,
  slug VARCHAR(220) NOT NULL,
  description TEXT NULL,
  goal_type VARCHAR(60) NOT NULL DEFAULT 'strategic',
  priority ENUM('low','normal','high','urgent') NOT NULL DEFAULT 'normal',
  status ENUM('not_started','active','paused','completed','archived','cancelled') NOT NULL DEFAULT 'active',
  progress_mode ENUM('auto','manual') NOT NULL DEFAULT 'auto',
  manual_progress TINYINT UNSIGNED NOT NULL DEFAULT 0,
  start_date DATE NULL,
  due_date DATE NULL,
  health_status ENUM('excellent','good','watch','risk','critical') NOT NULL DEFAULT 'good',
  health_score TINYINT UNSIGNED NOT NULL DEFAULT 70,
  last_activity_at DATETIME NULL,
  created_by BIGINT UNSIGNED NULL,
  archived_at DATETIME NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY uq_goal_slug (account_id, slug),
  INDEX idx_goals_account_status (account_id, status),
  INDEX idx_goals_workspace (workspace_id),
  CONSTRAINT fk_goals_account FOREIGN KEY (account_id) REFERENCES atlas_accounts(id) ON DELETE CASCADE,
  CONSTRAINT fk_goals_workspace FOREIGN KEY (workspace_id) REFERENCES atlas_workspaces(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS atlas_projects (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  account_id BIGINT UNSIGNED NOT NULL,
  workspace_id BIGINT UNSIGNED NULL,
  title VARCHAR(220) NOT NULL,
  slug VARCHAR(220) NOT NULL,
  description TEXT NULL,
  status ENUM('planning','active','waiting','deferred','completed','cancelled','archived') NOT NULL DEFAULT 'planning',
  priority ENUM('low','normal','high','urgent') NOT NULL DEFAULT 'normal',
  start_date DATE NULL,
  due_date DATE NULL,
  progress TINYINT UNSIGNED NOT NULL DEFAULT 0,
  health_status ENUM('excellent','good','watch','risk','critical') NOT NULL DEFAULT 'good',
  health_score TINYINT UNSIGNED NOT NULL DEFAULT 70,
  owner_user_id BIGINT UNSIGNED NULL,
  created_by BIGINT UNSIGNED NULL,
  archived_at DATETIME NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY uq_project_slug (account_id, slug),
  INDEX idx_projects_account_status (account_id, status),
  CONSTRAINT fk_projects_account FOREIGN KEY (account_id) REFERENCES atlas_accounts(id) ON DELETE CASCADE,
  CONSTRAINT fk_projects_workspace FOREIGN KEY (workspace_id) REFERENCES atlas_workspaces(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS atlas_goal_project_links (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  goal_id BIGINT UNSIGNED NOT NULL,
  project_id BIGINT UNSIGNED NOT NULL,
  weight TINYINT UNSIGNED NOT NULL DEFAULT 100,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  UNIQUE KEY uq_goal_project (goal_id, project_id),
  CONSTRAINT fk_gpl_goal FOREIGN KEY (goal_id) REFERENCES atlas_goals(id) ON DELETE CASCADE,
  CONSTRAINT fk_gpl_project FOREIGN KEY (project_id) REFERENCES atlas_projects(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS atlas_modules (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  account_id BIGINT UNSIGNED NOT NULL,
  project_id BIGINT UNSIGNED NOT NULL,
  title VARCHAR(220) NOT NULL,
  description TEXT NULL,
  status ENUM('not_started','in_progress','waiting','completed','cancelled','archived') NOT NULL DEFAULT 'not_started',
  sort_order INT NOT NULL DEFAULT 0,
  start_date DATE NULL,
  due_date DATE NULL,
  progress TINYINT UNSIGNED NOT NULL DEFAULT 0,
  created_by BIGINT UNSIGNED NULL,
  archived_at DATETIME NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  INDEX idx_modules_project (project_id),
  CONSTRAINT fk_modules_account FOREIGN KEY (account_id) REFERENCES atlas_accounts(id) ON DELETE CASCADE,
  CONSTRAINT fk_modules_project FOREIGN KEY (project_id) REFERENCES atlas_projects(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS atlas_tasks (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  account_id BIGINT UNSIGNED NOT NULL,
  workspace_id BIGINT UNSIGNED NULL,
  project_id BIGINT UNSIGNED NULL,
  module_id BIGINT UNSIGNED NULL,
  title VARCHAR(240) NOT NULL,
  description TEXT NULL,
  status ENUM('not_started','in_progress','waiting','deferred','completed','cancelled') NOT NULL DEFAULT 'not_started',
  priority ENUM('low','normal','high','urgent') NOT NULL DEFAULT 'normal',
  assigned_to BIGINT UNSIGNED NULL,
  created_by BIGINT UNSIGNED NULL,
  start_date DATE NULL,
  due_date DATE NULL,
  due_time TIME NULL,
  estimated_minutes INT UNSIGNED NULL,
  actual_minutes INT UNSIGNED NULL,
  progress TINYINT UNSIGNED NOT NULL DEFAULT 0,
  is_important TINYINT(1) NOT NULL DEFAULT 0,
  is_focus TINYINT(1) NOT NULL DEFAULT 0,
  completed_at DATETIME NULL,
  cancelled_at DATETIME NULL,
  archived_at DATETIME NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  INDEX idx_tasks_account_status_due (account_id, status, due_date),
  INDEX idx_tasks_project (project_id),
  INDEX idx_tasks_module (module_id),
  CONSTRAINT fk_tasks_account FOREIGN KEY (account_id) REFERENCES atlas_accounts(id) ON DELETE CASCADE,
  CONSTRAINT fk_tasks_workspace FOREIGN KEY (workspace_id) REFERENCES atlas_workspaces(id) ON DELETE SET NULL,
  CONSTRAINT fk_tasks_project FOREIGN KEY (project_id) REFERENCES atlas_projects(id) ON DELETE SET NULL,
  CONSTRAINT fk_tasks_module FOREIGN KEY (module_id) REFERENCES atlas_modules(id) ON DELETE SET NULL,
  CONSTRAINT fk_tasks_assigned FOREIGN KEY (assigned_to) REFERENCES atlas_users(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS atlas_checklist_items (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  task_id BIGINT UNSIGNED NOT NULL,
  title VARCHAR(240) NOT NULL,
  status ENUM('open','completed','cancelled') NOT NULL DEFAULT 'open',
  sort_order INT NOT NULL DEFAULT 0,
  completed_at DATETIME NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  INDEX idx_checklist_task (task_id),
  CONSTRAINT fk_checklist_task FOREIGN KEY (task_id) REFERENCES atlas_tasks(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS atlas_todo_items (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  account_id BIGINT UNSIGNED NOT NULL,
  workspace_id BIGINT UNSIGNED NULL,
  title VARCHAR(240) NOT NULL,
  notes TEXT NULL,
  priority ENUM('low','normal','high','urgent') NOT NULL DEFAULT 'normal',
  status ENUM('open','in_progress','completed','archived','cancelled') NOT NULL DEFAULT 'open',
  due_date DATE NULL,
  due_time TIME NULL,
  recurrence_rule VARCHAR(190) NULL,
  converted_task_id BIGINT UNSIGNED NULL,
  created_by BIGINT UNSIGNED NULL,
  completed_at DATETIME NULL,
  archived_at DATETIME NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  INDEX idx_todo_account_status_due (account_id, status, due_date),
  CONSTRAINT fk_todo_account FOREIGN KEY (account_id) REFERENCES atlas_accounts(id) ON DELETE CASCADE,
  CONSTRAINT fk_todo_workspace FOREIGN KEY (workspace_id) REFERENCES atlas_workspaces(id) ON DELETE SET NULL,
  CONSTRAINT fk_todo_task FOREIGN KEY (converted_task_id) REFERENCES atlas_tasks(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS atlas_calendar_events (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  account_id BIGINT UNSIGNED NOT NULL,
  workspace_id BIGINT UNSIGNED NULL,
  related_entity_type VARCHAR(50) NULL,
  related_entity_id BIGINT UNSIGNED NULL,
  title VARCHAR(240) NOT NULL,
  description TEXT NULL,
  event_type VARCHAR(60) NOT NULL DEFAULT 'event',
  location VARCHAR(240) NULL,
  start_at DATETIME NOT NULL,
  end_at DATETIME NOT NULL,
  is_all_day TINYINT(1) NOT NULL DEFAULT 0,
  recurrence_rule VARCHAR(190) NULL,
  reminder_minutes INT UNSIGNED NULL,
  status ENUM('scheduled','done','cancelled') NOT NULL DEFAULT 'scheduled',
  created_by BIGINT UNSIGNED NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  INDEX idx_events_account_start (account_id, start_at),
  INDEX idx_events_related (related_entity_type, related_entity_id),
  CONSTRAINT fk_events_account FOREIGN KEY (account_id) REFERENCES atlas_accounts(id) ON DELETE CASCADE,
  CONSTRAINT fk_events_workspace FOREIGN KEY (workspace_id) REFERENCES atlas_workspaces(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS atlas_documents (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  account_id BIGINT UNSIGNED NOT NULL,
  workspace_id BIGINT UNSIGNED NULL,
  related_entity_type VARCHAR(50) NULL,
  related_entity_id BIGINT UNSIGNED NULL,
  title VARCHAR(240) NOT NULL,
  document_type ENUM('file','link','note') NOT NULL DEFAULT 'note',
  file_path VARCHAR(500) NULL,
  external_url VARCHAR(500) NULL,
  notes TEXT NULL,
  created_by BIGINT UNSIGNED NULL,
  archived_at DATETIME NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  INDEX idx_documents_account (account_id),
  INDEX idx_documents_related (related_entity_type, related_entity_id),
  CONSTRAINT fk_documents_account FOREIGN KEY (account_id) REFERENCES atlas_accounts(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS atlas_ideas (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  account_id BIGINT UNSIGNED NOT NULL,
  workspace_id BIGINT UNSIGNED NULL,
  title VARCHAR(240) NOT NULL,
  description TEXT NULL,
  category VARCHAR(100) NULL,
  priority ENUM('low','normal','high','urgent') NOT NULL DEFAULT 'normal',
  status ENUM('raw','reviewing','accepted','converted','rejected','archived') NOT NULL DEFAULT 'raw',
  converted_entity_type VARCHAR(50) NULL,
  converted_entity_id BIGINT UNSIGNED NULL,
  created_by BIGINT UNSIGNED NULL,
  archived_at DATETIME NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  INDEX idx_ideas_account_status (account_id, status),
  CONSTRAINT fk_ideas_account FOREIGN KEY (account_id) REFERENCES atlas_accounts(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS atlas_activity_logs (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  account_id BIGINT UNSIGNED NOT NULL,
  user_id BIGINT UNSIGNED NULL,
  entity_type VARCHAR(50) NOT NULL,
  entity_id BIGINT UNSIGNED NULL,
  action VARCHAR(50) NOT NULL,
  title VARCHAR(240) NOT NULL,
  description TEXT NULL,
  old_values JSON NULL,
  new_values JSON NULL,
  ip_address VARCHAR(80) NULL,
  user_agent VARCHAR(500) NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  INDEX idx_activity_account_created (account_id, created_at),
  INDEX idx_activity_entity (entity_type, entity_id),
  CONSTRAINT fk_activity_account FOREIGN KEY (account_id) REFERENCES atlas_accounts(id) ON DELETE CASCADE,
  CONSTRAINT fk_activity_user FOREIGN KEY (user_id) REFERENCES atlas_users(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS atlas_notifications (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  account_id BIGINT UNSIGNED NOT NULL,
  user_id BIGINT UNSIGNED NULL,
  title VARCHAR(240) NOT NULL,
  message TEXT NULL,
  notification_type VARCHAR(80) NOT NULL DEFAULT 'system',
  severity ENUM('info','success','warning','danger') NOT NULL DEFAULT 'info',
  related_entity_type VARCHAR(50) NULL,
  related_entity_id BIGINT UNSIGNED NULL,
  due_at DATETIME NULL,
  read_at DATETIME NULL,
  dismissed_at DATETIME NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  INDEX idx_notifications_user_read (user_id, read_at),
  INDEX idx_notifications_account_due (account_id, due_at),
  CONSTRAINT fk_notifications_account FOREIGN KEY (account_id) REFERENCES atlas_accounts(id) ON DELETE CASCADE,
  CONSTRAINT fk_notifications_user FOREIGN KEY (user_id) REFERENCES atlas_users(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS atlas_resume_points (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  account_id BIGINT UNSIGNED NOT NULL,
  user_id BIGINT UNSIGNED NOT NULL,
  entity_type VARCHAR(50) NOT NULL,
  entity_id BIGINT UNSIGNED NOT NULL,
  title VARCHAR(240) NOT NULL,
  note TEXT NULL,
  last_position VARCHAR(240) NULL,
  priority ENUM('low','normal','high','urgent') NOT NULL DEFAULT 'normal',
  status ENUM('open','closed','dismissed') NOT NULL DEFAULT 'open',
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  INDEX idx_resume_user_status (user_id, status),
  CONSTRAINT fk_resume_account FOREIGN KEY (account_id) REFERENCES atlas_accounts(id) ON DELETE CASCADE,
  CONSTRAINT fk_resume_user FOREIGN KEY (user_id) REFERENCES atlas_users(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS atlas_settings (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  account_id BIGINT UNSIGNED NOT NULL,
  setting_key VARCHAR(120) NOT NULL,
  setting_value TEXT NULL,
  setting_group VARCHAR(80) NOT NULL DEFAULT 'general',
  updated_at DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY uq_setting_account_key (account_id, setting_key),
  CONSTRAINT fk_settings_account FOREIGN KEY (account_id) REFERENCES atlas_accounts(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS atlas_data_resets (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  account_id BIGINT UNSIGNED NOT NULL,
  user_id BIGINT UNSIGNED NOT NULL,
  reset_type VARCHAR(80) NOT NULL,
  notes TEXT NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  CONSTRAINT fk_resets_account FOREIGN KEY (account_id) REFERENCES atlas_accounts(id) ON DELETE CASCADE,
  CONSTRAINT fk_resets_user FOREIGN KEY (user_id) REFERENCES atlas_users(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
