summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--model/version.go2
-rw-r--r--store/sql_store.go51
2 files changed, 50 insertions, 3 deletions
diff --git a/model/version.go b/model/version.go
index f37447921..e3e6e14b9 100644
--- a/model/version.go
+++ b/model/version.go
@@ -11,7 +11,7 @@ import (
const (
VERSION_MAJOR = 0
- VERSION_MINOR = 7
+ VERSION_MINOR = 8
VERSION_PATCH = 0
BUILD_NUMBER = "_BUILD_NUMBER_"
BUILD_DATE = "_BUILD_DATE_"
diff --git a/store/sql_store.go b/store/sql_store.go
index 1ae722f16..2e679b81a 100644
--- a/store/sql_store.go
+++ b/store/sql_store.go
@@ -77,8 +77,10 @@ func NewSqlStore() Store {
}
// Temporary upgrade code, remove after 0.8.0 release
- if sqlStore.DoesColumnExist("Sessions", "AltId") {
- sqlStore.GetMaster().Exec("DROP TABLE IF EXISTS Sessions")
+ if sqlStore.DoesTableExist("Sessions") {
+ if sqlStore.DoesColumnExist("Sessions", "AltId") {
+ sqlStore.GetMaster().Exec("DROP TABLE IF EXISTS Sessions")
+ }
}
sqlStore.team = NewSqlTeamStore(sqlStore)
@@ -169,6 +171,51 @@ func (ss SqlStore) GetCurrentSchemaVersion() string {
return version
}
+func (ss SqlStore) DoesTableExist(tableName string) bool {
+ if utils.Cfg.SqlSettings.DriverName == "postgres" {
+ count, err := ss.GetMaster().SelectInt(
+ `SELECT count(relname) FROM pg_class WHERE relname=$1`,
+ strings.ToLower(tableName),
+ )
+
+ if err != nil {
+ l4g.Critical("Failed to check if table exists %v", err)
+ time.Sleep(time.Second)
+ panic("Failed to check if table exists " + err.Error())
+ }
+
+ return count > 0
+
+ } else if utils.Cfg.SqlSettings.DriverName == "mysql" {
+
+ count, err := ss.GetMaster().SelectInt(
+ `SELECT
+ COUNT(0) AS table_exists
+ FROM
+ information_schema.TABLES
+ WHERE
+ TABLE_SCHEMA = DATABASE()
+ AND TABLE_NAME = ?
+ `,
+ tableName,
+ )
+
+ if err != nil {
+ l4g.Critical("Failed to check if table exists %v", err)
+ time.Sleep(time.Second)
+ panic("Failed to check if table exists " + err.Error())
+ }
+
+ return count > 0
+
+ } else {
+ l4g.Critical("Failed to check if column exists because of missing driver")
+ time.Sleep(time.Second)
+ panic("Failed to check if column exists because of missing driver")
+ }
+
+}
+
func (ss SqlStore) DoesColumnExist(tableName string, columnName string) bool {
if utils.Cfg.SqlSettings.DriverName == "postgres" {
count, err := ss.GetMaster().SelectInt(