##----------------------------------------------------------------------------------#
 # MusicMiner Web Server															#
 # Name:		source/app/sql/upgrade_0-5-11_to_0-5-12.sql							#
 # Author:		Jesse J Morrow	(jesse@jessejmorrow.com)							#
 # Created:		2007-06-13															#
 # Updated:		2007-06-13															#
 # Compat:		MySQL 5																#
 # Copyright:	Copyright 2007 Soundminer Inc.										#
 # Purpose:		Upgrade the installed MusicMiner databases.							#
 # Version:		0.5.11 to 0.5.12													#
 #----------------------------------------------------------------------------------##

# Alter `perms` table to include new user option settings
ALTER TABLE `mm_admin`.`perms` ADD COLUMN `opt_home` ENUM('enabled','disabled') DEFAULT NULL COMMENT 'Enable/disable the home screen functionality and interface.' AFTER `sort_albums`,
 ADD COLUMN `opt_view` ENUM('user','auto','fixed') DEFAULT NULL COMMENT 'Allow user to choose results view or force \'auto\' or \'fixed\' view.' AFTER `opt_home`,
 ADD COLUMN `opt_vista` ENUM('user','albums','mixed','tracks') DEFAULT NULL COMMENT 'Allow user to choose results vista or force \'albums\', \'mixed\', or \'tracks\' vista.' AFTER `opt_view`,
 ADD COLUMN `opt_browse` ENUM('user','show','hide') DEFAULT NULL COMMENT 'Allow user to show/hide metabrowser or force \'show\' or \'hide\'.' AFTER `opt_vista`,
 ADD COLUMN `opt_grouping` ENUM('user','off','on') DEFAULT NULL COMMENT 'Allow user to turn grouping on/off for result tracks or force \'on\' or \'off\'.' AFTER `opt_browse`;

# Alter `users` table to making `grouping` column consistent with `perms`.`opt_grouping` column
ALTER TABLE `mm_admin`.`users` MODIFY COLUMN `grouping` ENUM('off','on') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'off';
UPDATE `mm_admin`.`users` SET `grouping` = 'off';

# Alter `users` table to rename `grouping` to `prf_grouping` and rename ENUM values to be consistent with `perms`.`opt_grouping`
ALTER TABLE `mm_admin`.`users` ADD COLUMN `prf_grouping` ENUM('off','on') NOT NULL DEFAULT 'off' AFTER `limit`;
UPDATE `mm_admin`.`users` SET `prf_grouping` = `grouping` + 0;
ALTER TABLE `mm_admin`.`users` DROP `grouping`;

# Alter `history` table to match change to `users` table
TRUNCATE TABLE `mm_admin`.`history`;
ALTER TABLE `mm_admin`.`history` CHANGE COLUMN `grouping` `prf_grouping` ENUM('off','on') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'off';

# Set base defaults for new user option settings
UPDATE `mm_admin`.`perms` SET `opt_home` = 'enabled', `opt_view` = 'user', `opt_vista` = 'user', `opt_browse` = 'user', `opt_grouping` = 'user' WHERE `id` = '1';

UPDATE `mm_admin`.`schema` SET `db_ver` = '0.5.12', `mm_ver` = '0.5.12', `sm_ver` = '0.5.7';
UPDATE `mm_cache`.`schema` SET `mm_ver` = '0.5.12';
UPDATE `mm_logs`.`schema` SET `mm_ver` = '0.5.12';