UPDATE `menus` SET `link`='/{locale}/training-group', `status`=1 WHERE  `id`=18;

DELIMTER //
CREATE TRIGGER `training_selection_before_insert` BEFORE INSERT ON `training_selection` FOR EACH ROW BEGIN

	SET NEW.category_id = (SELECT category_id FROM training WHERE id = NEW.training_id);
	
END;
//

UPDATE `paelo`.`menus` SET `link`='/{locale}/user-group', `status`=1 WHERE  `id`=20;


--
-- Table structure for table `training_reports`
--

CREATE TABLE `training_reports` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `company_id` int(11) NOT NULL,
  `start_date` date DEFAULT NULL,
  `date` date DEFAULT NULL,
  `date_interval` int(11) NOT NULL,
  `description` text DEFAULT NULL,
  `scheduled` tinyint(1) NOT NULL DEFAULT 0,
  `trainings` varchar(1024) NOT NULL DEFAULT 'a:0:{}',
  `results` varchar(255) NOT NULL DEFAULT 'a:0:{}',
  `recipients` varchar(2048) NOT NULL DEFAULT 'a:0:{}',
  `filter_by` int(11) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Table structure for table `training_subreports`
--

CREATE TABLE `training_subreports` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `filters` text NOT NULL,
  `training_report_id` int(11) DEFAULT NULL,
  `description` text DEFAULT NULL,
  `report_order` int(11) NOT NULL DEFAULT 0,
  `images` varchar(2048) DEFAULT NULL,
  `start_date` date NOT NULL,
  `end_date` date DEFAULT NULL,
  `filter_type` int(11) NOT NULL DEFAULT 0,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Indexes for table `training_reports`
--
ALTER TABLE `training_reports`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_companies_company_id` (`company_id`);
  
--
-- Indexes for table `training_subreports`
--
ALTER TABLE `training_subreports`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_trainingreport_id` (`training_report_id`);

--
-- AUTO_INCREMENT for table `training_reports`
--
ALTER TABLE `training_reports`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
  
--
-- AUTO_INCREMENT for table `training_subreports`
--
ALTER TABLE `training_subreports`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- Constraints for table `training_reports`
--
ALTER TABLE `training_reports`
  ADD CONSTRAINT `fk_companies_company_id` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
  
--
-- Constraints for table `training_subreports`
--
ALTER TABLE `training_subreports`
  ADD CONSTRAINT `fk_trainingreport_id` FOREIGN KEY (`training_report_id`) REFERENCES `training_reports` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

UPDATE `paelo`.`menus` SET `link`='/{locale}/training-report', `status`=1 WHERE  `id`=48;
UPDATE `paelo`.`menus` SET `link`='/{locale}/training-report', `status`=1 WHERE  `id`=71;

--
-- Structure de la table `training_report_queues`
--

CREATE TABLE `training_report_queues` (
  `id` int(11) NOT NULL,
  `training_report_id` int(11) NOT NULL,
  `recipient_id` int(11) DEFAULT NULL,
  `time_to_send` datetime NOT NULL DEFAULT current_timestamp(),
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Index pour la table `training_report_queues`
--
ALTER TABLE `training_report_queues`
  ADD PRIMARY KEY (`id`),
  ADD KEY `training_report_id` (`training_report_id`),
  ADD KEY `recipient_id` (`recipient_id`);

--
-- AUTO_INCREMENT pour la table `training_report_queues`
--
ALTER TABLE `training_report_queues`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- Table structure for table `external_training_folder`
--

CREATE TABLE `external_training_folder` (
  `id` int(11) NOT NULL,
  `description` text NOT NULL,
  `filename` varchar(255) NOT NULL,
  `filetype` varchar(255) NOT NULL,
  `user_id` int(11) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Indexes for table `external_training_folder`
--
ALTER TABLE `external_training_folder`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`);
  
--
-- AUTO_INCREMENT for table `external_training_folder`
--
ALTER TABLE `external_training_folder`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
  
--
-- Constraints for table `external_training_folder`
--
ALTER TABLE `external_training_folder`
  ADD CONSTRAINT `external_training_folder_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`);


ALTER TABLE `categories`
	CHANGE COLUMN `code` `code` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci' AFTER `video_de`;

UPDATE `paelo`.`menus` SET `icon`='qlementine-icons:user-16' WHERE  `id`=14;


--
-- Structure de la table `user_training_job`
--

CREATE TABLE `user_training_job` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `job_training_group_id` int(11) NOT NULL,
  `date` date NOT NULL,
  `completed` tinyint(1) NOT NULL DEFAULT 0,
  `company_id` int(11) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Index pour la table `user_training_job`
--
ALTER TABLE `user_training_job`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`),
  ADD KEY `job_training_group_id` (`job_training_group_id`),
  ADD KEY `idx_company_id` (`company_id`);

--
-- AUTO_INCREMENT pour la table `user_training_job`
--
ALTER TABLE `user_training_job`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;

--
-- Contraintes pour la table `user_training_job`
--
ALTER TABLE `user_training_job`
  ADD CONSTRAINT `user_training_job_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `user_training_job_ibfk_2` FOREIGN KEY (`job_training_group_id`) REFERENCES `job_training_group` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
