START TRANSACTION;

ALTER TABLE `tblVersion` ADD COLUMN `module` varchar(255) DEFAULT NULL;

ALTER TABLE `tblUsers` CHANGE `pwd` `pwd` varchar(255) DEFAULT NULL;

ALTER TABLE `tblUserPasswordHistory` CHANGE `pwd` `pwd` varchar(255) DEFAULT NULL;

ALTER TABLE `tblUserPasswordRequest` CHANGE `hash` `hash` varchar(255) DEFAULT NULL;

ALTER TABLE `tblUsers` ADD COLUMN `webauthn` text DEFAULT NULL AFTER `pwd`;

ALTER TABLE `tblUsers` ADD COLUMN `disabledUntil` datetime DEFAULT NULL AFTER `disabled`;

ALTER TABLE `tblDocumentContent` ADD COLUMN `lastrevisiondate` datetime DEFAULT NULL AFTER `revisiondate`;
  
CREATE TABLE `tblAttributeDefinitionGroups` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) DEFAULT NULL,
  `comment` text,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `tblAttributeDefinitionGroupAttributeDefinition` (
  `attrdef` int(11),
  `attrgrp` int(11),
  `sequence` double NOT NULL DEFAULT '0',
	`show` int(11),
  UNIQUE KEY `attrdef` (`attrdef`,`attrgrp`),
	CONSTRAINT `tblAttributeDefinitionGroupAttributeDefinition_attrdef` FOREIGN KEY (`attrdef`) REFERENCES `tblAttributeDefinitions` (`id`) ON DELETE CASCADE,
	CONSTRAINT `tblAttributeDefinitionGroupAttributeDefinition_attrgrp` FOREIGN KEY (`attrgrp`) REFERENCES `tblAttributeDefinitionGroups` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `tblFolderAttributeDefinitionGroup` (
  `folder` int(11),
  `attrgrp` int(11),
  `sequence` double NOT NULL DEFAULT '0',
  UNIQUE KEY `folder` (`folder`,`attrgrp`),
	CONSTRAINT `tblFolderAttributeDefinitionGroup_folder` FOREIGN KEY (`folder`) REFERENCES `tblFolders` (`id`) ON DELETE CASCADE,
	CONSTRAINT `tblFolderAttributeDefinitionGroup_attrgrp` FOREIGN KEY (`attrgrp`) REFERENCES `tblAttributeDefinitionGroups` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

UPDATE `tblVersion` set `major`=6, `minor`=1, `subminor`=0, `module`='core';

COMMIT;

