Browse Source

Migration, mailer database table, update install sqls

Vova Tkach 5 years ago
parent
commit
d4b0b010fb

+ 23 - 1
modules/module_index_act_mysql_setup.go

@@ -120,6 +120,23 @@ func (this *Modules) RegisterAction_IndexMysqlSetup() *Action {
 			return
 		}
 
+		// Table: notify_mail
+		if _, err = tx.Exec(
+			`CREATE TABLE notify_mail (
+				id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
+				email varchar(255) NOT NULL COMMENT 'Email address',
+				subject varchar(800) NOT NULL COMMENT 'Email subject',
+				message text NOT NULL COMMENT 'Email body',
+				error text NOT NULL COMMENT 'Send error message',
+				status int(1) NOT NULL COMMENT 'Sending status',
+				PRIMARY KEY (id)
+			) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
+		); err != nil {
+			tx.Rollback()
+			wrap.MsgError(err.Error())
+			return
+		}
+
 		// Table: pages
 		if _, err = tx.Exec(
 			`CREATE TABLE pages (
@@ -470,7 +487,7 @@ func (this *Modules) RegisterAction_IndexMysqlSetup() *Action {
 			return
 		}
 		if _, err = tx.Exec(
-			`INSERT INTO settings (name, value) VALUES ('database_version', '000000013');`,
+			`INSERT INTO settings (name, value) VALUES ('database_version', '000000014');`,
 		); err != nil {
 			tx.Rollback()
 			wrap.MsgError(err.Error())
@@ -638,6 +655,11 @@ func (this *Modules) RegisterAction_IndexMysqlSetup() *Action {
 			wrap.MsgError(err.Error())
 			return
 		}
+		if _, err = tx.Exec(`ALTER TABLE notify_mail ADD KEY status (status);`); err != nil {
+			tx.Rollback()
+			wrap.MsgError(err.Error())
+			return
+		}
 		if _, err = tx.Exec(`ALTER TABLE pages ADD UNIQUE KEY alias (alias);`); err != nil {
 			tx.Rollback()
 			wrap.MsgError(err.Error())

+ 1 - 0
support/migrate/000000001.go

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

+ 29 - 0
support/migrate/000000014.go

@@ -0,0 +1,29 @@
+package migrate
+
+import (
+	"golang-fave/engine/sqlw"
+)
+
+func Migrate_000000014(db *sqlw.DB, host string) error {
+	// Table: notify_mail
+	if _, err := db.Exec(
+		`CREATE TABLE notify_mail (
+			id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
+			email varchar(255) NOT NULL COMMENT 'Email address',
+			subject varchar(800) NOT NULL COMMENT 'Email subject',
+			message text NOT NULL COMMENT 'Email body',
+			error text NOT NULL COMMENT 'Send error message',
+			status int(1) NOT NULL COMMENT 'Sending status',
+			PRIMARY KEY (id)
+		) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
+	); err != nil {
+		return err
+	}
+
+	// Indexes
+	if _, err := db.Exec(`ALTER TABLE notify_mail ADD KEY status (status);`); err != nil {
+		return err
+	}
+
+	return nil
+}

+ 10 - 0
support/schema.sql

@@ -24,6 +24,15 @@ CREATE TABLE blog_posts (
 	active int(1) NOT NULL COMMENT 'Is active post or not',
 	PRIMARY KEY (id)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+CREATE TABLE notify_mail (
+	id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
+	email varchar(255) NOT NULL COMMENT 'Email address',
+	subject varchar(800) NOT NULL COMMENT 'Email subject',
+	message text NOT NULL COMMENT 'Email body',
+	error text NOT NULL COMMENT 'Send error message',
+	status int(1) NOT NULL COMMENT 'Sending status',
+	PRIMARY KEY (id)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 CREATE TABLE pages (
 	id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
 	user int(11) NOT NULL COMMENT 'User id',
@@ -124,6 +133,7 @@ ALTER TABLE blog_cats ADD KEY FK_blog_cats_user (user);
 ALTER TABLE blog_posts ADD UNIQUE KEY alias (alias);
 ALTER TABLE blog_posts ADD KEY FK_blog_posts_user (user);
 ALTER TABLE blog_posts ADD KEY FK_blog_posts_category (category);
+ALTER TABLE notify_mail ADD KEY status (status);
 ALTER TABLE pages ADD UNIQUE KEY alias (alias);
 ALTER TABLE pages ADD KEY alias_active (alias,active) USING BTREE;
 ALTER TABLE pages ADD KEY FK_pages_user (user);