Browse Source

Product custom fields, migration, update install scenario

Vova Tkach 5 years ago
parent
commit
fd3275b4a1

+ 3 - 1
modules/module_index_act_mysql_setup.go

@@ -333,6 +333,8 @@ func (this *Modules) RegisterAction_IndexMysqlSetup() *Action {
 				content text NOT NULL COMMENT 'Product content',
 				content text NOT NULL COMMENT 'Product content',
 				datetime datetime NOT NULL COMMENT 'Creation date/time',
 				datetime datetime NOT NULL COMMENT 'Creation date/time',
 				active int(1) NOT NULL COMMENT 'Is active product or not',
 				active int(1) NOT NULL COMMENT 'Is active product or not',
+				custom1 varchar(2048) NOT NULL DEFAULT '',
+				custom2 varchar(2048) NOT NULL DEFAULT '',
 				PRIMARY KEY (id)
 				PRIMARY KEY (id)
 			) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
 			) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
 		); err != nil {
 		); err != nil {
@@ -532,7 +534,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', '000000018');`,
+			`INSERT INTO settings (name, value) VALUES ('database_version', '000000019');`,
 		); err != nil {
 		); err != nil {
 			tx.Rollback()
 			tx.Rollback()
 			wrap.MsgError(err.Error())
 			wrap.MsgError(err.Error())

+ 1 - 0
support/migrate/000000001.go

@@ -24,4 +24,5 @@ var Migrations = map[string]func(*sqlw.DB, string) error{
 	"000000016": Migrate_000000016,
 	"000000016": Migrate_000000016,
 	"000000017": Migrate_000000017,
 	"000000017": Migrate_000000017,
 	"000000018": Migrate_000000018,
 	"000000018": Migrate_000000018,
+	"000000019": Migrate_000000019,
 }
 }

+ 17 - 0
support/migrate/000000019.go

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

+ 2 - 0
support/schema.sql

@@ -139,6 +139,8 @@ CREATE TABLE shop_products (
 	content text NOT NULL COMMENT 'Product content',
 	content text NOT NULL COMMENT 'Product content',
 	datetime datetime NOT NULL COMMENT 'Creation date/time',
 	datetime datetime NOT NULL COMMENT 'Creation date/time',
 	active int(1) NOT NULL COMMENT 'Is active product or not',
 	active int(1) NOT NULL COMMENT 'Is active product or not',
+	custom1 varchar(2048) NOT NULL DEFAULT '',
+	custom2 varchar(2048) NOT NULL DEFAULT '',
 	PRIMARY KEY (id)
 	PRIMARY KEY (id)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 CREATE TABLE users (
 CREATE TABLE users (