START TRANSACTION;

CREATE TABLE `customer_conversation` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`customer_id` INT(11) NOT NULL DEFAULT '0',
	`conversation_date` DATETIME NULL DEFAULT NULL,
	`question` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`answer` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	PRIMARY KEY (`id`) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;


CREATE TABLE `diet_user` (
	`diet_user_id` INT(11) NOT NULL AUTO_INCREMENT,
	`customer_id` INT(11) NOT NULL DEFAULT '0',
	PRIMARY KEY (`diet_user_id`) USING BTREE
)
ENGINE=InnoDB
;

CREATE TABLE `diet_raw_material` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`diet_id` INT(11) NOT NULL DEFAULT '0',
	`raw_material_id` INT(11) NULL DEFAULT '0',
	`kcal_min` INT(11) NULL DEFAULT '0',
	`kcal_max` INT(11) NULL DEFAULT '0',
	`protein_min` INT(11) NULL DEFAULT '0',
	`protein_max` INT(11) NULL DEFAULT '0',
	`ch_min` INT(11) NULL DEFAULT '0',
	`ch_max` INT(11) NULL DEFAULT '0',
	`fat_min` INT(11) NULL DEFAULT '0',
	`fat_max` INT(11) NULL DEFAULT '0',
	`sugar` INT(11) NULL DEFAULT '0',
	`name` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	PRIMARY KEY (`id`) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;

CREATE TABLE `diet_sensitivity` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`name` CHAR(100) NOT NULL DEFAULT '0' COLLATE 'utf8mb4_general_ci',
	PRIMARY KEY (`id`) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;

CREATE TABLE `diet_user_consumption` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`diet_user_id` INT(11) NOT NULL,
	`raw_material_id` INT(11) NOT NULL DEFAULT '0',
	`date_consumption` DATETIME NOT NULL,
	`name` CHAR(100) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`quantity` DOUBLE NOT NULL DEFAULT '0',
	`quantity_unit` CHAR(10) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`cal` INT(11) NULL DEFAULT NULL,
	`protein` DOUBLE NULL DEFAULT NULL,
	`fat` DOUBLE NULL DEFAULT NULL,
	`ch` DOUBLE NULL DEFAULT NULL,
	`sugar` DOUBLE NULL DEFAULT NULL,
	PRIMARY KEY (`id`) USING BTREE,
	INDEX `diet_user_id` (`diet_user_id`) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;

CREATE TABLE `diet_user_preference` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`diet_user_id` INT(11) NOT NULL DEFAULT '0',
	`raw_material_id` INT(11) NOT NULL DEFAULT '0',
	`temperature` DECIMAL(1,0) NOT NULL DEFAULT '0',
	PRIMARY KEY (`id`) USING BTREE,
	INDEX `diet_user_id` (`diet_user_id`) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;

CREATE TABLE `diet_user_sensitivity` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`sensitivity_id` INT(11) NOT NULL DEFAULT '0',
	`diet_user_id` INT(11) NOT NULL DEFAULT '0',
	PRIMARY KEY (`id`) USING BTREE,
	INDEX `diet_user_id` (`diet_user_id`) USING BTREE
)
COLLATE='utf8_hungarian_ci'
ENGINE=InnoDB
;



CREATE TABLE `raw_material` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`name` CHAR(100) NOT NULL COLLATE 'utf8mb4_general_ci',
	`description` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`kcal_min` INT(11) NULL DEFAULT '0',
	`kcal_max` INT(11) NULL DEFAULT '0',
	`protein_min` INT(11) NULL DEFAULT '0',
	`protein_max` INT(11) NULL DEFAULT '0',
	`ch_min` INT(11) NULL DEFAULT '0',
	`ch_max` INT(11) NULL DEFAULT '0',
	`fat_min` INT(11) NULL DEFAULT '0',
	`fat_max` INT(11) NULL DEFAULT '0',
	`sugar` INT(11) NULL DEFAULT '0',
	`store_id` INT(11) NULL DEFAULT '0',
	PRIMARY KEY (`id`) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
ROW_FORMAT=DYNAMIC
;

CREATE TABLE `recipe` (
	`recipe_id` INT(11) NOT NULL AUTO_INCREMENT,
	`name` CHAR(250) NOT NULL DEFAULT '' COLLATE 'utf8mb4_general_ci',
	`description` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`cal` INT(11) NULL DEFAULT NULL,
	`protein` DOUBLE NULL DEFAULT NULL,
	`fat` DOUBLE NULL DEFAULT NULL,
	`ch` DOUBLE NULL DEFAULT NULL,
	`diet_user_id` INT(11) NULL DEFAULT '0',
	PRIMARY KEY (`recipe_id`) USING BTREE,
	INDEX `name` (`name`) USING BTREE,
    INDEX `diet_user_id` (`diet_user_id`) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;

CREATE TABLE `store` (
	`store_id` INT(11) NOT NULL AUTO_INCREMENT,
	`store_name` CHAR(50) NOT NULL DEFAULT '' COLLATE 'utf8mb4_general_ci',
	`country` CHAR(4) NOT NULL DEFAULT '' COLLATE 'utf8mb4_general_ci',
	PRIMARY KEY (`store_id`) USING BTREE,
	INDEX `store_name` (`store_name`) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;

CREATE TABLE `recipe_raw_material` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`raw_material_id` INT(11) NOT NULL DEFAULT '0',
	`recipe_id` INT(11) NOT NULL DEFAULT '0',
	`quantity` INT(11) NULL DEFAULT '0',
	`quantity_unit` CHAR(10) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	PRIMARY KEY (`id`) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;


UPDATE configuration set config_value = "1.2.0", date_change=CURRENT_DATE WHERE config_key = "db_version";

COMMIT;
