CREATE TABLE `managers_domains` (
  `domain_id` int(11) NOT NULL,
  `manager_id` int(11) NOT NULL,
  PRIMARY KEY (`domain_id`, `manager_id`),
  FOREIGN KEY (domain_id) REFERENCES virtual_domains(id),
  FOREIGN KEY (manager_id) REFERENCES virtual_users(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `recovery_codes` (
  `id` int(11) NOT NULL auto_increment,
  `user_id` int(11) NOT NULL,
  `code` varchar(255) NOT NULL,
  `created` timestamp DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `code` (`code`),
  FOREIGN KEY (user_id) REFERENCES virtual_users(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

ALTER TABLE `virtual_users` ADD COLUMN `recovery_email` varchar(255) DEFAULT NULL;
ALTER TABLE `virtual_users` ADD COLUMN `is_manager` BOOLEAN DEFAULT FALSE;
