DROP TABLE IF EXISTS `registration`;
CREATE TABLE `registration` (
  `PK_registration_id` int(11) NOT NULL,
  `FK_registration_form_id` int(11) NOT NULL,
  `FK_users_id` int(11) NOT NULL,
  `date_registration` datetime DEFAULT NULL,
  `actif_registration` int(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `registration_datas`;
CREATE TABLE `registration_datas` (
  `PK_registration_datas_id` int(11) NOT NULL,
  `FK_registration_id` int(11) NOT NULL,
  `FK_registration_form_fields_id` int(11) NOT NULL,
  `value_registration_datas` longtext COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `registration_form`;
CREATE TABLE `registration_form` (
  `PK_registration_form_id` int(11) NOT NULL,
  `libelle_registration_form` varchar(220) COLLATE utf8_unicode_ci NOT NULL,
  `actif_registration_form` int(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `registration_form_blocs`;
CREATE TABLE `registration_form_blocs` (
  `PK_registration_form_blocs_id` int(11) NOT NULL,
  `FK_registration_form_id` int(11) NOT NULL,
  `libelle_registration_form_blocs` varchar(600) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  `description_registration_form_blocs` text COLLATE utf8_unicode_ci NOT NULL,
  `ordre_registration_form_blocs` int(11) NOT NULL DEFAULT '0',
  `actif_registration_form_blocs` int(1) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `registration_form_fields`;
CREATE TABLE `registration_form_fields` (
  `PK_registration_form_fields_id` int(11) NOT NULL,
  `FK_registration_form_blocs_id` int(11) NOT NULL,
  `libelle_registration_form_fields` varchar(220) COLLATE utf8_unicode_ci NOT NULL,
  `key_registration_form_fields` text COLLATE utf8_unicode_ci NOT NULL,
  `type_registration_form_fields` varchar(220) COLLATE utf8_unicode_ci NOT NULL,
  `required_registration_form_fields` int(1) NOT NULL,
  `default_registration_form_fields` int(1) NOT NULL DEFAULT '0',
  `default_key_registration_form_fields` varchar(220) COLLATE utf8_unicode_ci DEFAULT NULL,
  `quota_registration_form_fields` int(1) NOT NULL DEFAULT '0',
  `participe_registration_form_fields` int(1) NOT NULL,
  `ordre_registration_form_fields` int(11) NOT NULL,
  `actif_registration_form_fields` int(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `registration_params`;
CREATE TABLE `registration_params` (
  `PK_registration_params_id` int(11) NOT NULL,
  `FK_registration_form_id` int(11) NOT NULL,
  `duree_registration` int(1) DEFAULT NULL,
  `date_open_registration` date DEFAULT NULL,
  `time_open_registration` time DEFAULT NULL,
  `texte_open_registration` text COLLATE utf8_unicode_ci,
  `date_close_registration` date DEFAULT NULL,
  `time_close_registration` time DEFAULT NULL,
  `texte_close_registration` text COLLATE utf8_unicode_ci,
  `mail_registration` int(1) DEFAULT NULL,
  `from_registration` varchar(220) COLLATE utf8_unicode_ci DEFAULT NULL,
  `from_name_registration` varchar(220) COLLATE utf8_unicode_ci DEFAULT NULL,
  `copy_registration` varchar(500) COLLATE utf8_unicode_ci DEFAULT NULL,
  `objet_mail_registration` varchar(220) COLLATE utf8_unicode_ci DEFAULT NULL,
  `content_mail_registration` longtext COLLATE utf8_unicode_ci
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


ALTER TABLE `registration`
  ADD PRIMARY KEY (`PK_registration_id`),
  ADD KEY `actif_registration` (`actif_registration`),
  ADD KEY `FK_users_id` (`FK_users_id`),
  ADD KEY `FK_registration_form_id` (`FK_registration_form_id`);

ALTER TABLE `registration_datas`
  ADD PRIMARY KEY (`PK_registration_datas_id`),
  ADD KEY `FK_registration_form_fields_id` (`FK_registration_form_fields_id`),
  ADD KEY `FK_registration_id` (`FK_registration_id`);

ALTER TABLE `registration_form`
  ADD PRIMARY KEY (`PK_registration_form_id`),
  ADD KEY `actif_registration_form` (`actif_registration_form`);

ALTER TABLE `registration_form_blocs`
  ADD PRIMARY KEY (`PK_registration_form_blocs_id`),
  ADD KEY `FK_registration_form_id` (`FK_registration_form_id`),
  ADD KEY `ordre_registration_form_blocs` (`ordre_registration_form_blocs`);

ALTER TABLE `registration_form_fields`
  ADD PRIMARY KEY (`PK_registration_form_fields_id`),
  ADD KEY `FK_registration_form_id` (`FK_registration_form_blocs_id`),
  ADD KEY `ordre_registration_form_fields` (`ordre_registration_form_fields`),
  ADD KEY `actif_registration_form_fields` (`actif_registration_form_fields`),
  ADD KEY `participe_registration_form_fields` (`participe_registration_form_fields`);

ALTER TABLE `registration_params`
  ADD PRIMARY KEY (`PK_registration_params_id`),
  ADD KEY `FK_registration_form_id` (`FK_registration_form_id`);


ALTER TABLE `registration`
  MODIFY `PK_registration_id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `registration_datas`
  MODIFY `PK_registration_datas_id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `registration_form`
  MODIFY `PK_registration_form_id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `registration_form_blocs`
  MODIFY `PK_registration_form_blocs_id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `registration_form_fields`
  MODIFY `PK_registration_form_fields_id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `registration_params`
  MODIFY `PK_registration_params_id` int(11) NOT NULL AUTO_INCREMENT;
COMMIT;
