-- CREATE TABLE "smd__hashtag_collection" ----------------------
CREATE TABLE `smd__hashtag_collection`(
	`collectionID` Int( 11 ) UNSIGNED AUTO_INCREMENT NOT NULL,
	`name` VarChar( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
	`tags` Text NOT NULL,
	PRIMARY KEY ( `collectionID` ),
	CONSTRAINT `unique_collectionID` UNIQUE( `collectionID` ) )
CHARACTER SET = utf8
COLLATE = utf8_general_ci
ENGINE = InnoDB
AUTO_INCREMENT = 1;
-- -------------------------------------------------------------

-- CREATE INDEX "index_name" -----------------------------------
CREATE INDEX `index_name` USING BTREE ON `smd__hashtag_collection`( `name` );
-- -------------------------------------------------------------

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

-- CREATE INDEX "index_organizationID" -------------------------
CREATE INDEX `index_organizationID` ON `smd__organization_has_hashtag_collection`( `organizationID` );
-- -------------------------------------------------------------

-- CREATE INDEX "index_collectionID" ---------------------------
CREATE INDEX `index_collectionID` ON `smd__organization_has_hashtag_collection`( `collectionID` );
-- -------------------------------------------------------------

-- CREATE LINK "smd__hashtag_collection_smd__organization_has_hashtag_collection"
ALTER TABLE `smd__organization_has_hashtag_collection`
	ADD CONSTRAINT `smd__hashtag_collection_smd__organization_has_hashtag_collection` FOREIGN KEY ( `collectionID` )
	REFERENCES `smd__hashtag_collection`( `collectionID` )
	ON DELETE Cascade
	ON UPDATE Cascade;
-- -------------------------------------------------------------

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

-- CREATE TABLE "smd__hashtag_tag" -----------------------------
CREATE TABLE `smd__hashtag_tag`(
	`tagID` Int( 11 ) UNSIGNED AUTO_INCREMENT NOT NULL,
	`tag` VarChar( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
	PRIMARY KEY ( `tagID` ),
	CONSTRAINT `unique_tagID` UNIQUE( `tagID` ) )
CHARACTER SET = utf8
COLLATE = utf8_general_ci
ENGINE = InnoDB
AUTO_INCREMENT = 1;
-- -------------------------------------------------------------

-- CREATE INDEX "index_tag" ------------------------------------
CREATE INDEX `index_tag` USING BTREE ON `smd__hashtag_tag`( `tag` );
-- -------------------------------------------------------------

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

-- CREATE INDEX "index_tagID2" ---------------------------------
CREATE INDEX `index_tagID2` USING BTREE ON `smd__organization_has_hashtag_tag`( `tagID` );
-- -------------------------------------------------------------

-- CREATE INDEX "index_organizationID7" ------------------------
CREATE INDEX `index_organizationID7` USING BTREE ON `smd__organization_has_hashtag_tag`( `organizationID` );
-- -------------------------------------------------------------

-- CREATE LINK "smd__hashtag_tag_smd__organization_has_hashtag_tag"
ALTER TABLE `smd__organization_has_hashtag_tag`
	ADD CONSTRAINT `smd__hashtag_tag_smd__organization_has_hashtag_tag` FOREIGN KEY ( `tagID` )
	REFERENCES `smd__hashtag_tag`( `tagID` )
	ON DELETE Cascade
	ON UPDATE Cascade;
-- -------------------------------------------------------------

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

INSERT INTO `cms__module`(
    `name`
) VALUES (
    'module.hashtag'
 );
 SET @moduleID = LAST_INSERT_ID();

INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'hashtag.collection.list',
    @moduleID,
    'hashtag.collection.list.name',
    'hashtag.collection.list.description'
 );
INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'hashtag.collection.create',
    @moduleID,
    'hashtag.collection.create.name',
    'hashtag.collection.create.description'
 );
INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'hashtag.collection.update',
    @moduleID,
    'hashtag.collection.update.name',
    'hashtag.collection.update.description'
 );
INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'hashtag.collection.remove',
    @moduleID,
    'hashtag.collection.remove.name',
    'hashtag.collection.remove.description'
 );
 INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'hashtag.collection.bulkDelete',
    @moduleID,
    'hashtag.collection.bulkDelete.name',
    'hashtag.collection.bulkDelete.description'
 );
 INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'hashtag.tag.list',
    @moduleID,
    'hashtag.tag.list.name',
    'hashtag.tag.list.description'
 );
 INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'hashtag.tag.create',
    @moduleID,
    'hashtag.tag.create.name',
    'hashtag.tag.create.description'
 );
 INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'hashtag.tag.update',
    @moduleID,
    'hashtag.tag.update.name',
    'hashtag.tag.update.description'
 );
INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'hashtag.tag.remove',
    @moduleID,
    'hashtag.tag.remove.name',
    'hashtag.tag.remove.description'
 );
 INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'hashtag.tag.bulkDelete',
    @moduleID,
    'hashtag.tag.bulkDelete.name',
    'hashtag.tag.bulkDelete.description'
 );
 INSERT INTO `cms__resource`(
    `resourceID`,
    `moduleID`,
    `name`,
    `description`
) VALUES (
    'hashtag.tag.bulkCreate',
    @moduleID,
    'hashtag.tag.bulkCreate.name',
    'hashtag.tag.bulkCreate.description'
 );

-- CREATE FIELD "createDate" -----------------------------------
ALTER TABLE `smd__hashtag_collection` ADD COLUMN `createDate` Timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP;
-- -------------------------------------------------------------

-- CREATE INDEX "index_createDate8" ----------------------------
CREATE INDEX `index_createDate8` ON `smd__hashtag_collection`( `createDate` );
-- -------------------------------------------------------------

-- CREATE FIELD "createDate" -----------------------------------
ALTER TABLE `smd__hashtag_tag` ADD COLUMN `createDate` Timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP;
-- -------------------------------------------------------------

-- CREATE INDEX "index_createDate9" ----------------------------
CREATE INDEX `index_createDate9` ON `smd__hashtag_tag`( `createDate` );
-- -------------------------------------------------------------

