-- CREATE TABLE "smd__rss_group" -------------------------------
CREATE TABLE `smd__rss_group`(
	`groupID` Int( 11 ) UNSIGNED AUTO_INCREMENT NOT NULL,
	`name` VarChar( 255 ) NOT NULL,
	`createDate` Timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	PRIMARY KEY ( `groupID` ),
	CONSTRAINT `unique_groupID` UNIQUE( `groupID` ) )
ENGINE = InnoDB;
-- -------------------------------------------------------------

-- CREATE INDEX "index_name" -----------------------------------
CREATE INDEX `index_name` ON `smd__rss_group`( `name` );
-- -------------------------------------------------------------

-- CREATE INDEX "index_createDate10" ---------------------------
CREATE INDEX `index_createDate10` ON `smd__rss_group`( `createDate` );
-- -------------------------------------------------------------

-- CREATE TABLE "smd__rss_group_has_feed" ----------------------
CREATE TABLE `smd__rss_group_has_feed`(
	`groupID` Int( 11 ) UNSIGNED NOT NULL,
	`feedID` Int( 11 ) UNSIGNED NOT NULL,
	PRIMARY KEY ( `groupID`, `feedID` ) )
ENGINE = InnoDB;
-- -------------------------------------------------------------

-- CREATE INDEX "index_feedID" ---------------------------------
CREATE INDEX `index_feedID` ON `smd__rss_group_has_feed`( `feedID` );
-- -------------------------------------------------------------

-- CREATE INDEX "index_groupID" --------------------------------
CREATE INDEX `index_groupID` ON `smd__rss_group_has_feed`( `groupID` );
-- -------------------------------------------------------------

-- CREATE LINK "smd__rss_group_smd__rss_group_has_feed_groupID_groupID"
ALTER TABLE `smd__rss_group_has_feed`
	ADD CONSTRAINT `smd__rss_group_smd__rss_group_has_feed_groupID_groupID` FOREIGN KEY ( `groupID` )
	REFERENCES `smd__rss_group`( `groupID` )
	ON DELETE Cascade
	ON UPDATE Cascade;
-- -------------------------------------------------------------

-- CREATE TABLE "smd__rss_feed" --------------------------------
CREATE TABLE `smd__rss_feed`(
	`feedID` Int( 11 ) UNSIGNED AUTO_INCREMENT NOT NULL,
	`name` VarChar( 255 ) NOT NULL,
	`feedUrl` VarChar( 255 ) NOT NULL,
	`createDate` Timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	PRIMARY KEY ( `feedID` ),
	CONSTRAINT `unique_feedID` UNIQUE( `feedID` ) )
ENGINE = InnoDB;
-- -------------------------------------------------------------

-- CREATE INDEX "index_feedUrl" --------------------------------
CREATE INDEX `index_feedUrl` ON `smd__rss_feed`( `feedUrl` );
-- -------------------------------------------------------------

-- CREATE INDEX "index_createDate11" ---------------------------
CREATE INDEX `index_createDate11` ON `smd__rss_feed`( `createDate` );
-- -------------------------------------------------------------

-- CREATE LINK "smd__rss_feed_smd__rss_group_has_feed_feedID_feedID"
ALTER TABLE `smd__rss_group_has_feed`
	ADD CONSTRAINT `smd__rss_feed_smd__rss_group_has_feed_feedID_feedID` FOREIGN KEY ( `feedID` )
	REFERENCES `smd__rss_feed`( `feedID` )
	ON DELETE Cascade
	ON UPDATE Cascade;
-- -------------------------------------------------------------

-- CREATE TABLE "smd__rss_saved_post" --------------------------
CREATE TABLE `smd__rss_saved_post`(
	`postID` Int( 11 ) UNSIGNED AUTO_INCREMENT NOT NULL,
	`feedID` Int( 11 ) UNSIGNED NOT NULL,
	`userID` Int( 11 ) UNSIGNED NOT NULL,
	`content` JSON NOT NULL,
	`createDate` Timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	PRIMARY KEY ( `postID` ),
	CONSTRAINT `unique_postID` UNIQUE( `postID` ) )
ENGINE = InnoDB;
-- -------------------------------------------------------------

-- CREATE INDEX "index_feedID1" --------------------------------
CREATE INDEX `index_feedID1` ON `smd__rss_saved_post`( `feedID` );
-- -------------------------------------------------------------

-- CREATE INDEX "index_userID4" --------------------------------
CREATE INDEX `index_userID4` ON `smd__rss_saved_post`( `userID` );
-- -------------------------------------------------------------

-- CREATE INDEX "index_createDate12" ---------------------------
CREATE INDEX `index_createDate12` ON `smd__rss_saved_post`( `createDate` );
-- -------------------------------------------------------------

-- CHANGE "NULLABLE" OF "FIELD "feedID" ------------------------
ALTER TABLE `smd__rss_saved_post` MODIFY `feedID` Int( 11 ) UNSIGNED NULL;
-- -------------------------------------------------------------

-- CREATE LINK "smd__rss_feed_smd__rss_saved_post_feedID_feedID"
ALTER TABLE `smd__rss_saved_post`
	ADD CONSTRAINT `smd__rss_feed_smd__rss_saved_post_feedID_feedID` FOREIGN KEY ( `feedID` )
	REFERENCES `smd__rss_feed`( `feedID` )
	ON DELETE Set NULL
	ON UPDATE Cascade;
-- -------------------------------------------------------------

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

-- CREATE TABLE "smd__organization_has_rss_groups" -------------
CREATE TABLE `smd__organization_has_rss_groups`(
	`organizationID` Int( 11 ) UNSIGNED NOT NULL,
	`groupID` Int( 11 ) UNSIGNED NOT NULL,
	PRIMARY KEY ( `organizationID`, `groupID` ) )
