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',
	PRIMARY KEY (`membership_id`) USING BTREE
);

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,
	`training_plan_id` INT(11) NULL DEFAULT NULL,
	`days` CHAR(100) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci',
	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`
	ADD COLUMN `id_token` TEXT NULL DEFAULT NULL AFTER `lang_sync`;
ALTER TABLE `customer`
	ADD INDEX `id_token` (`id_token`);

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

COMMIT;
