Browse Source

Remove unnecessary db fields

Vova Tkach 5 years ago
parent
commit
ae4cf4b276

+ 12 - 18
modules/module_index_act_mysql_setup.go

@@ -91,10 +91,8 @@ func (this *Modules) RegisterAction_IndexMysqlSetup() *Action {
 		// Table: blog_cat_post_rel
 		// Table: blog_cat_post_rel
 		if _, err = tx.Exec(
 		if _, err = tx.Exec(
 			`CREATE TABLE blog_cat_post_rel (
 			`CREATE TABLE blog_cat_post_rel (
-				id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
 				post_id int(11) NOT NULL COMMENT 'Post id',
 				post_id int(11) NOT NULL COMMENT 'Post id',
-				category_id int(11) NOT NULL COMMENT 'Category id',
-				PRIMARY KEY (id)
+				category_id int(11) NOT NULL COMMENT 'Category id'
 			) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
 			) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
 		); err != nil {
 		); err != nil {
 			tx.Rollback()
 			tx.Rollback()
@@ -157,10 +155,8 @@ func (this *Modules) RegisterAction_IndexMysqlSetup() *Action {
 		// Table: shop_cat_product_rel
 		// Table: shop_cat_product_rel
 		if _, err = tx.Exec(
 		if _, err = tx.Exec(
 			`CREATE TABLE shop_cat_product_rel (
 			`CREATE TABLE shop_cat_product_rel (
-				id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
 				product_id int(11) NOT NULL COMMENT 'Product id',
 				product_id int(11) NOT NULL COMMENT 'Product id',
-				category_id int(11) NOT NULL COMMENT 'Category id',
-				PRIMARY KEY (id)
+				category_id int(11) NOT NULL COMMENT 'Category id'
 			) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
 			) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
 		); err != nil {
 		); err != nil {
 			tx.Rollback()
 			tx.Rollback()
@@ -204,10 +200,8 @@ func (this *Modules) RegisterAction_IndexMysqlSetup() *Action {
 		// Table: shop_filter_product_values
 		// Table: shop_filter_product_values
 		if _, err = tx.Exec(
 		if _, err = tx.Exec(
 			`CREATE TABLE shop_filter_product_values (
 			`CREATE TABLE shop_filter_product_values (
-				id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
 				product_id int(11) NOT NULL COMMENT 'Product id',
 				product_id int(11) NOT NULL COMMENT 'Product id',
-				filter_value_id int(11) NOT NULL COMMENT 'Filter value id',
-				PRIMARY KEY (id)
+				filter_value_id int(11) NOT NULL COMMENT 'Filter value id'
 			) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
 			) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
 		); err != nil {
 		); err != nil {
 			tx.Rollback()
 			tx.Rollback()
@@ -304,7 +298,7 @@ func (this *Modules) RegisterAction_IndexMysqlSetup() *Action {
 			return
 			return
 		}
 		}
 		if _, err = tx.Exec(
 		if _, err = tx.Exec(
-			`INSERT INTO blog_cat_post_rel (id, post_id, category_id) VALUES (1, 1, 9), (2, 2, 12), (3, 3, 8);`,
+			`INSERT INTO blog_cat_post_rel (post_id, category_id) VALUES (1, 9), (2, 12), (3, 8);`,
 		); err != nil {
 		); err != nil {
 			tx.Rollback()
 			tx.Rollback()
 			wrap.MsgError(err.Error())
 			wrap.MsgError(err.Error())
@@ -456,9 +450,9 @@ func (this *Modules) RegisterAction_IndexMysqlSetup() *Action {
 			return
 			return
 		}
 		}
 		if _, err = tx.Exec(
 		if _, err = tx.Exec(
-			`INSERT INTO shop_cat_product_rel (id, product_id, category_id)
+			`INSERT INTO shop_cat_product_rel (product_id, category_id)
 				VALUES
 				VALUES
-			(1, 1, 3);`,
+			(1, 3);`,
 		); err != nil {
 		); err != nil {
 			tx.Rollback()
 			tx.Rollback()
 			wrap.MsgError(err.Error())
 			wrap.MsgError(err.Error())
@@ -485,13 +479,13 @@ func (this *Modules) RegisterAction_IndexMysqlSetup() *Action {
 			return
 			return
 		}
 		}
 		if _, err = tx.Exec(
 		if _, err = tx.Exec(
-			`INSERT INTO shop_filter_product_values (id, product_id, filter_value_id)
+			`INSERT INTO shop_filter_product_values (product_id, filter_value_id)
 				VALUES
 				VALUES
-			(1, 1, 3),
-			(2, 1, 7),
-			(3, 1, 9),
-			(4, 1, 10),
-			(5, 1, 11);`,
+			(1, 3),
+			(1, 7),
+			(1, 9),
+			(1, 10),
+			(1, 11);`,
 		); err != nil {
 		); err != nil {
 			tx.Rollback()
 			tx.Rollback()
 			wrap.MsgError(err.Error())
 			wrap.MsgError(err.Error())

+ 1 - 0
support/migrate/000000001.go

@@ -9,4 +9,5 @@ var Migrations = map[string]func(*sqlw.DB) error{
 	"000000001": nil,
 	"000000001": nil,
 	"000000002": Migrate_000000002,
 	"000000002": Migrate_000000002,
 	"000000003": Migrate_000000003,
 	"000000003": Migrate_000000003,
+	"000000004": Migrate_000000004,
 }
 }

+ 0 - 3
support/migrate/000000003.go

@@ -6,9 +6,6 @@ import (
 )
 )
 
 
 func Migrate_000000003(db *sqlw.DB) error {
 func Migrate_000000003(db *sqlw.DB) error {
-	// ALTER TABLE blog_cat_post_rel ADD KEY post_id (post_id);
-	// ALTER TABLE blog_cat_post_rel ADD KEY category_id (category_id);
-
 	// Remove blog indexes
 	// Remove blog indexes
 	if _, err := db.Exec(`DROP INDEX post_id ON blog_cat_post_rel`); err != nil {
 	if _, err := db.Exec(`DROP INDEX post_id ON blog_cat_post_rel`); err != nil {
 		return err
 		return err

+ 24 - 0
support/migrate/000000004.go

@@ -0,0 +1,24 @@
+package migrate
+
+import (
+	"golang-fave/engine/sqlw"
+)
+
+func Migrate_000000004(db *sqlw.DB) error {
+	if _, err := db.Exec(
+		`ALTER TABLE blog_cat_post_rel DROP id;`,
+	); err != nil {
+		return err
+	}
+	if _, err := db.Exec(
+		`ALTER TABLE shop_cat_product_rel DROP id;`,
+	); err != nil {
+		return err
+	}
+	if _, err := db.Exec(
+		`ALTER TABLE shop_filter_product_values DROP id;`,
+	); err != nil {
+		return err
+	}
+	return nil
+}

+ 3 - 9
support/schema.sql

@@ -9,10 +9,8 @@ CREATE TABLE blog_cats (
 	PRIMARY KEY (id)
 	PRIMARY KEY (id)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 CREATE TABLE blog_cat_post_rel (
 CREATE TABLE blog_cat_post_rel (
-	id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
 	post_id int(11) NOT NULL COMMENT 'Post id',
 	post_id int(11) NOT NULL COMMENT 'Post id',
-	category_id int(11) NOT NULL COMMENT 'Category id',
-	PRIMARY KEY (id)
+	category_id int(11) NOT NULL COMMENT 'Category id'
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 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',
@@ -43,10 +41,8 @@ CREATE TABLE settings (
 	value text NOT NULL COMMENT 'Setting value'
 	value text NOT NULL COMMENT 'Setting value'
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 CREATE TABLE shop_cat_product_rel (
 CREATE TABLE shop_cat_product_rel (
-	id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
 	product_id int(11) NOT NULL COMMENT 'Product id',
 	product_id int(11) NOT NULL COMMENT 'Product id',
-	category_id int(11) NOT NULL COMMENT 'Category id',
-	PRIMARY KEY (id)
+	category_id int(11) NOT NULL COMMENT 'Category id'
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 CREATE TABLE shop_cats (
 CREATE TABLE shop_cats (
 	id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
 	id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
@@ -66,10 +62,8 @@ CREATE TABLE shop_currencies (
 	PRIMARY KEY (id)
 	PRIMARY KEY (id)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 CREATE TABLE shop_filter_product_values (
 CREATE TABLE shop_filter_product_values (
-	id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
 	product_id int(11) NOT NULL COMMENT 'Product id',
 	product_id int(11) NOT NULL COMMENT 'Product id',
-	filter_value_id int(11) NOT NULL COMMENT 'Filter value id',
-	PRIMARY KEY (id)
+	filter_value_id int(11) NOT NULL COMMENT 'Filter value id'
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 CREATE TABLE shop_filters (
 CREATE TABLE shop_filters (
 	id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
 	id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',