##----------------------------------------------------------------------------------#
 # MusicMiner Web Server															#
 # Name:		source/app/sql/upgrade_1.2.0.2.sql									#
 # Author:		Jesse J Morrow	(jesse@jessejmorrow.com)							#
 # Created:		2009-11-12															#
 # Updated:		2009-11-13															#
 # Compat:		MySQL 5																#
 # Copyright:	Copyright 2009 Soundminer Inc.										#
 # Purpose:		Upgrade the installed MusicMiner databases.							#
 # Version:		1.2.0.1 to 1.2.0.2													#
 #----------------------------------------------------------------------------------##

# Add 'group' and 'shared' types to `folder_states` table
ALTER TABLE `mm_admin`.`folder_states` MODIFY COLUMN `type` ENUM('section','group','shared','folder','cuesheet','playlist') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'folder' COMMENT 'Indicates which table, `folders`, `cuesheets`, or `playlists` that `id` is associated with.';

# Migrate existing users/groups Playlists to the root structure (done in 1.2.0, but just to be sure as noticed a folder during testing that was not renamed to 'Playlists')
UPDATE `mm_admin`.`folders`, `mm_admin`.`users` SET `owner_id` = `users`.`id`, `folders`.`type` = 'private', `o_access` = 'read,add,modify,delete', `s_access` = '', `root_id` = `folders`.`id`, `path` = CONCAT('/', `users`.`user`,':', `users`.`id`, '/'), `folders`.`name` = 'Playlists' WHERE `folders`.`id` = `users`.`folder_id`;
UPDATE `mm_admin`.`folders`, `mm_admin`.`groups` SET `owner_id` = -`groups`.`id`, `folders`.`type` = 'private', `o_access` = 'read,add,modify,delete', `s_access` = '', `root_id` = `folders`.`id`, `path` = CONCAT('/', `groups`.`name`, ':', -`groups`.`id`, '/'), `folders`.`name` = 'Playlists' WHERE `folders`.`id` = `groups`.`folder_id`;

#-----------------------------------------------------------------------------
# Versions
#-----------------------------------------------------------------------------

# Update version fields
UPDATE `mm_admin`.`schema` SET `db_ver` = '1.2.0.2', `sm_ver` = '1.2.0.2';