#
# MySQL upgrade script for upgrade database from version 2.0.4 to 2.0.5
# 

#-----------------------------------------------------------------------------
#-- template_edition
#-----------------------------------------------------------------------------



CREATE TABLE `template_edition`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`sf_guard_user_id` INTEGER  NOT NULL,
	`template_id` INTEGER  NOT NULL,
	`source_conf` LONGTEXT,
	`temporary_conf` LONGTEXT,
	PRIMARY KEY (`id`),
	UNIQUE KEY `unique_template` (`template_id`),
	INDEX `template_edition_FI_1` (`sf_guard_user_id`),
	CONSTRAINT `template_edition_FK_1`
		FOREIGN KEY (`sf_guard_user_id`)
		REFERENCES `sf_guard_user` (`id`)
		ON DELETE CASCADE,
	CONSTRAINT `template_edition_FK_2`
		FOREIGN KEY (`template_id`)
		REFERENCES `template` (`id`)
		ON DELETE CASCADE
)Type=InnoDB;


#-----------------------------------------------------------------------------
#-- Ajout des nouvelles permissions.
#-----------------------------------------------------------------------------

INSERT INTO sf_guard_permission (name, description) VALUES ('editTemplateConf', 'accès à l''éditeur de modèles');

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 = 'editTemplateConf'
          AND
            sf_guard_group.name = 'Global Administrator';


