diff options
Diffstat (limited to 'store/sql_store.go')
-rw-r--r-- | store/sql_store.go | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/store/sql_store.go b/store/sql_store.go index 692ac2664..d4d8fdf73 100644 --- a/store/sql_store.go +++ b/store/sql_store.go @@ -30,6 +30,11 @@ import ( "github.com/mattermost/platform/utils" ) +const ( + INDEX_TYPE_FULL_TEXT = "full_text" + INDEX_TYPE_DEFAULT = "default" +) + type SqlStore struct { master *gorp.DbMap replicas []*gorp.DbMap @@ -74,7 +79,14 @@ func NewSqlStore() Store { // Check to see if it's the most current database schema version if !model.IsCurrentVersion(schemaVersion) { // If we are upgrading from the previous version then print a warning and continue - if model.IsPreviousVersion(schemaVersion) { + + // Special case + isSchemaVersion07 := false + if schemaVersion == "0.7.1" || schemaVersion == "0.7.0" { + isSchemaVersion07 = true + } + + if model.IsPreviousVersion(schemaVersion) || isSchemaVersion07 { l4g.Warn("The database schema version of " + schemaVersion + " appears to be out of date") l4g.Warn("Attempting to upgrade the database schema version to " + model.CurrentVersion) } else { @@ -86,6 +98,13 @@ func NewSqlStore() Store { } } + // REMOVE in 1.2 + if sqlStore.DoesTableExist("Sessions") { + if sqlStore.DoesColumnExist("Sessions", "AltId") { + sqlStore.GetMaster().Exec("DROP TABLE IF EXISTS Sessions") + } + } + sqlStore.team = NewSqlTeamStore(sqlStore) sqlStore.channel = NewSqlChannelStore(sqlStore) sqlStore.post = NewSqlPostStore(sqlStore) @@ -363,14 +382,14 @@ func (ss SqlStore) RemoveColumnIfExists(tableName string, columnName string) boo // } func (ss SqlStore) CreateIndexIfNotExists(indexName string, tableName string, columnName string) { - ss.createIndexIfNotExists(indexName, tableName, columnName, false) + ss.createIndexIfNotExists(indexName, tableName, columnName, INDEX_TYPE_DEFAULT) } func (ss SqlStore) CreateFullTextIndexIfNotExists(indexName string, tableName string, columnName string) { - ss.createIndexIfNotExists(indexName, tableName, columnName, true) + ss.createIndexIfNotExists(indexName, tableName, columnName, INDEX_TYPE_FULL_TEXT) } -func (ss SqlStore) createIndexIfNotExists(indexName string, tableName string, columnName string, fullText bool) { +func (ss SqlStore) createIndexIfNotExists(indexName string, tableName string, columnName string, indexType string) { if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES { _, err := ss.GetMaster().SelectStr("SELECT $1::regclass", indexName) @@ -380,7 +399,7 @@ func (ss SqlStore) createIndexIfNotExists(indexName string, tableName string, co } query := "" - if fullText { + if indexType == INDEX_TYPE_FULL_TEXT { query = "CREATE INDEX " + indexName + " ON " + tableName + " USING gin(to_tsvector('english', " + columnName + "))" } else { query = "CREATE INDEX " + indexName + " ON " + tableName + " (" + columnName + ")" @@ -406,7 +425,7 @@ func (ss SqlStore) createIndexIfNotExists(indexName string, tableName string, co } fullTextIndex := "" - if fullText { + if indexType == INDEX_TYPE_FULL_TEXT { fullTextIndex = " FULLTEXT " } |