DROP TABLE IF EXISTS `connection`;
CREATE TABLE `connection` (
  `PK_connection_id` int NOT NULL,
  `date` datetime NOT NULL,
  `email` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `prenom` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `nom` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `FK_users_id` int NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

ALTER TABLE `connection`
  ADD PRIMARY KEY (`PK_connection_id`);

ALTER TABLE `connection`
  MODIFY `PK_connection_id` int NOT NULL AUTO_INCREMENT;
  
DROP TABLE IF EXISTS `tracker_event`;
CREATE TABLE `tracker_event` (
  `PK_tracker_event_id` int NOT NULL,
  `FK_tracker_event_type_id` int NOT NULL,
  `date` datetime NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
DROP TABLE IF EXISTS `tracker_event_data`;
CREATE TABLE `tracker_event_data` (
  `PK_tracker_event_data_id` int NOT NULL,
  `value_tracker_event_data` text NOT NULL,
  `FK_tracker_event_type_data_id` int NOT NULL,
  `FK_tracker_event_id` int NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `tracker_event_data_type`;
CREATE TABLE `tracker_event_data_type` (
  `PK_tracker_event_data_type_id` int NOT NULL,
  `libelle_tracker_event_data_type` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `needed_tracker_event_data_type` tinyint(1) NOT NULL,
  `actif_tracker_event_data_type` int NOT NULL DEFAULT '1'
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `tracker_event_data_type` (`PK_tracker_event_data_type_id`, `libelle_tracker_event_data_type`, `needed_tracker_event_data_type`, `actif_tracker_event_data_type`) VALUES
(2, 'route', 0, 1),
(1, 'user', 1, 1);
DROP TABLE IF EXISTS `tracker_event_type`;
CREATE TABLE `tracker_event_type` (
  `PK_tracker_event_type_id` int NOT NULL,
  `libelle_tracker_event_type` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `actif_tracker_event_type` int NOT NULL DEFAULT '1'
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
INSERT INTO `tracker_event_type` (`PK_tracker_event_type_id`, `libelle_tracker_event_type`, `actif_tracker_event_type`) VALUES
(2, 'view_page', 1),
(3, 'connection', 1);
DROP TABLE IF EXISTS `tracker_event_type_tracker_event_data_type`;
CREATE TABLE `tracker_event_type_tracker_event_data_type` (
  `PK_tracker_event_type_tracker_event_type_data_id` int NOT NULL,
  `FK_tracker_event_type_id` int NOT NULL,
  `FK_tracker_event_data_type_id` int NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `tracker_event_type_tracker_event_data_type` (`PK_tracker_event_type_tracker_event_type_data_id`, `FK_tracker_event_type_id`, `FK_tracker_event_data_type_id`) VALUES
(1, 3, 1);
ALTER TABLE `tracker_event`
  ADD PRIMARY KEY (`PK_tracker_event_id`);
ALTER TABLE `tracker_event_data`
  ADD PRIMARY KEY (`PK_tracker_event_data_id`),
  ADD KEY `FK_tracker_event_type_data_id` (`FK_tracker_event_type_data_id`),
  ADD KEY `FK_tracker_event_id` (`FK_tracker_event_id`);
ALTER TABLE `tracker_event_data_type`
  ADD PRIMARY KEY (`PK_tracker_event_data_type_id`);
ALTER TABLE `tracker_event_type`
  ADD PRIMARY KEY (`PK_tracker_event_type_id`);
ALTER TABLE `tracker_event_type_tracker_event_data_type`
  ADD PRIMARY KEY (`PK_tracker_event_type_tracker_event_type_data_id`),
  ADD KEY `FK_tracker_event_type_id` (`FK_tracker_event_type_id`),
  ADD KEY `FK_tracker_event_data_type_id` (`FK_tracker_event_data_type_id`);
ALTER TABLE `tracker_event`
  MODIFY `PK_tracker_event_id` int NOT NULL AUTO_INCREMENT;
ALTER TABLE `tracker_event_data`
  MODIFY `PK_tracker_event_data_id` int NOT NULL AUTO_INCREMENT;
ALTER TABLE `tracker_event_data_type`
  MODIFY `PK_tracker_event_data_type_id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
ALTER TABLE `tracker_event_type`
  MODIFY `PK_tracker_event_type_id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
ALTER TABLE `tracker_event_type_tracker_event_data_type`
  MODIFY `PK_tracker_event_type_tracker_event_type_data_id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
COMMIT;
