Browse Source

Migration for old price

Vova Tkach 5 years ago
parent
commit
57b95fc14f

+ 2 - 1
modules/module_index_act_mysql_setup.go

@@ -322,6 +322,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',
+				price_old float(8,2) NOT NULL DEFAULT '0.00',
 				gname varchar(255) NOT NULL,
 				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',
@@ -531,7 +532,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', '000000015');`,
+			`INSERT INTO settings (name, value) VALUES ('database_version', '000000016');`,
 		); err != nil {
 		); err != nil {
 			tx.Rollback()
 			tx.Rollback()
 			wrap.MsgError(err.Error())
 			wrap.MsgError(err.Error())

+ 1 - 0
support/migrate/000000001.go

@@ -21,4 +21,5 @@ var Migrations = map[string]func(*sqlw.DB, string) error{
 	"000000013": Migrate_000000013,
 	"000000013": Migrate_000000013,
 	"000000014": Migrate_000000014,
 	"000000014": Migrate_000000014,
 	"000000015": Migrate_000000015,
 	"000000015": Migrate_000000015,
+	"000000016": Migrate_000000016,
 }
 }

+ 13 - 0
support/migrate/000000016.go

@@ -0,0 +1,13 @@
+package migrate
+
+import (
+	"golang-fave/engine/sqlw"
+)
+
+func Migrate_000000016(db *sqlw.DB, host string) error {
+	if _, err := db.Exec(`ALTER TABLE shop_products ADD COLUMN price_old float(8,2) NOT NULL DEFAULT '0.00' AFTER price;`); err != nil {
+		return err
+	}
+
+	return nil
+}

+ 1 - 0
support/schema.sql

@@ -128,6 +128,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',
+	price_old float(8,2) NOT NULL DEFAULT '0.00',
 	gname varchar(255) NOT NULL,
 	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',