-- CREATE TABLE "smd__dashboard" -------------------------------
CREATE TABLE `smd__dashboard` (
	`dashboardID` Int( 11 ) UNSIGNED AUTO_INCREMENT NOT NULL,
	`name` VarChar( 255 ) NOT NULL,
	`data` JSON NULL,
	PRIMARY KEY ( `dashboardID` ),
	CONSTRAINT `unique_dashboardID` UNIQUE( `dashboardID` ) )
ENGINE = InnoDB;
-- -------------------------------------------------------------

-- CREATE INDEX "index_userID" ---------------------------------
CREATE INDEX `index_userID` ON `smd__dashboard`( `userID` );
-- -------------------------------------------------------------

-- CREATE TABLE "smd__dashboard_has_users" ---------------------
CREATE TABLE `smd__dashboard_has_users` (
	`dashboardID` Int( 11 ) UNSIGNED NOT NULL,
	`userID` Int( 11 ) UNSIGNED NOT NULL,
	`type` Enum( 'owner', 'user' ) NOT NULL DEFAULT 'user',
	`permissions` Set( 'view', 'edit', 'delete' ) NOT NULL DEFAULT view,
	PRIMARY KEY ( `dashboardID`, `userID` ) )
ENGINE = InnoDB;
-- -------------------------------------------------------------

-- CREATE INDEX "index_userID1" --------------------------------
CREATE INDEX `index_userID1` ON `smd__dashboard_has_users`( `userID` );
-- -------------------------------------------------------------

-- CREATE INDEX "index_dashboardID" ----------------------------
CREATE INDEX `index_dashboardID` ON `smd__dashboard_has_users`( `dashboardID` );
-- -------------------------------------------------------------

-- CREATE LINK "smd__dashboard_smd__dashboard_has_users_dashboardID_dashboardID"
ALTER TABLE `smd__dashboard_has_users`
	ADD CONSTRAINT `smd__dashboard_smd__dashboard_has_users_dashboardID_dashboardID` FOREIGN KEY ( `dashboardID` )
	REFERENCES `smd__dashboard`( `dashboardID` )
	ON DELETE Cascade
	ON UPDATE Cascade;
-- -------------------------------------------------------------

-- CREATE LINK "cms__user_smd__dashboard_has_users_userID_userID"
ALTER TABLE `smd__dashboard_has_users`
	ADD CONSTRAINT `cms__user_smd__dashboard_has_users_userID_userID` FOREIGN KEY ( `userID` )
	REFERENCES `cms__user`( `userID` )
	ON DELETE Cascade
	ON UPDATE Cascade;
-- -------------------------------------------------------------