START TRANSACTION;

CREATE TABLE `membership` (
	`membership_id` INT(11) NOT NULL AUTO_INCREMENT,
	`name` CHAR(100) NOT NULL COLLATE 'utf8mb4_general_ci',
	`description` CHAR(200) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`duration` INT(11) NULL DEFAULT NULL,
	`duration_type` ENUM('free','subscription','lifetime','limited') NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`duration_unit` ENUM('day','week','month','year') NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	`training_plan_id` INT(11) NULL DEFAULT '0',
	`training_plan_day_ids` CHAR(100) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	PRIMARY KEY (`membership_id`) USING BTREE,
	INDEX `training_plan_id` (`training_plan_id`) USING BTREE
)
ENGINE=InnoDB
;

CREATE TABLE `customer_membership` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`customer_id` INT(11) NOT NULL DEFAULT '0',
	`membership_id` INT(11) NOT NULL DEFAULT '0',
	`start_date` DATETIME NULL DEFAULT NULL,
	PRIMARY KEY (`id`) USING BTREE,
	INDEX `customer_id` (`customer_id`) USING BTREE,
	INDEX `membership_id` (`membership_id`) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;

ALTER TABLE `customer_property`
	ADD COLUMN `goal` TINYINT NULL DEFAULT '0' AFTER `date_add`;
ALTER TABLE `customer_property`
	ADD COLUMN `goal_date` DATE NULL DEFAULT NULL AFTER `goal`;

ALTER TABLE `customer_training_plan`
	ADD COLUMN `result` CHAR(100) NULL DEFAULT NULL AFTER `status`;

ALTER TABLE `customer`
	CHANGE COLUMN `firebase_uid` `firebase_uid` CHAR(200) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci' AFTER `body_type`;
ALTER TABLE `customer`
	CHANGE COLUMN `firebase_reg_token` `firebase_reg_token` TEXT NULL COLLATE 'utf8mb4_general_ci' AFTER `trial_date`;
ALTER TABLE `customer`
	ADD INDEX `firebase_reg_token` (`firebase_reg_token`);

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

COMMIT;