-- ------------------------------------------------
-- Groups of functionalities
-- Created 20140527
-- ------------------------------------------------

CREATE TABLE IF NOT EXISTS `sod_func_group` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(64) DEFAULT NULL,
  `system` varchar(8) DEFAULT NULL,
  `client` varchar(3) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `sys_cli` (`system`,`client`)
);
INSERT INTO `sod_func_group` VALUES (0, 'Unassigned', null, null);
UPDATE `sod_func_group` SET id=0 WHERE id=1;
ALTER TABLE `sod_func_group` AUTO_INCREMENT=1;

ALTER TABLE `sod_functionalities` 
  ADD COLUMN `group_id` INT NOT NULL DEFAULT 0  AFTER `description`, 
  ADD CONSTRAINT `fk_func_grp`
    FOREIGN KEY (`group_id` )
    REFERENCES `sod_func_group` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  ADD INDEX `fk_func_grp_idx` (`group_id` ASC) ;
