Browse Source

blog_cat_post_rel table unique key

Vova Tkach 6 years ago
parent
commit
7dd7895a78
2 changed files with 6 additions and 0 deletions
  1. 1 0
      database/schema.sql
  2. 5 0
      modules/module_index_act_mysql_setup.go

+ 1 - 0
database/schema.sql

@@ -17,6 +17,7 @@ CREATE TABLE `blog_cat_post_rel` (
 	PRIMARY KEY (`id`)
 	PRIMARY KEY (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 ALTER TABLE `blog_cat_post_rel` ADD KEY `post_id` (`post_id`), ADD KEY `category_id` (`category_id`);
 ALTER TABLE `blog_cat_post_rel` ADD KEY `post_id` (`post_id`), ADD KEY `category_id` (`category_id`);
+ALTER TABLE `blog_cat_post_rel` ADD UNIQUE KEY `post_category` (`post_id`,`category_id`) USING BTREE;
 
 
 CREATE TABLE `blog_posts` (
 CREATE TABLE `blog_posts` (
 	`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
 	`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',

+ 5 - 0
modules/module_index_act_mysql_setup.go

@@ -123,6 +123,11 @@ func (this *Modules) RegisterAction_IndexMysqlSetup() *Action {
 			wrap.MsgError(err.Error())
 			wrap.MsgError(err.Error())
 			return
 			return
 		}
 		}
+		if _, err = tx.Exec(`ALTER TABLE blog_cat_post_rel ADD UNIQUE KEY post_category (post_id,category_id) USING BTREE;`); err != nil {
+			tx.Rollback()
+			wrap.MsgError(err.Error())
+			return
+		}
 
 
 		// Table: blog_posts
 		// Table: blog_posts
 		if _, err = tx.Exec(
 		if _, err = tx.Exec(