START TRANSACTION;

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

ALTER TABLE "tblUsers" ALTER COLUMN "pwd" TYPE varchar(255) DEFAULT NULL;

ALTER TABLE "tblUserPasswordHistory" ALTER COLUMN "pwd" varchar(255) DEFAULT NULL;

ALTER TABLE "tblUserPasswordRequest" ALTER COLUMN "hash" varchar(255) DEFAULT NULL;

ALTER TABLE "tblUsers" ADD COLUMN "webauthn" TYPE text DEFAULT NULL;

ALTER TABLE "tblUsers" ADD COLUMN "disabledUntil" TYPE TIMESTAMP 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, "module"='core';

COMMIT;
