summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2015-09-29 14:17:16 -0700
committer=Corey Hulen <corey@hulen.com>2015-09-29 14:17:16 -0700
commit8fadea44debd00c1babd12bff9eb2dd0a5d99370 (patch)
tree029cf65137b2590308c2d745ef61d7458d3d7287 /store
parent942702ff1a6cc3763742ea9fec6ecc587d998411 (diff)
downloadchat-8fadea44debd00c1babd12bff9eb2dd0a5d99370.tar.gz
chat-8fadea44debd00c1babd12bff9eb2dd0a5d99370.tar.bz2
chat-8fadea44debd00c1babd12bff9eb2dd0a5d99370.zip
PLT-404 adding basic error checking to config file.
Diffstat (limited to 'store')
-rw-r--r--store/sql_channel_store.go4
-rw-r--r--store/sql_post_store.go4
-rw-r--r--store/sql_post_store_test.go7
-rw-r--r--store/sql_store.go22
4 files changed, 15 insertions, 22 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go
index 877246fc3..cb686090e 100644
--- a/store/sql_channel_store.go
+++ b/store/sql_channel_store.go
@@ -583,7 +583,7 @@ func (s SqlChannelStore) UpdateLastViewedAt(channelId string, userId string) Sto
var query string
- if utils.Cfg.SqlSettings.DriverName == "postgres" {
+ if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
query = `UPDATE
ChannelMembers
SET
@@ -597,7 +597,7 @@ func (s SqlChannelStore) UpdateLastViewedAt(channelId string, userId string) Sto
Channels.Id = ChannelMembers.ChannelId
AND UserId = :UserId
AND ChannelId = :ChannelId`
- } else if utils.Cfg.SqlSettings.DriverName == "mysql" {
+ } else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL {
query = `UPDATE
ChannelMembers, Channels
SET
diff --git a/store/sql_post_store.go b/store/sql_post_store.go
index 21e8e9d00..668f45fbb 100644
--- a/store/sql_post_store.go
+++ b/store/sql_post_store.go
@@ -418,7 +418,7 @@ func (s SqlPostStore) Search(teamId string, userId string, terms string, isHasht
var posts []*model.Post
- if utils.Cfg.SqlSettings.DriverName == "postgres" {
+ if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
// Parse text for wildcards
if wildcard, err := regexp.Compile("\\*($| )"); err == nil {
@@ -451,7 +451,7 @@ func (s SqlPostStore) Search(teamId string, userId string, terms string, isHasht
result.Err = model.NewAppError("SqlPostStore.Search", "We encounted an error while searching for posts", "teamId="+teamId+", err="+err.Error())
}
- } else if utils.Cfg.SqlSettings.DriverName == "mysql" {
+ } else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL {
searchQuery := fmt.Sprintf(`SELECT
*
FROM
diff --git a/store/sql_post_store_test.go b/store/sql_post_store_test.go
index bc1cb2c2c..257054033 100644
--- a/store/sql_post_store_test.go
+++ b/store/sql_post_store_test.go
@@ -530,13 +530,6 @@ func TestPostStoreSearch(t *testing.T) {
t.Fatal("returned wrong serach result")
}
- // if utils.Cfg.SqlSettings.DriverName == "mysql" {
- // r2 := (<-store.Post().Search(teamId, userId, "new york", false)).Data.(*model.PostList)
- // if len(r2.Order) >= 1 && r2.Order[0] != o2.Id {
- // t.Fatal("returned wrong serach result")
- // }
- // }
-
r3 := (<-store.Post().Search(teamId, userId, "new", false)).Data.(*model.PostList)
if len(r3.Order) != 2 && r3.Order[0] != o1.Id {
t.Fatal("returned wrong serach result")
diff --git a/store/sql_store.go b/store/sql_store.go
index 6dcf2e8cd..3ef9cfbc4 100644
--- a/store/sql_store.go
+++ b/store/sql_store.go
@@ -160,9 +160,9 @@ 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" {
+ } else if driver == model.DATABASE_DRIVER_MYSQL {
dbmap = &gorp.DbMap{Db: db, TypeConverter: mattermConverter{}, Dialect: gorp.MySQLDialect{Engine: "InnoDB", Encoding: "UTF8MB4"}}
- } else if driver == "postgres" {
+ } else if driver == model.DATABASE_DRIVER_POSTGRES {
dbmap = &gorp.DbMap{Db: db, TypeConverter: mattermConverter{}, Dialect: gorp.PostgresDialect{}}
} else {
l4g.Critical("Failed to create dialect specific driver")
@@ -183,7 +183,7 @@ func (ss SqlStore) GetCurrentSchemaVersion() string {
}
func (ss SqlStore) DoesTableExist(tableName string) bool {
- if utils.Cfg.SqlSettings.DriverName == "postgres" {
+ if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
count, err := ss.GetMaster().SelectInt(
`SELECT count(relname) FROM pg_class WHERE relname=$1`,
strings.ToLower(tableName),
@@ -197,7 +197,7 @@ func (ss SqlStore) DoesTableExist(tableName string) bool {
return count > 0
- } else if utils.Cfg.SqlSettings.DriverName == "mysql" {
+ } else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL {
count, err := ss.GetMaster().SelectInt(
`SELECT
@@ -228,7 +228,7 @@ func (ss SqlStore) DoesTableExist(tableName string) bool {
}
func (ss SqlStore) DoesColumnExist(tableName string, columnName string) bool {
- if utils.Cfg.SqlSettings.DriverName == "postgres" {
+ if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
count, err := ss.GetMaster().SelectInt(
`SELECT COUNT(0)
FROM pg_attribute
@@ -251,7 +251,7 @@ func (ss SqlStore) DoesColumnExist(tableName string, columnName string) bool {
return count > 0
- } else if utils.Cfg.SqlSettings.DriverName == "mysql" {
+ } else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL {
count, err := ss.GetMaster().SelectInt(
`SELECT
@@ -288,7 +288,7 @@ func (ss SqlStore) CreateColumnIfNotExists(tableName string, columnName string,
return false
}
- if utils.Cfg.SqlSettings.DriverName == "postgres" {
+ if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
_, err := ss.GetMaster().Exec("ALTER TABLE " + tableName + " ADD " + columnName + " " + postgresColType + " DEFAULT '" + defaultValue + "'")
if err != nil {
l4g.Critical("Failed to create column %v", err)
@@ -298,7 +298,7 @@ func (ss SqlStore) CreateColumnIfNotExists(tableName string, columnName string,
return true
- } else if utils.Cfg.SqlSettings.DriverName == "mysql" {
+ } else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL {
_, err := ss.GetMaster().Exec("ALTER TABLE " + tableName + " ADD " + columnName + " " + mySqlColType + " DEFAULT '" + defaultValue + "'")
if err != nil {
l4g.Critical("Failed to create column %v", err)
@@ -334,7 +334,7 @@ func (ss SqlStore) RemoveColumnIfExists(tableName string, columnName string) boo
// func (ss SqlStore) RenameColumnIfExists(tableName string, oldColumnName string, newColumnName string, colType string) bool {
// // XXX TODO FIXME this should be removed after 0.6.0
-// if utils.Cfg.SqlSettings.DriverName == "postgres" {
+// if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
// return false
// }
@@ -363,7 +363,7 @@ func (ss SqlStore) CreateFullTextIndexIfNotExists(indexName string, tableName st
func (ss SqlStore) createIndexIfNotExists(indexName string, tableName string, columnName string, fullText bool) {
- if utils.Cfg.SqlSettings.DriverName == "postgres" {
+ if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
_, err := ss.GetMaster().SelectStr("SELECT $1::regclass", indexName)
// It should fail if the index does not exist
if err == nil {
@@ -383,7 +383,7 @@ func (ss SqlStore) createIndexIfNotExists(indexName string, tableName string, co
time.Sleep(time.Second)
panic("Failed to create index " + err.Error())
}
- } else if utils.Cfg.SqlSettings.DriverName == "mysql" {
+ } else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL {
count, err := ss.GetMaster().SelectInt("SELECT COUNT(0) AS index_exists FROM information_schema.statistics WHERE TABLE_SCHEMA = DATABASE() and table_name = ? AND index_name = ?", tableName, indexName)
if err != nil {