Browse Source

db.Exec -> db.ExecContext

Vova Tkach 5 years ago
parent
commit
58355f06cc

+ 3 - 5
engine/sqlw/sqlw.go

@@ -102,16 +102,14 @@ func (this *DB) Query(ctx context.Context, query string, args ...interface{}) (*
 	return this.db.Query(query, args...)
 }
 
-// TODO: func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error)
-// https://golang.org/pkg/database/sql/
-func (this *DB) Exec(query string, args ...interface{}) (sql.Result, error) {
+func (this *DB) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
 	if consts.ParamDebug {
 		s := time.Now()
-		r, e := this.db.Exec(query, args...)
+		r, e := this.db.ExecContext(ctx, query, args...)
 		log(query, s, e, false)
 		return r, e
 	}
-	return this.db.Exec(query, args...)
+	return this.db.ExecContext(ctx, query, args...)
 }
 
 // TODO: review

+ 2 - 0
engine/wrapper/wrapper.go

@@ -312,6 +312,7 @@ func (this *Wrapper) SendEmailUsual(email, subject, message string) error {
 	}
 
 	if _, err := this.DB.Exec(
+		this.R.Context(),
 		`INSERT INTO notify_mail SET
 			id = NULL,
 			email = ?,
@@ -344,6 +345,7 @@ func (this *Wrapper) SendEmailFast(email, subject, message string) error {
 	}
 
 	if _, err := this.DB.Exec(
+		this.R.Context(),
 		`INSERT INTO notify_mail SET
 			id = NULL,
 			email = ?,

+ 1 - 0
modules/module_index_act_cypress.go

@@ -35,6 +35,7 @@ func (this *Modules) RegisterAction_IndexCypressReset() *Action {
 		wrap.RemoveProductImageThumbnails("*", "*")
 
 		_, _ = db.Exec(
+			wrap.R.Context(),
 			`DROP TABLE
 				blog_cat_post_rel,
 				blog_cats,

+ 1 - 0
modules/module_index_act_first_user.go

@@ -52,6 +52,7 @@ func (this *Modules) RegisterAction_IndexFirstUser() *Action {
 		}
 
 		_, err = wrap.DB.Exec(
+			wrap.R.Context(),
 			`INSERT INTO users SET
 				id = 1,
 				first_name = ?,

+ 2 - 0
modules/module_index_act_update_profile.go

@@ -29,6 +29,7 @@ func (this *Modules) RegisterAction_IndexUserUpdateProfile() *Action {
 		if pf_password != "" {
 			// Update with password if set
 			_, err := wrap.DB.Exec(
+				wrap.R.Context(),
 				`UPDATE users SET
 					first_name = ?,
 					last_name = ?,
@@ -50,6 +51,7 @@ func (this *Modules) RegisterAction_IndexUserUpdateProfile() *Action {
 		} else {
 			// Update without password if not set
 			_, err := wrap.DB.Exec(
+				wrap.R.Context(),
 				`UPDATE users SET
 					first_name = ?,
 					last_name = ?,

+ 3 - 0
smtp.go

@@ -97,6 +97,7 @@ func smtp_prepare(ctx context.Context, db *sqlw.DB, conf *config.Config) {
 			err = rows.Scan(scan...)
 			if err == nil {
 				if _, err := db.Exec(
+					ctx,
 					`UPDATE notify_mail SET status = 3 WHERE id = ?;`,
 					utils.StrToInt(string(values[0])),
 				); err == nil {
@@ -112,6 +113,7 @@ func smtp_prepare(ctx context.Context, db *sqlw.DB, conf *config.Config) {
 							receivers,
 						); err == nil {
 							if _, err := db.Exec(
+								ctx,
 								`UPDATE notify_mail SET status = 1 WHERE id = ?;`,
 								id,
 							); err != nil {
@@ -119,6 +121,7 @@ func smtp_prepare(ctx context.Context, db *sqlw.DB, conf *config.Config) {
 							}
 						} else {
 							if _, err := db.Exec(
+								ctx,
 								`UPDATE notify_mail SET error = ?, status = 0 WHERE id = ?;`,
 								err.Error(),
 								id,

+ 6 - 2
support/migrate.sh

@@ -11,10 +11,12 @@ TARGET_FILE="./support/migrate/${NEXT_NUM_STR}.go"
 echo "package migrate" > $TARGET_FILE
 echo "" >> $TARGET_FILE
 echo "import (" >> $TARGET_FILE
+echo "	\"context\"" >> $TARGET_FILE
+echo "" >> $TARGET_FILE
 echo "	\"golang-fave/engine/sqlw\"" >> $TARGET_FILE
 echo ")" >> $TARGET_FILE
 echo "" >> $TARGET_FILE
-echo "func Migrate_${NEXT_NUM_STR}(db *sqlw.DB, host string) error {" >> $TARGET_FILE
+echo "func Migrate_${NEXT_NUM_STR}(ctx context.Context, db *sqlw.DB, host string) error {" >> $TARGET_FILE
 echo "	return nil" >> $TARGET_FILE
 echo "}" >> $TARGET_FILE
 
@@ -23,10 +25,12 @@ LIST_FILE="./support/migrate/000000001.go"
 echo "package migrate" > $LIST_FILE
 echo "" >> $LIST_FILE
 echo "import (" >> $LIST_FILE
+echo "	\"context\"" >> $LIST_FILE
+echo "" >> $LIST_FILE
 echo "	\"golang-fave/engine/sqlw\"" >> $LIST_FILE
 echo ")" >> $LIST_FILE
 echo "" >> $LIST_FILE
-echo "var Migrations = map[string]func(*sqlw.DB, string) error{" >> $LIST_FILE
+echo "var Migrations = map[string]func(context.Context, *sqlw.DB, string) error{" >> $LIST_FILE
 echo "	\"000000000\": nil," >> $LIST_FILE
 echo "	\"000000001\": nil," >> $LIST_FILE
 for i in `ls ./support/migrate/*.go | sort -V`; do

+ 4 - 3
support/migrate/000000000.go

@@ -1,20 +1,21 @@
 package migrate
 
 import (
+	"context"
 	"fmt"
 
 	"golang-fave/engine/sqlw"
 	"golang-fave/utils"
 )
 
-func Run(db *sqlw.DB, version int, host string) error {
+func Run(ctx context.Context, db *sqlw.DB, version int, host string) error {
 	var last string
 	for i, fn := range Migrations {
 		if utils.StrToInt(i) > 1 {
 			if version < utils.StrToInt(i) {
 				last = i
 				if fn != nil {
-					fn(db, host)
+					fn(ctx, db, host)
 					fmt.Printf("Migrated %s: %s\n", host, i)
 				}
 			}
@@ -22,7 +23,7 @@ func Run(db *sqlw.DB, version int, host string) error {
 	}
 
 	if last != "" {
-		if _, err := db.Exec(`UPDATE settings SET value = ? WHERE name = 'database_version';`, last); err != nil {
+		if _, err := db.Exec(ctx, `UPDATE settings SET value = ? WHERE name = 'database_version';`, last); err != nil {
 			return err
 		}
 	}

+ 3 - 1
support/migrate/000000001.go

@@ -1,10 +1,12 @@
 package migrate
 
 import (
+	"context"
+
 	"golang-fave/engine/sqlw"
 )
 
-var Migrations = map[string]func(*sqlw.DB, string) error{
+var Migrations = map[string]func(context.Context, *sqlw.DB, string) error{
 	"000000000": nil,
 	"000000001": nil,
 	"000000002": Migrate_000000002,

+ 3 - 1
support/migrate/000000002.go

@@ -1,10 +1,12 @@
 package migrate
 
 import (
+	"context"
+
 	"golang-fave/engine/sqlw"
 )
 
-func Migrate_000000002(db *sqlw.DB, host string) error {
+func Migrate_000000002(ctx context.Context, db *sqlw.DB, host string) error {
 	// Empty migration file
 	return nil
 }

+ 58 - 34
support/migrate/000000003.go

@@ -1,21 +1,24 @@
 package migrate
 
 import (
+	"context"
+
 	"golang-fave/engine/sqlw"
 	"golang-fave/utils"
 )
 
-func Migrate_000000003(db *sqlw.DB, host string) error {
+func Migrate_000000003(ctx context.Context, db *sqlw.DB, host string) error {
 	// Remove blog indexes
-	if _, err := db.Exec(`DROP INDEX post_id ON blog_cat_post_rel`); err != nil {
+	if _, err := db.Exec(ctx, `DROP INDEX post_id ON blog_cat_post_rel`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`DROP INDEX category_id ON blog_cat_post_rel`); err != nil {
+	if _, err := db.Exec(ctx, `DROP INDEX category_id ON blog_cat_post_rel`); err != nil {
 		return err
 	}
 
 	// Table: shop_cat_product_rel
 	if _, err := db.Exec(
+		ctx,
 		`CREATE TABLE shop_cat_product_rel (
 			id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
 			product_id int(11) NOT NULL COMMENT 'Product id',
@@ -28,6 +31,7 @@ func Migrate_000000003(db *sqlw.DB, host string) error {
 
 	// Table: shop_cats
 	if _, err := db.Exec(
+		ctx,
 		`CREATE TABLE shop_cats (
 			id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
 			user int(11) NOT NULL COMMENT 'User id',
@@ -43,6 +47,7 @@ func Migrate_000000003(db *sqlw.DB, host string) error {
 
 	// Table: shop_currencies
 	if _, err := db.Exec(
+		ctx,
 		`CREATE TABLE shop_currencies (
 			id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
 			name varchar(255) NOT NULL COMMENT 'Currency name',
@@ -57,6 +62,7 @@ func Migrate_000000003(db *sqlw.DB, host string) error {
 
 	// Table: shop_filter_product_values
 	if _, err := db.Exec(
+		ctx,
 		`CREATE TABLE shop_filter_product_values (
 			id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
 			product_id int(11) NOT NULL COMMENT 'Product id',
@@ -69,6 +75,7 @@ func Migrate_000000003(db *sqlw.DB, host string) error {
 
 	// Table: shop_filters
 	if _, err := db.Exec(
+		ctx,
 		`CREATE TABLE shop_filters (
 			id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
 			name varchar(255) NOT NULL COMMENT 'Filter name in CP',
@@ -81,6 +88,7 @@ func Migrate_000000003(db *sqlw.DB, host string) error {
 
 	// Table: shop_filters_values
 	if _, err := db.Exec(
+		ctx,
 		`CREATE TABLE shop_filters_values (
 			id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
 			filter_id int(11) NOT NULL COMMENT 'Filter id',
@@ -93,6 +101,7 @@ func Migrate_000000003(db *sqlw.DB, host string) error {
 
 	// Table: shop_products
 	if _, err := db.Exec(
+		ctx,
 		`CREATE TABLE shop_products (
 			id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
 			user int(11) NOT NULL COMMENT 'User id',
@@ -112,6 +121,7 @@ func Migrate_000000003(db *sqlw.DB, host string) error {
 
 	// Demo datas
 	if _, err := db.Exec(
+		ctx,
 		`INSERT INTO shop_cat_product_rel (id, product_id, category_id)
 			VALUES
 		(1, 1, 3);`,
@@ -119,6 +129,7 @@ func Migrate_000000003(db *sqlw.DB, host string) error {
 		return err
 	}
 	if _, err := db.Exec(
+		ctx,
 		`INSERT INTO shop_cats (id, user, name, alias, lft, rgt)
 			VALUES
 		(1, 1, 'ROOT', 'ROOT', 1, 6),
@@ -128,6 +139,7 @@ func Migrate_000000003(db *sqlw.DB, host string) error {
 		return err
 	}
 	if _, err := db.Exec(
+		ctx,
 		`INSERT INTO shop_currencies (id, name, coefficient, code, symbol)
 			VALUES
 		(1, 'US Dollar', 1.0000, 'USD', '$');`,
@@ -135,6 +147,7 @@ func Migrate_000000003(db *sqlw.DB, host string) error {
 		return err
 	}
 	if _, err := db.Exec(
+		ctx,
 		`INSERT INTO shop_filter_product_values (id, product_id, filter_value_id)
 			VALUES
 		(1, 1, 3),
@@ -146,6 +159,7 @@ func Migrate_000000003(db *sqlw.DB, host string) error {
 		return err
 	}
 	if _, err := db.Exec(
+		ctx,
 		`INSERT INTO shop_filters (id, name, filter)
 			VALUES
 		(1, 'Mobile phones manufacturer', 'Manufacturer'),
@@ -155,6 +169,7 @@ func Migrate_000000003(db *sqlw.DB, host string) error {
 		return err
 	}
 	if _, err := db.Exec(
+		ctx,
 		`INSERT INTO shop_filters_values (id, filter_id, name)
 			VALUES
 		(1, 1, 'Apple'),
@@ -172,6 +187,7 @@ func Migrate_000000003(db *sqlw.DB, host string) error {
 		return err
 	}
 	if _, err := db.Exec(
+		ctx,
 		`INSERT INTO shop_products SET
 			id = ?,
 			user = ?,
@@ -199,97 +215,105 @@ func Migrate_000000003(db *sqlw.DB, host string) error {
 	}
 
 	// Indexes
-	if _, err := db.Exec(`ALTER TABLE shop_cat_product_rel ADD UNIQUE KEY product_category (product_id,category_id) USING BTREE;`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_cat_product_rel ADD UNIQUE KEY product_category (product_id,category_id) USING BTREE;`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_cat_product_rel ADD KEY FK_shop_cat_product_rel_product_id (product_id);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_cat_product_rel ADD KEY FK_shop_cat_product_rel_product_id (product_id);`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_cat_product_rel ADD KEY FK_shop_cat_product_rel_category_id (category_id);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_cat_product_rel ADD KEY FK_shop_cat_product_rel_category_id (category_id);`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_cats ADD UNIQUE KEY alias (alias);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_cats ADD UNIQUE KEY alias (alias);`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_cats ADD KEY lft (lft), ADD KEY rgt (rgt);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_cats ADD KEY lft (lft), ADD KEY rgt (rgt);`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_cats ADD KEY FK_shop_cats_user (user);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_cats ADD KEY FK_shop_cats_user (user);`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_filter_product_values ADD UNIQUE KEY product_filter_value (product_id,filter_value_id) USING BTREE;`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_filter_product_values ADD UNIQUE KEY product_filter_value (product_id,filter_value_id) USING BTREE;`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_filter_product_values ADD KEY FK_shop_filter_product_values_product_id (product_id);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_filter_product_values ADD KEY FK_shop_filter_product_values_product_id (product_id);`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_filter_product_values ADD KEY FK_shop_filter_product_values_filter_value_id (filter_value_id);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_filter_product_values ADD KEY FK_shop_filter_product_values_filter_value_id (filter_value_id);`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_filters ADD KEY name (name);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_filters ADD KEY name (name);`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_filters_values ADD KEY FK_shop_filters_values_filter_id (filter_id);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_filters_values ADD KEY FK_shop_filters_values_filter_id (filter_id);`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_filters_values ADD KEY name (name);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_filters_values ADD KEY name (name);`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_products ADD UNIQUE KEY alias (alias);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_products ADD UNIQUE KEY alias (alias);`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_products ADD KEY FK_shop_products_user (user);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_products ADD KEY FK_shop_products_user (user);`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_products ADD KEY FK_shop_products_currency (currency);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_products ADD KEY FK_shop_products_currency (currency);`); err != nil {
 		return err
 	}
 
 	// References
-	if _, err := db.Exec(`
-		ALTER TABLE shop_cat_product_rel ADD CONSTRAINT FK_shop_cat_product_rel_product_id
+	if _, err := db.Exec(
+		ctx,
+		`ALTER TABLE shop_cat_product_rel ADD CONSTRAINT FK_shop_cat_product_rel_product_id
 		FOREIGN KEY (product_id) REFERENCES shop_products (id) ON DELETE RESTRICT;
 	`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`
-		ALTER TABLE shop_cat_product_rel ADD CONSTRAINT FK_shop_cat_product_rel_category_id
+	if _, err := db.Exec(
+		ctx,
+		`ALTER TABLE shop_cat_product_rel ADD CONSTRAINT FK_shop_cat_product_rel_category_id
 		FOREIGN KEY (category_id) REFERENCES shop_cats (id) ON DELETE RESTRICT;
 	`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`
-		ALTER TABLE shop_cats ADD CONSTRAINT FK_shop_cats_user
+	if _, err := db.Exec(
+		ctx,
+		`ALTER TABLE shop_cats ADD CONSTRAINT FK_shop_cats_user
 		FOREIGN KEY (user) REFERENCES users (id) ON DELETE RESTRICT;
 	`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`
-		ALTER TABLE shop_filter_product_values ADD CONSTRAINT FK_shop_filter_product_values_product_id
+	if _, err := db.Exec(
+		ctx,
+		`ALTER TABLE shop_filter_product_values ADD CONSTRAINT FK_shop_filter_product_values_product_id
 		FOREIGN KEY (product_id) REFERENCES shop_products (id) ON DELETE RESTRICT;
 	`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`
-		ALTER TABLE shop_filter_product_values ADD CONSTRAINT FK_shop_filter_product_values_filter_value_id
+	if _, err := db.Exec(
+		ctx,
+		`ALTER TABLE shop_filter_product_values ADD CONSTRAINT FK_shop_filter_product_values_filter_value_id
 		FOREIGN KEY (filter_value_id) REFERENCES shop_filters_values (id) ON DELETE RESTRICT;
 	`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`
-		ALTER TABLE shop_filters_values ADD CONSTRAINT FK_shop_filters_values_filter_id
+	if _, err := db.Exec(
+		ctx,
+		`ALTER TABLE shop_filters_values ADD CONSTRAINT FK_shop_filters_values_filter_id
 		FOREIGN KEY (filter_id) REFERENCES shop_filters (id) ON DELETE RESTRICT;
 	`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`
-		ALTER TABLE shop_products ADD CONSTRAINT FK_shop_products_user
+	if _, err := db.Exec(
+		ctx,
+		`ALTER TABLE shop_products ADD CONSTRAINT FK_shop_products_user
 		FOREIGN KEY (user) REFERENCES users (id) ON DELETE RESTRICT;
 	`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`
-		ALTER TABLE shop_products ADD CONSTRAINT FK_shop_products_currency
+	if _, err := db.Exec(
+		ctx,
+		`ALTER TABLE shop_products ADD CONSTRAINT FK_shop_products_currency
 		FOREIGN KEY (currency) REFERENCES shop_currencies (id) ON DELETE RESTRICT;
 	`); err != nil {
 		return err

+ 6 - 1
support/migrate/000000004.go

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

+ 2 - 1
support/migrate/000000005.go

@@ -1,6 +1,7 @@
 package migrate
 
 import (
+	"context"
 	"io/ioutil"
 	"os"
 
@@ -8,7 +9,7 @@ import (
 	"golang-fave/engine/sqlw"
 )
 
-func Migrate_000000005(db *sqlw.DB, host string) error {
+func Migrate_000000005(ctx context.Context, db *sqlw.DB, host string) error {
 	if err := ioutil.WriteFile(host+string(os.PathSeparator)+"/template/shop-category.html", ThemeFiles.AllData["shop-category.html"], 0664); err != nil {
 		return err
 	}

+ 9 - 5
support/migrate/000000006.go

@@ -1,12 +1,15 @@
 package migrate
 
 import (
+	"context"
+
 	"golang-fave/engine/sqlw"
 )
 
-func Migrate_000000006(db *sqlw.DB, host string) error {
+func Migrate_000000006(ctx context.Context, db *sqlw.DB, host string) error {
 	// Table: shop_product_images
 	if _, err := db.Exec(
+		ctx,
 		`CREATE TABLE shop_product_images (
 			product_id int(11) NOT NULL,
 			filename varchar(255) NOT NULL
@@ -16,16 +19,17 @@ func Migrate_000000006(db *sqlw.DB, host string) error {
 	}
 
 	// Indexes
-	if _, err := db.Exec(`ALTER TABLE shop_product_images ADD UNIQUE KEY product_filename (product_id,filename) USING BTREE;`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_product_images ADD UNIQUE KEY product_filename (product_id,filename) USING BTREE;`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_product_images ADD KEY FK_shop_product_images_product_id (product_id);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_product_images ADD KEY FK_shop_product_images_product_id (product_id);`); err != nil {
 		return err
 	}
 
 	// References
-	if _, err := db.Exec(`
-		ALTER TABLE shop_product_images ADD CONSTRAINT FK_shop_product_images_product_id
+	if _, err := db.Exec(
+		ctx,
+		`ALTER TABLE shop_product_images ADD CONSTRAINT FK_shop_product_images_product_id
 		FOREIGN KEY (product_id) REFERENCES shop_products (id) ON DELETE RESTRICT;
 	`); err != nil {
 		return err

+ 13 - 10
support/migrate/000000007.go

@@ -1,42 +1,45 @@
 package migrate
 
 import (
+	"context"
+
 	"golang-fave/engine/sqlw"
 )
 
-func Migrate_000000007(db *sqlw.DB, host string) error {
+func Migrate_000000007(ctx context.Context, db *sqlw.DB, host string) error {
 	// Changes
-	if _, err := db.Exec(`ALTER TABLE shop_products ADD COLUMN vendor VARCHAR(255) NOT NULL DEFAULT '' AFTER alias;`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_products ADD COLUMN vendor VARCHAR(255) NOT NULL DEFAULT '' AFTER alias;`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_products ADD COLUMN quantity INT(11) NOT NULL DEFAULT 0 AFTER vendor;`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_products ADD COLUMN quantity INT(11) NOT NULL DEFAULT 0 AFTER vendor;`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_products ADD COLUMN category INT(11) NOT NULL DEFAULT 1 AFTER quantity;`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_products ADD COLUMN category INT(11) NOT NULL DEFAULT 1 AFTER quantity;`); err != nil {
 		return err
 	}
 
 	// Indexes
-	if _, err := db.Exec(`ALTER TABLE shop_products ADD KEY FK_shop_products_category (category);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_products ADD KEY FK_shop_products_category (category);`); err != nil {
 		return err
 	}
 
 	// References
-	if _, err := db.Exec(`
-		ALTER TABLE shop_products ADD CONSTRAINT FK_shop_products_category
+	if _, err := db.Exec(
+		ctx,
+		`ALTER TABLE shop_products ADD CONSTRAINT FK_shop_products_category
 		FOREIGN KEY (category) REFERENCES shop_cats (id) ON DELETE RESTRICT;
 	`); err != nil {
 		return err
 	}
 
 	// Remove default
-	if _, err := db.Exec(`ALTER TABLE shop_products ALTER vendor DROP DEFAULT;`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_products ALTER vendor DROP DEFAULT;`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_products ALTER quantity DROP DEFAULT;`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_products ALTER quantity DROP DEFAULT;`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_products ALTER category DROP DEFAULT;`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_products ALTER category DROP DEFAULT;`); err != nil {
 		return err
 	}
 

+ 9 - 6
support/migrate/000000008.go

@@ -1,30 +1,33 @@
 package migrate
 
 import (
+	"context"
+
 	"golang-fave/engine/sqlw"
 )
 
-func Migrate_000000008(db *sqlw.DB, host string) error {
+func Migrate_000000008(ctx context.Context, db *sqlw.DB, host string) error {
 	// Changes
-	if _, err := db.Exec(`ALTER TABLE blog_posts ADD COLUMN category INT(11) NOT NULL DEFAULT 1 AFTER alias;`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE blog_posts ADD COLUMN category INT(11) NOT NULL DEFAULT 1 AFTER alias;`); err != nil {
 		return err
 	}
 
 	// Indexes
-	if _, err := db.Exec(`ALTER TABLE blog_posts ADD KEY FK_blog_posts_category (category);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE blog_posts ADD KEY FK_blog_posts_category (category);`); err != nil {
 		return err
 	}
 
 	// References
-	if _, err := db.Exec(`
-		ALTER TABLE blog_posts ADD CONSTRAINT FK_blog_posts_category
+	if _, err := db.Exec(
+		ctx,
+		`ALTER TABLE blog_posts ADD CONSTRAINT FK_blog_posts_category
 		FOREIGN KEY (category) REFERENCES blog_cats (id) ON DELETE RESTRICT;
 	`); err != nil {
 		return err
 	}
 
 	// Remove default
-	if _, err := db.Exec(`ALTER TABLE blog_posts ALTER category DROP DEFAULT;`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE blog_posts ALTER category DROP DEFAULT;`); err != nil {
 		return err
 	}
 

+ 2 - 1
support/migrate/000000009.go

@@ -1,6 +1,7 @@
 package migrate
 
 import (
+	"context"
 	"io/ioutil"
 	"os"
 
@@ -8,7 +9,7 @@ import (
 	"golang-fave/engine/sqlw"
 )
 
-func Migrate_000000009(db *sqlw.DB, host string) error {
+func Migrate_000000009(ctx context.Context, db *sqlw.DB, host string) error {
 	if err := ioutil.WriteFile(host+string(os.PathSeparator)+"/template/cached-block-1.html", ThemeFiles.AllData["cached-block-1.html"], 0664); err != nil {
 		return err
 	}

+ 8 - 5
support/migrate/000000010.go

@@ -1,23 +1,26 @@
 package migrate
 
 import (
+	"context"
+
 	"golang-fave/engine/sqlw"
 )
 
-func Migrate_000000010(db *sqlw.DB, host string) error {
+func Migrate_000000010(ctx context.Context, db *sqlw.DB, host string) error {
 	// Changes
-	if _, err := db.Exec(`ALTER TABLE shop_products ADD COLUMN parent_id INT(11) DEFAULT NULL AFTER id;`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_products ADD COLUMN parent_id INT(11) DEFAULT NULL AFTER id;`); err != nil {
 		return err
 	}
 
 	// Indexes
-	if _, err := db.Exec(`ALTER TABLE shop_products ADD KEY FK_shop_products_parent_id (parent_id);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_products ADD KEY FK_shop_products_parent_id (parent_id);`); err != nil {
 		return err
 	}
 
 	// References
-	if _, err := db.Exec(`
-		ALTER TABLE shop_products ADD CONSTRAINT FK_shop_products_parent_id
+	if _, err := db.Exec(
+		ctx,
+		`ALTER TABLE shop_products ADD CONSTRAINT FK_shop_products_parent_id
 		FOREIGN KEY (parent_id) REFERENCES shop_products (id) ON DELETE RESTRICT;
 	`); err != nil {
 		return err

+ 6 - 4
support/migrate/000000011.go

@@ -1,19 +1,21 @@
 package migrate
 
 import (
+	"context"
+
 	"golang-fave/engine/sqlw"
 )
 
-func Migrate_000000011(db *sqlw.DB, host string) error {
-	if _, err := db.Exec(`ALTER TABLE shop_product_images ADD id INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;`); err != nil {
+func Migrate_000000011(ctx context.Context, db *sqlw.DB, host string) error {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_product_images ADD id INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;`); err != nil {
 		return err
 	}
 
-	if _, err := db.Exec(`ALTER TABLE shop_product_images ADD COLUMN ord INT(11) NOT NULL DEFAULT 0 AFTER filename;`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_product_images ADD COLUMN ord INT(11) NOT NULL DEFAULT 0 AFTER filename;`); err != nil {
 		return err
 	}
 
-	if _, err := db.Exec(`UPDATE shop_product_images SET ord = id;`); err != nil {
+	if _, err := db.Exec(ctx, `UPDATE shop_product_images SET ord = id;`); err != nil {
 		return err
 	}
 

+ 4 - 2
support/migrate/000000012.go

@@ -1,11 +1,13 @@
 package migrate
 
 import (
+	"context"
+
 	"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 {
+func Migrate_000000012(ctx context.Context, db *sqlw.DB, host string) error {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_products ADD KEY name (name);`); err != nil {
 		return err
 	}
 

+ 5 - 3
support/migrate/000000013.go

@@ -1,15 +1,17 @@
 package migrate
 
 import (
+	"context"
+
 	"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 {
+func Migrate_000000013(ctx context.Context, db *sqlw.DB, host string) error {
+	if _, err := db.Exec(ctx, `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 {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_products ALTER gname DROP DEFAULT;`); err != nil {
 		return err
 	}
 

+ 5 - 2
support/migrate/000000014.go

@@ -1,12 +1,15 @@
 package migrate
 
 import (
+	"context"
+
 	"golang-fave/engine/sqlw"
 )
 
-func Migrate_000000014(db *sqlw.DB, host string) error {
+func Migrate_000000014(ctx context.Context, db *sqlw.DB, host string) error {
 	// Table: notify_mail
 	if _, err := db.Exec(
+		ctx,
 		`CREATE TABLE notify_mail (
 			id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
 			email varchar(255) NOT NULL COMMENT 'Email address',
@@ -22,7 +25,7 @@ func Migrate_000000014(db *sqlw.DB, host string) error {
 	}
 
 	// Indexes
-	if _, err := db.Exec(`ALTER TABLE notify_mail ADD KEY status (status);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE notify_mail ADD KEY status (status);`); err != nil {
 		return err
 	}
 

+ 18 - 11
support/migrate/000000015.go

@@ -1,12 +1,15 @@
 package migrate
 
 import (
+	"context"
+
 	"golang-fave/engine/sqlw"
 )
 
-func Migrate_000000015(db *sqlw.DB, host string) error {
+func Migrate_000000015(ctx context.Context, db *sqlw.DB, host string) error {
 	// Table: shop_orders
 	if _, err := db.Exec(
+		ctx,
 		`CREATE TABLE shop_orders (
 			id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
 			create_datetime datetime NOT NULL COMMENT 'Create date/time',
@@ -32,6 +35,7 @@ func Migrate_000000015(db *sqlw.DB, host string) error {
 
 	// Table: shop_order_products
 	if _, err := db.Exec(
+		ctx,
 		`CREATE TABLE shop_order_products (
 			id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
 			order_id int(11) NOT NULL COMMENT 'Order ID',
@@ -45,34 +49,37 @@ func Migrate_000000015(db *sqlw.DB, host string) error {
 	}
 
 	// Indexes
-	if _, err := db.Exec(`ALTER TABLE shop_orders ADD KEY FK_shop_orders_currency_id (currency_id);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_orders ADD KEY FK_shop_orders_currency_id (currency_id);`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_order_products ADD UNIQUE KEY order_product (order_id,product_id) USING BTREE;`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_order_products ADD UNIQUE KEY order_product (order_id,product_id) USING BTREE;`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_order_products ADD KEY FK_shop_order_products_order_id (order_id);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_order_products ADD KEY FK_shop_order_products_order_id (order_id);`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`ALTER TABLE shop_order_products ADD KEY FK_shop_order_products_product_id (product_id);`); err != nil {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_order_products ADD KEY FK_shop_order_products_product_id (product_id);`); err != nil {
 		return err
 	}
 
 	// References
-	if _, err := db.Exec(`
-		ALTER TABLE shop_orders ADD CONSTRAINT FK_shop_orders_currency_id
+	if _, err := db.Exec(
+		ctx,
+		`ALTER TABLE shop_orders ADD CONSTRAINT FK_shop_orders_currency_id
 		FOREIGN KEY (currency_id) REFERENCES shop_currencies (id) ON DELETE RESTRICT;
 	`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`
-		ALTER TABLE shop_order_products ADD CONSTRAINT FK_shop_order_products_order_id
+	if _, err := db.Exec(
+		ctx,
+		`ALTER TABLE shop_order_products ADD CONSTRAINT FK_shop_order_products_order_id
 		FOREIGN KEY (order_id) REFERENCES shop_orders (id) ON DELETE RESTRICT;
 	`); err != nil {
 		return err
 	}
-	if _, err := db.Exec(`
-		ALTER TABLE shop_order_products ADD CONSTRAINT FK_shop_order_products_product_id
+	if _, err := db.Exec(
+		ctx,
+		`ALTER TABLE shop_order_products ADD CONSTRAINT FK_shop_order_products_product_id
 		FOREIGN KEY (product_id) REFERENCES shop_products (id) ON DELETE RESTRICT;
 	`); err != nil {
 		return err

+ 4 - 2
support/migrate/000000016.go

@@ -1,11 +1,13 @@
 package migrate
 
 import (
+	"context"
+
 	"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 {
+func Migrate_000000016(ctx context.Context, db *sqlw.DB, host string) error {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_products ADD COLUMN price_old float(8,2) NOT NULL DEFAULT '0.00' AFTER price;`); err != nil {
 		return err
 	}
 

+ 2 - 1
support/migrate/000000017.go

@@ -1,6 +1,7 @@
 package migrate
 
 import (
+	"context"
 	"io/ioutil"
 	"os"
 
@@ -8,7 +9,7 @@ import (
 	"golang-fave/engine/sqlw"
 )
 
-func Migrate_000000017(db *sqlw.DB, host string) error {
+func Migrate_000000017(ctx context.Context, db *sqlw.DB, host string) error {
 	if err := ioutil.WriteFile(host+string(os.PathSeparator)+"/template/email-new-order-admin.html", ThemeFiles.AllData["email-new-order-admin.html"], 0664); err != nil {
 		return err
 	}

+ 4 - 2
support/migrate/000000018.go

@@ -1,11 +1,13 @@
 package migrate
 
 import (
+	"context"
+
 	"golang-fave/engine/sqlw"
 )
 
-func Migrate_000000018(db *sqlw.DB, host string) error {
-	if _, err := db.Exec(`UPDATE notify_mail SET status = 0, error = 'SMTP server is not configured' WHERE status = 2;`); err != nil {
+func Migrate_000000018(ctx context.Context, db *sqlw.DB, host string) error {
+	if _, err := db.Exec(ctx, `UPDATE notify_mail SET status = 0, error = 'SMTP server is not configured' WHERE status = 2;`); err != nil {
 		return err
 	}
 

+ 5 - 3
support/migrate/000000019.go

@@ -1,15 +1,17 @@
 package migrate
 
 import (
+	"context"
+
 	"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 {
+func Migrate_000000019(ctx context.Context, db *sqlw.DB, host string) error {
+	if _, err := db.Exec(ctx, `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 {
+	if _, err := db.Exec(ctx, `ALTER TABLE shop_products ADD COLUMN custom2 varchar(2048) NOT NULL DEFAULT '' AFTER custom1;`); err != nil {
 		return err
 	}
 

+ 4 - 2
support/migrate/000000020.go

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

+ 5 - 3
support/support.go

@@ -66,6 +66,7 @@ func (this *Support) Migrate(ctx context.Context, host string) error {
 		if err := db.QueryRow(ctx, `SELECT value FROM settings WHERE name = 'database_version' LIMIT 1;`).Scan(&version); err != nil {
 			if this.isSettingsTableDoesntExist(err) {
 				if _, err := db.Exec(
+					ctx,
 					`CREATE TABLE settings (
 						name varchar(255) NOT NULL COMMENT 'Setting name',
 						value text NOT NULL COMMENT 'Setting value'
@@ -74,6 +75,7 @@ func (this *Support) Migrate(ctx context.Context, host string) error {
 					return err
 				}
 				if _, err := db.Exec(
+					ctx,
 					`INSERT INTO settings (name, value) VALUES ('database_version', '000000002');`,
 				); err != nil {
 					return err
@@ -83,11 +85,11 @@ func (this *Support) Migrate(ctx context.Context, host string) error {
 			}
 			return err
 		}
-		return this.Process(db, version, host)
+		return this.Process(ctx, db, version, host)
 	}
 	return nil
 }
 
-func (this *Support) Process(db *sqlw.DB, version string, host string) error {
-	return migrate.Run(db, utils.StrToInt(version), host)
+func (this *Support) Process(ctx context.Context, db *sqlw.DB, version string, host string) error {
+	return migrate.Run(ctx, db, utils.StrToInt(version), host)
 }