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



#-----------------------------------------------------------------------------
#-- sf_guard_user_profile
#-----------------------------------------------------------------------------

ALTER TABLE sf_guard_user_profile
    ADD `token` VARCHAR(256) AFTER available_points;

#-----------------------------------------------------------------------------
#-- print_job
#-----------------------------------------------------------------------------

ALTER TABLE print_job
    ADD `discount` FLOAT AFTER price;


#-----------------------------------------------------------------------------
#-- draft
#-----------------------------------------------------------------------------

ALTER TABLE draft
    ADD discount FLOAT AFTER description,
    ADD unit_discount FLOAT AFTER discount;

#-----------------------------------------------------------------------------
#-- translation
#-----------------------------------------------------------------------------
ALTER TABLE translation
    ADD `html` INTEGER default 0 NOT NULL AFTER code;


INSERT INTO translation (code) VALUES ('estimated-delivery');
INSERT INTO translation_i18n (id, culture, value) SELECT translation.id, 'en', 'Estimated delivery' FROM translation WHERE code = 'estimated-delivery';
INSERT INTO translation_i18n (id, culture, value) SELECT translation.id, 'fr', 'Délai de livraison estimé' FROM translation WHERE code = 'estimated-delivery';

INSERT INTO translation (code) VALUES ('price-delivery-ignored');
INSERT INTO translation_i18n (id, culture, value) SELECT translation.id, 'en', 'Price (delivery ignored)' FROM translation WHERE code = 'price-delivery-ignored';
INSERT INTO translation_i18n (id, culture, value) SELECT translation.id, 'fr', 'Coût (hors livraison)' FROM translation WHERE code = 'price-delivery-ignored';

INSERT INTO translation (code) VALUES ('total-price');
INSERT INTO translation_i18n (id, culture, value) SELECT translation.id, 'en', 'Total price' FROM translation WHERE code = 'total-price';
INSERT INTO translation_i18n (id, culture, value) SELECT translation.id, 'fr', 'Coût total' FROM translation WHERE code = 'total-price';

INSERT INTO translation (code) VALUES ('estimated-cost-delivery-ignored');
INSERT INTO translation_i18n (id, culture, value) SELECT translation.id, 'en', 'Estimated cost (delivery ignored)' FROM translation WHERE code = 'estimated-cost-delivery-ignored';
INSERT INTO translation_i18n (id, culture, value) SELECT translation.id, 'fr', 'Coût approximatif (hors livraison)' FROM translation WHERE code = 'estimated-cost-delivery-ignored';

#-----------------------------------------------------------------------------
#-- sf_guard_group
#-----------------------------------------------------------------------------

INSERT INTO sf_guard_group(name, description)
    VALUES ('Template tester', 'People allowed to test templates');

INSERT INTO sf_guard_permission (name, description) VALUES ('testTemplates', 'Access to template testing.');

INSERT INTO sf_guard_group_permission (group_id, permission_id)
        SELECT sf_guard_group.id, sf_guard_permission.id
        FROM sf_guard_group, sf_guard_permission
        WHERE
          (
              sf_guard_permission.name = 'accessAdministration'
            OR
              sf_guard_permission.name = 'viewTemplates'
            OR
              sf_guard_permission.name = 'testTemplates'
          )
          AND
            sf_guard_group.name = 'Template tester';

INSERT INTO sf_guard_group_permission (group_id, permission_id)
        SELECT sf_guard_group.id, sf_guard_permission.id
        FROM sf_guard_group, sf_guard_permission
        WHERE
            sf_guard_permission.name = 'testTemplates'
          AND
          (
              sf_guard_group.name = 'admin'
            OR
              sf_guard_group.name = 'Global Administrator'
            OR
              sf_guard_group.name = 'Local Administrator'
          );

#-----------------------------------------------------------------------------
#-- hierarchy_hierarchy_history
#-----------------------------------------------------------------------------

ALTER TABLE `hierarchy_hierarchy_history` ADD INDEX `hierarchy_hierarchy_history_FI_1` (`parent_hierarchy_history_id`);
ALTER TABLE `hierarchy_hierarchy_history` DROP INDEX `unique_hierarchy_hierarchy_history`;


