Browse Source

Migration, index for product name

Vova Tkach 5 years ago
parent
commit
ede9be29a8

+ 6 - 1
modules/module_index_act_mysql_setup.go

@@ -469,7 +469,7 @@ func (this *Modules) RegisterAction_IndexMysqlSetup() *Action {
 			return
 		}
 		if _, err = tx.Exec(
-			`INSERT INTO settings (name, value) VALUES ('database_version', '000000011');`,
+			`INSERT INTO settings (name, value) VALUES ('database_version', '000000012');`,
 		); err != nil {
 			tx.Rollback()
 			wrap.MsgError(err.Error())
@@ -750,6 +750,11 @@ func (this *Modules) RegisterAction_IndexMysqlSetup() *Action {
 			wrap.MsgError(err.Error())
 			return
 		}
+		if _, err = tx.Exec(`ALTER TABLE shop_products ADD KEY name (name);`); err != nil {
+			tx.Rollback()
+			wrap.MsgError(err.Error())
+			return
+		}
 		if _, err = tx.Exec(`ALTER TABLE users ADD UNIQUE KEY email (email);`); err != nil {
 			tx.Rollback()
 			wrap.MsgError(err.Error())

+ 1 - 0
support/migrate/000000001.go

@@ -17,4 +17,5 @@ var Migrations = map[string]func(*sqlw.DB, string) error{
 	"000000009": Migrate_000000009,
 	"000000010": Migrate_000000010,
 	"000000011": Migrate_000000011,
+	"000000012": Migrate_000000012,
 }

+ 13 - 0
support/migrate/000000012.go

@@ -0,0 +1,13 @@
+package migrate
+
+import (
+	"golang-fave/engine/sqlw"
+)
+
+func Migrate_000000012(db *sqlw.DB, host string) error {
+	if _, err := db.Exec(`ALTER TABLE shop_products ADD KEY name (name);`); err != nil {
+		return err
+	}
+
+	return nil
+}

+ 1 - 0
support/schema.sql

@@ -146,6 +146,7 @@ ALTER TABLE shop_products ADD KEY FK_shop_products_user (user);
 ALTER TABLE shop_products ADD KEY FK_shop_products_currency (currency);
 ALTER TABLE shop_products ADD KEY FK_shop_products_category (category);
 ALTER TABLE shop_products ADD KEY FK_shop_products_parent_id (parent_id);
+ALTER TABLE shop_products ADD KEY name (name);
 ALTER TABLE users ADD UNIQUE KEY email (email);
 
 # References