DROP TABLE IF EXISTS `tickets`;
CREATE TABLE `tickets` (
  `PK_tickets_id` int(11) NOT NULL,
  `FK_users_id` int(11) NOT NULL,
  `number_tickets` varchar(220) COLLATE utf8_unicode_ci NOT NULL,
  `libelle_tickets` varchar(500) COLLATE utf8_unicode_ci NOT NULL,
  `date_tickets` datetime NOT NULL,
  `date_cloture_tickets` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `status_tickets` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'W'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `tickets_history`;
CREATE TABLE `tickets_history` (
  `PK_tickets_history_id` int(11) NOT NULL,
  `FK_tickets_id` int(11) NOT NULL,
  `admin_message` int(1) NOT NULL DEFAULT '0',
  `message_tickets_history` text COLLATE utf8_unicode_ci NOT NULL,
  `file_tickets_history` varchar(220) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  `file_name_tickets_history` varchar(220) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  `date_tickets_history` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


ALTER TABLE `tickets`
  ADD PRIMARY KEY (`PK_tickets_id`),
  ADD KEY `libelle_tickets` (`libelle_tickets`(333)),
  ADD KEY `date_tickets` (`date_tickets`),
  ADD KEY `status_tickets` (`status_tickets`),
  ADD KEY `FK_users_id` (`FK_users_id`),
  ADD KEY `number_tickets` (`number_tickets`);

ALTER TABLE `tickets_history`
  ADD PRIMARY KEY (`PK_tickets_history_id`),
  ADD KEY `FK_tickets_id` (`FK_tickets_id`),
  ADD KEY `date_tickets_history` (`date_tickets_history`);


ALTER TABLE `tickets`
  MODIFY `PK_tickets_id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `tickets_history`
  MODIFY `PK_tickets_history_id` int(11) NOT NULL AUTO_INCREMENT;
COMMIT;
