Browse Source

Migration for product group name

Vova Tkach 5 years ago
parent
commit
009e673a11

+ 2 - 1
modules/module_index_act_mysql_setup.go

@@ -261,6 +261,7 @@ func (this *Modules) RegisterAction_IndexMysqlSetup() *Action {
 				user int(11) NOT NULL COMMENT 'User id',
 				user int(11) NOT NULL COMMENT 'User id',
 				currency int(11) NOT NULL COMMENT 'Currency id',
 				currency int(11) NOT NULL COMMENT 'Currency id',
 				price float(8,2) NOT NULL COMMENT 'Product price',
 				price float(8,2) NOT NULL COMMENT 'Product price',
+				gname varchar(255) NOT NULL,
 				name varchar(255) NOT NULL COMMENT 'Product name',
 				name varchar(255) NOT NULL COMMENT 'Product name',
 				alias varchar(255) NOT NULL COMMENT 'Product alias',
 				alias varchar(255) NOT NULL COMMENT 'Product alias',
 				vendor varchar(255) NOT NULL,
 				vendor varchar(255) NOT NULL,
@@ -469,7 +470,7 @@ func (this *Modules) RegisterAction_IndexMysqlSetup() *Action {
 			return
 			return
 		}
 		}
 		if _, err = tx.Exec(
 		if _, err = tx.Exec(
-			`INSERT INTO settings (name, value) VALUES ('database_version', '000000012');`,
+			`INSERT INTO settings (name, value) VALUES ('database_version', '000000013');`,
 		); err != nil {
 		); err != nil {
 			tx.Rollback()
 			tx.Rollback()
 			wrap.MsgError(err.Error())
 			wrap.MsgError(err.Error())

+ 2 - 0
modules/module_shop_act_duplicate.go

@@ -46,6 +46,7 @@ func (this *Modules) RegisterAction_ShopDuplicate() *Action {
 					user,
 					user,
 					currency,
 					currency,
 					price,
 					price,
+					gname,
 					name,
 					name,
 					alias,
 					alias,
 					vendor,
 					vendor,
@@ -60,6 +61,7 @@ func (this *Modules) RegisterAction_ShopDuplicate() *Action {
 					user,
 					user,
 					currency,
 					currency,
 					price,
 					price,
+					'',
 					CONCAT(name, ' (Copy)'),
 					CONCAT(name, ' (Copy)'),
 					CONCAT(REGEXP_REPLACE(alias, '-c[0-9]+$', ''), '-c', '`+utils.Int64ToStr(time.Now().Unix())+`'),
 					CONCAT(REGEXP_REPLACE(alias, '-c[0-9]+$', ''), '-c', '`+utils.Int64ToStr(time.Now().Unix())+`'),
 					vendor,
 					vendor,

+ 5 - 0
modules/module_shop_act_modify.go

@@ -15,6 +15,7 @@ func (this *Modules) RegisterAction_ShopModify() *Action {
 		WantAdmin: true,
 		WantAdmin: true,
 	}, func(wrap *wrapper.Wrapper) {
 	}, func(wrap *wrapper.Wrapper) {
 		pf_id := wrap.R.FormValue("id")
 		pf_id := wrap.R.FormValue("id")
+		pf_gname := wrap.R.FormValue("gname")
 		pf_name := wrap.R.FormValue("name")
 		pf_name := wrap.R.FormValue("name")
 		pf_price := wrap.R.FormValue("price")
 		pf_price := wrap.R.FormValue("price")
 		pf_currency := wrap.R.FormValue("currency")
 		pf_currency := wrap.R.FormValue("currency")
@@ -95,6 +96,7 @@ func (this *Modules) RegisterAction_ShopModify() *Action {
 						user = ?,
 						user = ?,
 						currency = ?,
 						currency = ?,
 						price = ?,
 						price = ?,
+						gname = ?,
 						name = ?,
 						name = ?,
 						alias = ?,
 						alias = ?,
 						vendor = ?,
 						vendor = ?,
@@ -108,6 +110,7 @@ func (this *Modules) RegisterAction_ShopModify() *Action {
 					wrap.User.A_id,
 					wrap.User.A_id,
 					utils.StrToInt(pf_currency),
 					utils.StrToInt(pf_currency),
 					utils.StrToFloat64(pf_price),
 					utils.StrToFloat64(pf_price),
+					pf_gname,
 					pf_name,
 					pf_name,
 					pf_alias,
 					pf_alias,
 					pf_vendor,
 					pf_vendor,
@@ -210,6 +213,7 @@ func (this *Modules) RegisterAction_ShopModify() *Action {
 					`UPDATE shop_products SET
 					`UPDATE shop_products SET
 						currency = ?,
 						currency = ?,
 						price = ?,
 						price = ?,
+						gname = ?,
 						name = ?,
 						name = ?,
 						alias = ?,
 						alias = ?,
 						vendor = ?,
 						vendor = ?,
@@ -223,6 +227,7 @@ func (this *Modules) RegisterAction_ShopModify() *Action {
 					;`,
 					;`,
 					utils.StrToInt(pf_currency),
 					utils.StrToInt(pf_currency),
 					utils.StrToFloat64(pf_price),
 					utils.StrToFloat64(pf_price),
+					pf_gname,
 					pf_name,
 					pf_name,
 					pf_alias,
 					pf_alias,
 					pf_vendor,
 					pf_vendor,

+ 1 - 0
support/migrate/000000001.go

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

+ 17 - 0
support/migrate/000000013.go

@@ -0,0 +1,17 @@
+package migrate
+
+import (
+	"golang-fave/engine/sqlw"
+)
+
+func Migrate_000000013(db *sqlw.DB, host string) error {
+	if _, err := db.Exec(`ALTER TABLE shop_products ADD COLUMN gname VARCHAR(255) NOT NULL DEFAULT '' AFTER price;`); err != nil {
+		return err
+	}
+
+	if _, err := db.Exec(`ALTER TABLE shop_products ALTER gname DROP DEFAULT;`); err != nil {
+		return err
+	}
+
+	return nil
+}

+ 1 - 0
support/schema.sql

@@ -91,6 +91,7 @@ CREATE TABLE shop_products (
 	user int(11) NOT NULL COMMENT 'User id',
 	user int(11) NOT NULL COMMENT 'User id',
 	currency int(11) NOT NULL COMMENT 'Currency id',
 	currency int(11) NOT NULL COMMENT 'Currency id',
 	price float(8,2) NOT NULL COMMENT 'Product price',
 	price float(8,2) NOT NULL COMMENT 'Product price',
+	gname varchar(255) NOT NULL,
 	name varchar(255) NOT NULL COMMENT 'Product name',
 	name varchar(255) NOT NULL COMMENT 'Product name',
 	alias varchar(255) NOT NULL COMMENT 'Product alias',
 	alias varchar(255) NOT NULL COMMENT 'Product alias',
 	vendor varchar(255) NOT NULL,
 	vendor varchar(255) NOT NULL,