#
# MySQL upgrade script for upgrade database from version 2.0.61 to 2.0.62
#

###############################
# Shared code for library     #
###############################

SET NAMES 'utf8';

SET FOREIGN_KEY_CHECKS = 0;

ALTER TABLE `color_library` ADD `shared_code` VARCHAR(256);
ALTER TABLE `font_library` ADD `shared_code` VARCHAR(256);
ALTER TABLE `image_library` ADD `shared_code` VARCHAR(256);
ALTER TABLE `text_library` ADD `shared_code` VARCHAR(256);
ALTER TABLE `item_library` ADD `shared_code` VARCHAR(256);
ALTER TABLE `external_item_library` ADD `shared_code` VARCHAR(256);


SET FOREIGN_KEY_CHECKS = 1;



UPDATE color_library lib
   JOIN template_color_library tpl ON
   lib.id=tpl.color_library_id
SET lib.shared_code = tpl.code
WHERE lib.shared_code IS NULL;

UPDATE font_library lib
   JOIN template_font_library tpl ON
   lib.id=tpl.font_library_id
SET lib.shared_code = tpl.code
WHERE lib.shared_code IS NULL;

UPDATE image_library lib
   JOIN template_image_library tpl ON
   lib.id=tpl.image_library_id
SET lib.shared_code = tpl.code
WHERE lib.shared_code IS NULL;

UPDATE text_library lib
   JOIN template_text_library tpl ON
   lib.id=tpl.text_library_id
SET lib.shared_code = tpl.code
WHERE lib.shared_code IS NULL;

UPDATE item_library lib
   JOIN template_item_library tpl ON
   lib.id=tpl.item_library_id
SET lib.shared_code = tpl.code
WHERE lib.shared_code IS NULL;

UPDATE external_item_library lib
   JOIN template_external_item_library tpl ON
   lib.id=tpl.external_item_library_id
SET lib.shared_code = tpl.code
WHERE lib.shared_code IS NULL;