summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
Diffstat (limited to 'store')
-rw-r--r--store/sql_post_store.go19
-rw-r--r--store/sql_store.go26
2 files changed, 44 insertions, 1 deletions
diff --git a/store/sql_post_store.go b/store/sql_post_store.go
index fdae20f60..3460fca92 100644
--- a/store/sql_post_store.go
+++ b/store/sql_post_store.go
@@ -9,8 +9,10 @@ import (
"strconv"
"strings"
+ l4g "code.google.com/p/log4go"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
+ "time"
)
type SqlPostStore struct {
@@ -30,7 +32,7 @@ func NewSqlPostStore(sqlStore *SqlStore) PostStore {
table.ColMap("Message").SetMaxSize(4000)
table.ColMap("Type").SetMaxSize(26)
table.ColMap("Hashtags").SetMaxSize(1000)
- table.ColMap("Props").SetMaxSize(4000)
+ table.ColMap("Props")
table.ColMap("Filenames").SetMaxSize(4000)
}
@@ -38,6 +40,21 @@ func NewSqlPostStore(sqlStore *SqlStore) PostStore {
}
func (s SqlPostStore) UpgradeSchemaIfNeeded() {
+ colType := s.GetColumnDataType("Posts", "Props")
+ if colType != "text" {
+
+ query := "ALTER TABLE Posts MODIFY COLUMN Props TEXT"
+ if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
+ query = "ALTER TABLE Posts ALTER COLUMN Props TYPE text"
+ }
+
+ _, err := s.GetMaster().Exec(query)
+ if err != nil {
+ l4g.Critical("Failed to alter column Posts.Props to TEXT: " + err.Error())
+ time.Sleep(time.Second)
+ panic("Failed to alter column Posts.Props to TEXT: " + err.Error())
+ }
+ }
}
func (s SqlPostStore) CreateIndexesIfNotExists() {
diff --git a/store/sql_store.go b/store/sql_store.go
index e5c540e06..f348db10b 100644
--- a/store/sql_store.go
+++ b/store/sql_store.go
@@ -455,6 +455,20 @@ func IsUniqueConstraintError(err string, mysql string, postgres string) bool {
return unique && field
}
+func (ss SqlStore) GetColumnDataType(tableName, columnName string) string {
+ dataType, err := ss.GetMaster().SelectStr("SELECT data_type FROM INFORMATION_SCHEMA.COLUMNS where table_name = :Tablename AND column_name = :Columnname", map[string]interface{}{
+ "Tablename": tableName,
+ "Columnname": columnName,
+ })
+ if err != nil {
+ l4g.Critical("Failed to get data type for column %s from table %s: %v", columnName, tableName, err.Error())
+ time.Sleep(time.Second)
+ panic("Failed to get get data type for column " + columnName + " from table " + tableName + ": " + err.Error())
+ }
+
+ return dataType
+}
+
func (ss SqlStore) GetMaster() *gorp.DbMap {
return ss.master
}
@@ -529,6 +543,8 @@ func (me mattermConverter) ToDb(val interface{}) (interface{}, error) {
return model.ArrayToJson(t), nil
case model.EncryptStringMap:
return encrypt([]byte(utils.Cfg.SqlSettings.AtRestEncryptKey), model.MapToJson(t))
+ case model.StringInterface:
+ return model.StringInterfaceToJson(t), nil
}
return val, nil
@@ -572,6 +588,16 @@ func (me mattermConverter) FromDb(target interface{}) (gorp.CustomScanner, bool)
return json.Unmarshal(b, target)
}
return gorp.CustomScanner{new(string), target, binder}, true
+ case *model.StringInterface:
+ binder := func(holder, target interface{}) error {
+ s, ok := holder.(*string)
+ if !ok {
+ return errors.New("FromDb: Unable to convert StringInterface to *string")
+ }
+ b := []byte(*s)
+ return json.Unmarshal(b, target)
+ }
+ return gorp.CustomScanner{new(string), target, binder}, true
}
return gorp.CustomScanner{}, false