ENGINE = InnoDB;
-- -------------------------------------------------------------

-- CREATE INDEX "index_groupID5" -------------------------------
CREATE INDEX `index_groupID5` ON `smd__organization_has_rss_groups`( `groupID` );
-- -------------------------------------------------------------

-- CREATE INDEX "index_organizationID8" ------------------------
CREATE INDEX `index_organizationID8` ON `smd__organization_has_rss_groups`( `organizationID` );
-- -------------------------------------------------------------

-- CREATE LINK "smd__rss_group_smd__organization_has_rss_groups_groupID_groupID"
ALTER TABLE `smd__organization_has_rss_groups`
	ADD CONSTRAINT `smd__rss_group_smd__organization_has_rss_groups_groupID_groupID` FOREIGN KEY ( `groupID` )
	REFERENCES `smd__rss_group`( `groupID` )
	ON DELETE Cascade
	ON UPDATE Cascade;
-- -------------------------------------------------------------

-- CREATE LINK "smd__organization_smd__organization_has_rss_groups"
ALTER TABLE `smd__organization_has_rss_groups`
	ADD CONSTRAINT `smd__organization_smd__organization_has_rss_groups` FOREIGN KEY ( `organizationID` )
	REFERENCES `smd__organization`( `organizationID` )
	ON DELETE Cascade
	ON UPDATE Cascade;
-- -------------------------------------------------------------

-- CREATE TABLE "smd__organization_has_rss_feeds" --------------
CREATE TABLE `smd__organization_has_rss_feeds`(
	`organizationID` Int( 11 ) UNSIGNED NOT NULL,
	`feedID` Int( 11 ) UNSIGNED NOT NULL,
	PRIMARY KEY ( `organizationID`, `feedID` ) )
ENGINE = InnoDB;
-- -------------------------------------------------------------

-- CREATE INDEX "index_feedID2" --------------------------------
CREATE INDEX `index_feedID2` ON `smd__organization_has_rss_feeds`( `feedID` );
-- -------------------------------------------------------------

-- CREATE INDEX "index_organizationID9" ------------------------
CREATE INDEX `index_organizationID9` ON `smd__organization_has_rss_feeds`( `organizationID` );
-- -------------------------------------------------------------

-- CREATE LINK "smd__rss_feed_smd__organization_has_rss_feeds_feedID_feedID"
ALTER TABLE `smd__organization_has_rss_feeds`
	ADD CONSTRAINT `smd__rss_feed_smd__organization_has_rss_feeds_feedID_feedID` FOREIGN KEY ( `feedID` )
	REFERENCES `smd__rss_feed`( `feedID` )
	ON DELETE Cascade
	ON UPDATE Cascade;
-- -------------------------------------------------------------

-- CREATE LINK "smd__organization_smd__organization_has_rss_feeds_organizationID"
ALTER TABLE `smd__organization_has_rss_feeds`
	ADD CONSTRAINT `smd__organization_smd__organization_has_rss_feeds_organizationID` FOREIGN KEY ( `organizationID` )
	REFERENCES `smd__organization`( `organizationID` )
	ON DELETE Cascade
	ON UPDATE Cascade;
-- -------------------------------------------------------------

INSERT INTO `cms__module`(
    `name`
) VALUES (
    'module.rss'
 );

SET @moduleID = LAST_INSERT_ID();

INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'rss.feed.list',
    @moduleID,
    'rss.feed.list.name',
    'rss.feed.list.description'
 );

 INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'rss.feed.create',
    @moduleID,
    'rss.feed.create.name',
    'rss.feed.create.description'
 );

 INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'rss.feed.update',
    @moduleID,
    'rss.feed.update.name',
    'rss.feed.update.description'
 );

INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'rss.feed.remove',
    @moduleID,
    'rss.feed.remove.name',
    'rss.feed.remove.description'
 );

 INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'rss.feed.load',
    @moduleID,
    'rss.feed.load.name',
    'rss.feed.load.description'
 );

 INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'rss.group.list',
    @moduleID,
    'rss.group.list.name',
    'rss.group.list.description'
 );

 INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'rss.feed.bulkCreate',
    @moduleID,
    'rss.feed.bulkCreate.name',
    'rss.feed.bulkCreate.description'
 );

 INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'rss.feed.bulkDelete',
    @moduleID,
    'rss.feed.bulkDelete.name',
    'rss.feed.bulkDelete.description'
 );

 INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'rss.group.create',
    @moduleID,
    'rss.group.create.name',
    'rss.group.create.description'
 );

 INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'rss.group.update',
    @moduleID,
    'rss.group.update.name',
    'rss.group.update.description'
 );

 INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'rss.group.remove',
    @moduleID,
    'rss.group.remove.name',
    'rss.group.remove.description'
 );

 INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'rss.group.bulkDelete',
    @moduleID,
    'rss.group.bulkDelete.name',
    'rss.group.bulkDelete.description'
 );

 INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'rss.group.feeds',
    @moduleID,
    'rss.group.feeds.name',
    'rss.group.feeds.description'
 );

 INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'rss.savedPost.list',
    @moduleID,
    'rss.savedPost.list.name',
    'rss.savedPost.list.description'
 );

 INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'rss.savedPost.create',
    @moduleID,
    'rss.savedPost.create.name',
    'rss.savedPost.create.description'
 );

 INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'rss.savedPost.remove',
    @moduleID,
    'rss.savedPost.remove.name',
    'rss.savedPost.remove.description'
 );










