START TRANSACTION;

CREATE TABLE "tblDownloadLinks" (
  "id" SERIAL UNIQUE,
  "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" SERIAL UNIQUE,
  "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" REAL 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" REAL NOT NULL default '0',
  UNIQUE ("folder", "attrgrp")
);

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

COMMIT;
