CREATE TABLE SavedSearches (
  id INTEGER NOT NULL AUTO_INCREMENT,
  Name VARCHAR(255) NOT NULL,
  Description VARCHAR(255) NULL,
  Type VARCHAR(64) NOT NULL DEFAULT 'Ticket',
  PrincipalId INTEGER NOT NULL,
  Creator INTEGER NOT NULL DEFAULT 0,
  Created DATETIME NULL,
  LastUpdatedBy INTEGER NOT NULL DEFAULT 0,
  LastUpdated DATETIME NULL,
  Disabled INT2 NOT NULL DEFAULT 0,
  PRIMARY KEY (id)
) ENGINE=InnoDB CHARACTER SET utf8mb4;

CREATE INDEX SavedSearches1 on SavedSearches(Name);
CREATE INDEX SavedSearches2 on SavedSearches(PrincipalId, Disabled);

CREATE TABLE Dashboards (
  id INTEGER NOT NULL AUTO_INCREMENT,
  Name VARCHAR(255) NOT NULL,
  Description VARCHAR(255) NULL,
  PrincipalId INTEGER NOT NULL,
  Creator INTEGER NOT NULL DEFAULT 0,
  Created DATETIME NULL,
  LastUpdatedBy INTEGER NOT NULL DEFAULT 0,
  LastUpdated DATETIME NULL,
  Disabled INT2 NOT NULL DEFAULT 0,
  PRIMARY KEY (id)
) ENGINE=InnoDB CHARACTER SET utf8mb4;

CREATE INDEX Dashboards1 on Dashboards(Name);
CREATE INDEX Dashboards2 on Dashboards(PrincipalId, Disabled);

CREATE TABLE DashboardSubscriptions (
  id INTEGER NOT NULL AUTO_INCREMENT,
  UserId INTEGER NOT NULL,
  DashboardId INTEGER NOT NULL,
  Creator INTEGER NOT NULL DEFAULT 0,
  Created DATETIME NULL,
  LastUpdatedBy INTEGER NOT NULL DEFAULT 0,
  LastUpdated DATETIME NULL,
  Disabled INT2 NOT NULL DEFAULT 0,
  PRIMARY KEY (id)
) ENGINE=InnoDB CHARACTER SET utf8mb4;

CREATE INDEX DashboardsSubscription1 on DashboardSubscriptions(UserId);
CREATE INDEX DashboardsSubscription2 on DashboardSubscriptions(DashboardId);

CREATE TABLE ObjectContents (
  id BIGINT NOT NULL AUTO_INCREMENT,
  ObjectType VARCHAR(64) NOT NULL,
  ObjectId INTEGER NOT NULL,
  ContentEncoding VARCHAR(64) NULL,
  Content LONGTEXT NULL,
  Creator INTEGER NOT NULL DEFAULT 0,
  Created DATETIME NULL,
  LastUpdatedBy INTEGER NOT NULL DEFAULT 0,
  LastUpdated DATETIME NULL,
  Disabled INT2 NOT NULL DEFAULT 0,
  PRIMARY KEY (id)
) ENGINE=InnoDB CHARACTER SET utf8mb4;

CREATE INDEX ObjectContents1 ON ObjectContents (ObjectType, ObjectId, Disabled);

UPDATE ACL SET RightName='AdminOwnDashboard' WHERE RightName='ModifyOwnDashboard';
DELETE FROM ACL WHERE RightName='CreateOwnDashboard';
DELETE FROM ACL WHERE RightName='DeleteOwnDashboard';
