BEGIN;

CREATE TABLE `tblDownloadLinks` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT,
  `document` INTEGER REFERENCES `tblDocuments` (`id`) ON DELETE CASCADE,
  `version` INTEGER unsigned NOT NULL default '0',
  `userID` INTEGER NOT NULL default '0' REFERENCES `tblUsers` (`id`) ON DELETE CASCADE,
  `hash` varchar(50) default NULL,
  `valid` TEXT default NULL
);

CREATE TABLE `tblAttributeDefinitionGroups` (
  `id` INTEGER PRIMARY KEY AUTOINCREMENT,
  `name` varchar(100) default NULL,
  `comment` text,
  UNIQUE(`name`)
);

CREATE TABLE `tblAttributeDefinitionGroupAttributeDefinition` (
  `attrdef` INTEGER REFERENCES `tblAttributeDefinitions` (`id`) ON DELETE CASCADE,
  `attrgrp` INTEGER REFERENCES `tblAttributeDefinitionGroups` (`id`) ON DELETE CASCADE,
  `sequence` double NOT NULL default '0',
	`show` INTEGER,
  UNIQUE(`attrdef`, `attrgrp`)
);

CREATE TABLE `tblFolderAttributeDefinitionGroup` (
  `folder` INTEGER REFERENCES `tblFolders` (`id`) ON DELETE CASCADE,
  `attrgrp` INTEGER REFERENCES `tblAttributeDefinitionGroups` (`id`) ON DELETE CASCADE,
  `sequence` double NOT NULL default '0',
  UNIQUE(`folder`, `attrgrp`)
);

UPDATE tblVersion set major=6, minor=1, subminor=0;

COMMIT;
