summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2015-07-15 09:52:46 -0800
committerCorey Hulen <corey@hulen.com>2015-07-15 09:52:46 -0800
commit593556d30d4d85abae30ca4755b817d618a318c1 (patch)
tree9e5c02ccf47c0aef28161df7b1017d270b5055d9 /store
parent31e9c6ae49cdddd241687a08c0a8e9251a00dca2 (diff)
parentc84baf230ccb6f95fcf43798a3eb837c625639db (diff)
downloadchat-593556d30d4d85abae30ca4755b817d618a318c1.tar.gz
chat-593556d30d4d85abae30ca4755b817d618a318c1.tar.bz2
chat-593556d30d4d85abae30ca4755b817d618a318c1.zip
Merge pull request #153 from nickago/MM-1460
MM-1460 Updated database schema for emoji compatibility
Diffstat (limited to 'store')
-rw-r--r--store/sql_post_store.go5
-rw-r--r--store/sql_store.go12
2 files changed, 15 insertions, 2 deletions
diff --git a/store/sql_post_store.go b/store/sql_post_store.go
index 7ada515d7..5b9ebfdf2 100644
--- a/store/sql_post_store.go
+++ b/store/sql_post_store.go
@@ -35,6 +35,11 @@ func NewSqlPostStore(sqlStore *SqlStore) PostStore {
}
func (s SqlPostStore) UpgradeSchemaIfNeeded() {
+
+ // These execs are for upgrading currently created databases to full utf8mb4 compliance
+ // Will be removed as seen fit for upgrading
+ s.GetMaster().Exec("ALTER TABLE Posts charset=utf8mb4")
+ s.GetMaster().Exec("ALTER TABLE Posts MODIFY COLUMN Message varchar(4000) CHARACTER SET utf8mb4")
}
func (s SqlPostStore) CreateIndexesIfNotExists() {
diff --git a/store/sql_store.go b/store/sql_store.go
index a0a1a9f23..7a2d059b9 100644
--- a/store/sql_store.go
+++ b/store/sql_store.go
@@ -24,6 +24,7 @@ import (
sqltrace "log"
"math/rand"
"os"
+ "strings"
"time"
)
@@ -81,7 +82,14 @@ func NewSqlStore() Store {
func setupConnection(con_type string, driver string, dataSource string, maxIdle int, maxOpen int, trace bool) *gorp.DbMap {
- db, err := dbsql.Open(driver, dataSource)
+ charset := ""
+ if strings.Index(dataSource, "?") > -1 {
+ charset = "&charset=utf8mb4,utf8"
+ } else {
+ charset = "?charset=utf8mb4,utf8"
+ }
+
+ db, err := dbsql.Open(driver, dataSource+charset)
if err != nil {
l4g.Critical("Failed to open sql connection to '%v' err:%v", dataSource, err)
time.Sleep(time.Second)
@@ -104,7 +112,7 @@ func setupConnection(con_type string, driver string, dataSource string, maxIdle
if driver == "sqlite3" {
dbmap = &gorp.DbMap{Db: db, TypeConverter: mattermConverter{}, Dialect: gorp.SqliteDialect{}}
} else if driver == "mysql" {
- dbmap = &gorp.DbMap{Db: db, TypeConverter: mattermConverter{}, Dialect: gorp.MySQLDialect{Engine: "InnoDB", Encoding: "UTF8"}}
+ dbmap = &gorp.DbMap{Db: db, TypeConverter: mattermConverter{}, Dialect: gorp.MySQLDialect{Engine: "InnoDB", Encoding: "UTF8MB4"}}
} else {
l4g.Critical("Failed to create dialect specific driver")
time.Sleep(time.Second)