#-----------------------------------------------------------------------------
#-- kit
#-----------------------------------------------------------------------------



CREATE TABLE `kit`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`hierarchy_id` INTEGER  NOT NULL,
	`available` INTEGER default 0,
	`start_date` DATE,
	`end_date` DATE,
	PRIMARY KEY (`id`),
	INDEX `kit_FI_1` (`hierarchy_id`),
	CONSTRAINT `kit_FK_1`
		FOREIGN KEY (`hierarchy_id`)
		REFERENCES `hierarchy` (`id`)
		ON UPDATE RESTRICT
		ON DELETE RESTRICT
);

#-----------------------------------------------------------------------------
#-- kit_i18n
#-----------------------------------------------------------------------------



CREATE TABLE `kit_i18n`
(
	`id` INTEGER  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	`name` VARCHAR(256)  NOT NULL,
	PRIMARY KEY (`id`,`culture`),
	CONSTRAINT `kit_i18n_FK_1`
		FOREIGN KEY (`id`)
		REFERENCES `kit` (`id`)
		ON UPDATE RESTRICT
		ON DELETE CASCADE
);

#-----------------------------------------------------------------------------
#-- kit_template
#-----------------------------------------------------------------------------



CREATE TABLE `kit_template`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`template_id` INTEGER  NOT NULL,
	`kit_id` INTEGER  NOT NULL,
	`optionnal` INTEGER default 0,
	PRIMARY KEY (`id`),
	INDEX `kit_template_FI_1` (`template_id`),
	CONSTRAINT `kit_template_FK_1`
		FOREIGN KEY (`template_id`)
		REFERENCES `template` (`id`)
		ON UPDATE RESTRICT
		ON DELETE CASCADE,
	INDEX `kit_template_FI_2` (`kit_id`),
	CONSTRAINT `kit_template_FK_2`
		FOREIGN KEY (`kit_id`)
		REFERENCES `kit` (`id`)
		ON UPDATE RESTRICT
		ON DELETE CASCADE
);

#-----------------------------------------------------------------------------
#-- kit_ecd_emailing_template
#-----------------------------------------------------------------------------



CREATE TABLE `kit_ecd_emailing_template`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`ecd_emailing_template_id` INTEGER  NOT NULL,
	`kit_id` INTEGER  NOT NULL,
	`optionnal` INTEGER default 0,
	PRIMARY KEY (`id`),
	INDEX `kit_ecd_emailing_template_FI_1` (`ecd_emailing_template_id`),
	CONSTRAINT `kit_ecd_emailing_template_FK_1`
		FOREIGN KEY (`ecd_emailing_template_id`)
		REFERENCES `ecd_emailing_template` (`id`)
		ON UPDATE RESTRICT
		ON DELETE CASCADE,
	INDEX `kit_ecd_emailing_template_FI_2` (`kit_id`),
	CONSTRAINT `kit_ecd_emailing_template_FK_2`
		FOREIGN KEY (`kit_id`)
		REFERENCES `kit` (`id`)
		ON UPDATE RESTRICT
		ON DELETE CASCADE
);

#-----------------------------------------------------------------------------
#-- kit_media
#-----------------------------------------------------------------------------



CREATE TABLE `kit_media`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`media_id` INTEGER  NOT NULL,
	`kit_id` INTEGER  NOT NULL,
	`optionnal` INTEGER default 0,
	PRIMARY KEY (`id`),
	INDEX `kit_media_FI_1` (`media_id`),
	CONSTRAINT `kit_media_FK_1`
		FOREIGN KEY (`media_id`)
		REFERENCES `media` (`id`)
		ON UPDATE RESTRICT
		ON DELETE CASCADE,
	INDEX `kit_media_FI_2` (`kit_id`),
	CONSTRAINT `kit_media_FK_2`
		FOREIGN KEY (`kit_id`)
		REFERENCES `kit` (`id`)
		ON UPDATE RESTRICT
		ON DELETE CASCADE
);

#-----------------------------------------------------------------------------
#-- kit_tpl_tag
#-----------------------------------------------------------------------------



CREATE TABLE `kit_tpl_tag`
(
	`kit_id` INTEGER  NOT NULL,
	`tpl_tag_id` INTEGER  NOT NULL,
	PRIMARY KEY (`kit_id`,`tpl_tag_id`),
	CONSTRAINT `kit_tpl_tag_FK_1`
		FOREIGN KEY (`kit_id`)
		REFERENCES `kit` (`id`)
		ON UPDATE RESTRICT
		ON DELETE CASCADE,
	INDEX `kit_tpl_tag_FI_2` (`tpl_tag_id`),
	CONSTRAINT `kit_tpl_tag_FK_2`
		FOREIGN KEY (`tpl_tag_id`)
		REFERENCES `tpl_tag` (`id`)
		ON UPDATE RESTRICT
		ON DELETE CASCADE
);
