
ALTER TABLE `account`.`role`
    MODIFY COLUMN `hasLogin` tinyint(3) unsigned DEFAULT 1 NOT NULL;

ALTER TABLE `account`.`roleInherit`
    ADD UNIQUE( `role`, `inheritsFrom`);

ALTER TABLE `account`.`roleInherit`
    DROP PRIMARY KEY;

ALTER TABLE `account`.`roleInherit`
    ADD `id` INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST,
    ADD PRIMARY KEY (`id`);

ALTER TABLE `account`.`mailAlias`
    ADD `description` VARCHAR(255) NULL AFTER `alias`;

ALTER TABLE `account`.`mailAliasAccount`
    ADD UNIQUE( `mailAlias`, `account`);

ALTER TABLE `account`.`mailAliasAccount`
    DROP PRIMARY KEY;

ALTER TABLE `account`.`mailAliasAccount`
    ADD `id` INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST,
    ADD PRIMARY KEY (`id`);

ALTER TABLE account.ldapConfig
    ADD groupDn varchar(255) NULL;

UPDATE account.ldapConfig SET groupDn = 'ou=groups,dc=verdnatura,dc=es';

DROP PROCEDURE IF EXISTS account.user_syncPassword;

USE account;

DELIMITER $$

CREATE TRIGGER role_beforeInsert
	BEFORE INSERT ON `role` FOR EACH ROW
BEGIN
	CALL role_checkName(NEW.`name`);
END$$

CREATE TRIGGER role_beforeUpdate
	BEFORE UPDATE ON `role` FOR EACH ROW
BEGIN
	IF !(NEW.`name` <=> OLD.`name`) THEN
		CALL role_checkName (NEW.`name`);
	END IF;
END$$

DELIMITER ;