Fixing postgres issue and bumping version number

This commit is contained in:
=Corey Hulen
2015-09-16 21:16:07 -07:00
parent 4352118700
commit 51c3445e69
2 changed files with 50 additions and 3 deletions

View File

@@ -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_"

View File

@@ -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(