From cef7a1aae4205ebf4fbd8958f1f870ff69759edf Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 16 Sep 2015 17:37:11 -0700 Subject: PLT-92 Adding server side versioning to the binary --- .gitignore | 1 + Makefile | 7 ++++ api/context.go | 2 +- mattermost.go | 17 ++++++++- model/utils.go | 7 +--- model/version.go | 78 ++++++++++++++++++++++++++++++++++++++ model/version_test.go | 72 +++++++++++++++++++++++++++++++++++ store/sql_post_store.go | 4 +- store/sql_post_store_test.go | 8 ++-- store/sql_store.go | 7 ++++ store/sql_user_store.go | 4 +- utils/config.go | 8 +++- web/react/stores/browser_store.jsx | 7 +--- 13 files changed, 199 insertions(+), 23 deletions(-) create mode 100644 model/version.go create mode 100644 model/version_test.go diff --git a/.gitignore b/.gitignore index 79761adac..2c6563bcf 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ dist npm-debug.log bundle*.js +model/version.go # Compiled Object files, Static and Dynamic libs (Shared Objects) diff --git a/Makefile b/Makefile index cd82c27a3..a6541b748 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ GOPATH ?= $(GOPATH:) GOFLAGS ?= $(GOFLAGS:) BUILD_NUMBER ?= $(BUILD_NUMBER:) +BUILD_DATE=`date +'%y.%m.%d %H:%M:%S'` GO=$(GOPATH)/bin/godep go ESLINT=node_modules/eslint/bin/eslint.js @@ -40,6 +41,9 @@ travis: @echo Checking for style guide compliance cd web/react && $(ESLINT) --quiet components/* dispatcher/* pages/* stores/* utils/* + @sed -i'.bak' 's|_BUILD_NUMBER_|$(BUILD_NUMBER)|g' ./model/version.go + @sed -i'.bak' 's|_BUILD_DATE_|$(BUILD_DATE)|g' ./model/version.go + @$(GO) build $(GOFLAGS) ./... @$(GO) install $(GOFLAGS) ./... @@ -204,6 +208,9 @@ cleandb: fi dist: install + @sed -i'.bak' 's|_BUILD_NUMBER_|$(BUILD_NUMBER)|g' ./model/version.go + @sed -i'.bak' 's|_BUILD_DATE_|$(BUILD_DATE)|g' ./model/version.go + @$(GO) build $(GOFLAGS) -i ./... @$(GO) install $(GOFLAGS) ./... diff --git a/api/context.go b/api/context.go index b1b4d2d10..b896ca7b1 100644 --- a/api/context.go +++ b/api/context.go @@ -125,7 +125,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { c.setSiteURL(protocol + "://" + r.Host) w.Header().Set(model.HEADER_REQUEST_ID, c.RequestId) - w.Header().Set(model.HEADER_VERSION_ID, utils.Cfg.ServiceSettings.Version+fmt.Sprintf(".%v", utils.CfgLastModified)) + w.Header().Set(model.HEADER_VERSION_ID, fmt.Sprintf("%v.%v", model.GetFullVersion(), utils.CfgLastModified)) // Instruct the browser not to display us in an iframe for anti-clickjacking if !h.isApi { diff --git a/mattermost.go b/mattermost.go index 0bdb90424..75e405e88 100644 --- a/mattermost.go +++ b/mattermost.go @@ -23,6 +23,7 @@ import ( var flagCmdCreateTeam bool var flagCmdCreateUser bool var flagCmdAssignRole bool +var flagCmdVersion bool var flagCmdResetPassword bool var flagConfigFile string var flagEmail string @@ -83,14 +84,16 @@ func parseCmds() { flag.BoolVar(&flagCmdCreateTeam, "create_team", false, "") flag.BoolVar(&flagCmdCreateUser, "create_user", false, "") flag.BoolVar(&flagCmdAssignRole, "assign_role", false, "") + flag.BoolVar(&flagCmdVersion, "version", false, "") flag.BoolVar(&flagCmdResetPassword, "reset_password", false, "") flag.Parse() - flagRunCmds = flagCmdCreateTeam || flagCmdCreateUser || flagCmdAssignRole || flagCmdResetPassword + flagRunCmds = flagCmdCreateTeam || flagCmdCreateUser || flagCmdAssignRole || flagCmdResetPassword || flagCmdVersion } func runCmds() { + cmdVersion() cmdCreateTeam() cmdCreateUser() cmdAssignRole() @@ -184,6 +187,16 @@ func cmdCreateUser() { } } +func cmdVersion() { + if flagCmdVersion { + fmt.Fprintln(os.Stderr, "Version: "+model.GetFullVersion()) + fmt.Fprintln(os.Stderr, "Build Number: "+model.BUILD_NUMBER) + fmt.Fprintln(os.Stderr, "Build Date: "+model.BUILD_DATE) + + os.Exit(0) + } +} + func cmdAssignRole() { if flagCmdAssignRole { if len(flagTeamName) == 0 { @@ -298,6 +311,8 @@ Usage: platform [options] + -version Display the current version + -config="config.json" Path to the config file -email="user@example.com" Email address used in other commands diff --git a/model/utils.go b/model/utils.go index 04b92947b..ee94cafc3 100644 --- a/model/utils.go +++ b/model/utils.go @@ -16,11 +16,6 @@ import ( "time" ) -const ( - // Also change web/react/stores/browser_store.jsx BROWSER_STORE_VERSION - ETAG_ROOT_VERSION = "12" -) - type StringMap map[string]string type StringArray []string type EncryptStringMap map[string]string @@ -235,7 +230,7 @@ func IsValidAlphaNum(s string, allowUnderscores bool) bool { func Etag(parts ...interface{}) string { - etag := ETAG_ROOT_VERSION + etag := GetFullVersion() for _, part := range parts { etag += fmt.Sprintf(".%v", part) diff --git a/model/version.go b/model/version.go new file mode 100644 index 000000000..f37447921 --- /dev/null +++ b/model/version.go @@ -0,0 +1,78 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "fmt" + "strconv" + "strings" +) + +const ( + VERSION_MAJOR = 0 + VERSION_MINOR = 7 + VERSION_PATCH = 0 + BUILD_NUMBER = "_BUILD_NUMBER_" + BUILD_DATE = "_BUILD_DATE_" +) + +func GetFullVersion() string { + return fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH) +} + +func SplitVersion(version string) (int64, int64, int64) { + parts := strings.Split(version, ".") + + major := int64(0) + minor := int64(0) + patch := int64(0) + + if len(parts) > 0 { + major, _ = strconv.ParseInt(parts[0], 10, 64) + } + + if len(parts) > 1 { + minor, _ = strconv.ParseInt(parts[1], 10, 64) + } + + if len(parts) > 2 { + patch, _ = strconv.ParseInt(parts[2], 10, 64) + } + + return major, minor, patch +} + +func GetPreviousVersion(version string) (int64, int64) { + major, minor, _ := SplitVersion(version) + + if minor == 0 { + major = major - 1 + minor = 9 + } else { + minor = minor - 1 + } + + return major, minor +} + +func IsCurrentVersion(versionToCheck string) bool { + toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck) + + if toCheckMajor == VERSION_MAJOR && toCheckMinor == VERSION_MINOR { + return true + } else { + return false + } +} + +func IsLastVersion(versionToCheck string) bool { + toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck) + prevMajor, prevMinor := GetPreviousVersion(GetFullVersion()) + + if toCheckMajor == prevMajor && toCheckMinor == prevMinor { + return true + } else { + return false + } +} diff --git a/model/version_test.go b/model/version_test.go new file mode 100644 index 000000000..fb52d96a5 --- /dev/null +++ b/model/version_test.go @@ -0,0 +1,72 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "fmt" + "testing" +) + +func TestVersion(t *testing.T) { + GetFullVersion() + + major1, minor1, patch1 := SplitVersion("junk") + if major1 != 0 || minor1 != 0 || patch1 != 0 { + t.Fatal() + } + + major2, minor2, patch2 := SplitVersion("1.2.3") + if major2 != 1 || minor2 != 2 || patch2 != 3 { + t.Fatal() + } + + major3, minor3, patch3 := SplitVersion("1.2") + if major3 != 1 || minor3 != 2 || patch3 != 0 { + t.Fatal() + } + + major4, minor4, patch4 := SplitVersion("1") + if major4 != 1 || minor4 != 0 || patch4 != 0 { + t.Fatal() + } + + major5, minor5, patch5 := SplitVersion("1.2.3.junkgoeswhere") + if major5 != 1 || minor5 != 2 || patch5 != 3 { + t.Fatal() + } + + if IsLastVersion(GetFullVersion()) { + t.Fatal() + } + + if !IsLastVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR-1, VERSION_PATCH)) { + t.Fatal() + } + + // pacth should not affect current version check + if !IsLastVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR-1, VERSION_PATCH+1)) { + t.Fatal() + } + + if IsLastVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR+1, VERSION_PATCH)) { + t.Fatal() + } + + if !IsCurrentVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH)) { + t.Fatal() + } + + // pacth should not affect current version check + if !IsCurrentVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH+1)) { + t.Fatal() + } + + if IsCurrentVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR+1, VERSION_PATCH)) { + t.Fatal() + } + + if IsCurrentVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR+1, VERSION_MINOR, VERSION_PATCH)) { + t.Fatal() + } +} diff --git a/store/sql_post_store.go b/store/sql_post_store.go index 20de23eb7..50e1c3c33 100644 --- a/store/sql_post_store.go +++ b/store/sql_post_store.go @@ -196,9 +196,9 @@ func (s SqlPostStore) GetEtag(channelId string) StoreChannel { var et etagPosts err := s.GetReplica().SelectOne(&et, "SELECT Id, UpdateAt FROM Posts WHERE ChannelId = :ChannelId ORDER BY UpdateAt DESC LIMIT 1", map[string]interface{}{"ChannelId": channelId}) if err != nil { - result.Data = fmt.Sprintf("%v.0.%v", model.ETAG_ROOT_VERSION, model.GetMillis()) + result.Data = fmt.Sprintf("%v.0.%v", model.GetFullVersion(), model.GetMillis()) } else { - result.Data = fmt.Sprintf("%v.%v.%v", model.ETAG_ROOT_VERSION, et.Id, et.UpdateAt) + result.Data = fmt.Sprintf("%v.%v.%v", model.GetFullVersion(), et.Id, et.UpdateAt) } storeChannel <- result diff --git a/store/sql_post_store_test.go b/store/sql_post_store_test.go index d48dea51c..bec2ceb60 100644 --- a/store/sql_post_store_test.go +++ b/store/sql_post_store_test.go @@ -37,14 +37,14 @@ func TestPostStoreGet(t *testing.T) { o1.Message = "a" + model.NewId() + "b" etag1 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string) - if strings.Index(etag1, model.ETAG_ROOT_VERSION+".0.") != 0 { + if strings.Index(etag1, model.GetFullVersion()+".0.") != 0 { t.Fatal("Invalid Etag") } o1 = (<-store.Post().Save(o1)).Data.(*model.Post) etag2 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string) - if strings.Index(etag2, model.ETAG_ROOT_VERSION+"."+o1.Id) != 0 { + if strings.Index(etag2, model.GetFullVersion()+"."+o1.Id) != 0 { t.Fatal("Invalid Etag") } @@ -136,7 +136,7 @@ func TestPostStoreDelete(t *testing.T) { o1.Message = "a" + model.NewId() + "b" etag1 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string) - if strings.Index(etag1, model.ETAG_ROOT_VERSION+".0.") != 0 { + if strings.Index(etag1, model.GetFullVersion()+".0.") != 0 { t.Fatal("Invalid Etag") } @@ -160,7 +160,7 @@ func TestPostStoreDelete(t *testing.T) { } etag2 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string) - if strings.Index(etag2, model.ETAG_ROOT_VERSION+"."+o1.Id) != 0 { + if strings.Index(etag2, model.GetFullVersion()+"."+o1.Id) != 0 { t.Fatal("Invalid Etag") } } diff --git a/store/sql_store.go b/store/sql_store.go index c0b3c2021..6ba73a0e5 100644 --- a/store/sql_store.go +++ b/store/sql_store.go @@ -56,6 +56,8 @@ func NewSqlStore() Store { utils.Cfg.SqlSettings.Trace) } + //version := sqlStore.GetCurrentSchemaVersion() + // Temporary upgrade code, remove after 0.8.0 release if sqlStore.DoesColumnExist("Sessions", "AltId") { sqlStore.GetMaster().Exec("DROP TABLE IF EXISTS Sessions") @@ -131,6 +133,11 @@ func setupConnection(con_type string, driver string, dataSource string, maxIdle return dbmap } +func (ss SqlStore) GetCurrentSchemaVersion() string { + version, _ := ss.GetMaster().SelectStr("SELECT PropVal FROM MattermostSystem WHERE PropName='SchemaVersion'") + return version +} + func (ss SqlStore) DoesColumnExist(tableName string, columnName string) bool { if utils.Cfg.SqlSettings.DriverName == "postgres" { count, err := ss.GetMaster().SelectInt( diff --git a/store/sql_user_store.go b/store/sql_user_store.go index 52d670d56..90e1343a8 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -325,9 +325,9 @@ func (s SqlUserStore) GetEtagForProfiles(teamId string) StoreChannel { updateAt, err := s.GetReplica().SelectInt("SELECT UpdateAt FROM Users WHERE TeamId = :TeamId ORDER BY UpdateAt DESC LIMIT 1", map[string]interface{}{"TeamId": teamId}) if err != nil { - result.Data = fmt.Sprintf("%v.%v", model.ETAG_ROOT_VERSION, model.GetMillis()) + result.Data = fmt.Sprintf("%v.%v", model.GetFullVersion(), model.GetMillis()) } else { - result.Data = fmt.Sprintf("%v.%v", model.ETAG_ROOT_VERSION, updateAt) + result.Data = fmt.Sprintf("%v.%v", model.GetFullVersion(), updateAt) } storeChannel <- result diff --git a/utils/config.go b/utils/config.go index 0eb8329d1..eed627448 100644 --- a/utils/config.go +++ b/utils/config.go @@ -11,6 +11,8 @@ import ( "strconv" l4g "code.google.com/p/log4go" + + "github.com/mattermost/platform/model" ) const ( @@ -26,7 +28,6 @@ type ServiceSettings struct { AllowTesting bool UseSSL bool Port string - Version string InviteSalt string PublicLinkSalt string ResetSalt string @@ -275,7 +276,10 @@ func getSanitizeOptions(c *Config) map[string]bool { func getClientProperties(c *Config) map[string]string { props := make(map[string]string) - props["Version"] = c.ServiceSettings.Version + props["Version"] = model.GetFullVersion() + props["BuildNumber"] = model.BUILD_NUMBER + props["BuildDate"] = model.BUILD_DATE + props["SiteName"] = c.ServiceSettings.SiteName props["ByPassEmail"] = strconv.FormatBool(c.EmailSettings.ByPassEmail) props["FeedbackEmail"] = c.EmailSettings.FeedbackEmail diff --git a/web/react/stores/browser_store.jsx b/web/react/stores/browser_store.jsx index e1ca52746..d2dedb271 100644 --- a/web/react/stores/browser_store.jsx +++ b/web/react/stores/browser_store.jsx @@ -9,9 +9,6 @@ function getPrefix() { return UserStore.getCurrentId() + '_'; } -// Also change model/utils.go ETAG_ROOT_VERSION -var BROWSER_STORE_VERSION = '.5'; - class BrowserStoreClass { constructor() { this.getItem = this.getItem.bind(this); @@ -25,9 +22,9 @@ class BrowserStoreClass { this.isLocalStorageSupported = this.isLocalStorageSupported.bind(this); var currentVersion = localStorage.getItem('local_storage_version'); - if (currentVersion !== BROWSER_STORE_VERSION) { + if (currentVersion !== global.window.config.Version) { this.clear(); - localStorage.setItem('local_storage_version', BROWSER_STORE_VERSION); + localStorage.setItem('local_storage_version', global.window.config.Version); } } -- cgit v1.2.3-1-g7c22 From e3bf54f1619635f9e1e90bbabb611e9fa7a4bae7 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 16 Sep 2015 17:45:00 -0700 Subject: fixing build --- .gitignore | 1 + Makefile | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2c6563bcf..e27362fdc 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ npm-debug.log bundle*.js model/version.go +model/version.go.bak # Compiled Object files, Static and Dynamic libs (Shared Objects) diff --git a/Makefile b/Makefile index a6541b748..cf8410ef1 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ GOPATH ?= $(GOPATH:) GOFLAGS ?= $(GOFLAGS:) BUILD_NUMBER ?= $(BUILD_NUMBER:) -BUILD_DATE=`date +'%y.%m.%d %H:%M:%S'` +BUILD_DATE = $(shell date -u) GO=$(GOPATH)/bin/godep go ESLINT=node_modules/eslint/bin/eslint.js -- cgit v1.2.3-1-g7c22 From 1e7f7852ad09d97c8d33012192bd1ff418881b8f Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 16 Sep 2015 17:49:48 -0700 Subject: Outputing version to logs on server start --- mattermost.go | 1 + 1 file changed, 1 insertion(+) diff --git a/mattermost.go b/mattermost.go index 75e405e88..b2b5f584b 100644 --- a/mattermost.go +++ b/mattermost.go @@ -43,6 +43,7 @@ func main() { } pwd, _ := os.Getwd() + l4g.Info("Current version is %v (%v/%v)", model.GetFullVersion(), model.BUILD_NUMBER, model.BUILD_DATE) l4g.Info("Current working directory is %v", pwd) l4g.Info("Loaded config file from %v", utils.FindConfigFile(flagConfigFile)) -- cgit v1.2.3-1-g7c22 From abda39b6523f2563d4663036f13ad1c24dac161e Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 16 Sep 2015 19:59:57 -0700 Subject: Adding database schema version --- model/system.go | 34 ++++++++++++++++ model/system_test.go | 19 +++++++++ store/sql_channel_store.go | 1 - store/sql_store.go | 39 +++++++++++++++++- store/sql_system_store.go | 92 ++++++++++++++++++++++++++++++++++++++++++ store/sql_system_store_test.go | 33 +++++++++++++++ store/store.go | 7 ++++ 7 files changed, 222 insertions(+), 3 deletions(-) create mode 100644 model/system.go create mode 100644 model/system_test.go create mode 100644 store/sql_system_store.go create mode 100644 store/sql_system_store_test.go diff --git a/model/system.go b/model/system.go new file mode 100644 index 000000000..c79391cca --- /dev/null +++ b/model/system.go @@ -0,0 +1,34 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "encoding/json" + "io" +) + +type System struct { + Name string `json:"name"` + Value string `json:"value"` +} + +func (o *System) ToJson() string { + b, err := json.Marshal(o) + if err != nil { + return "" + } else { + return string(b) + } +} + +func SystemFromJson(data io.Reader) *System { + decoder := json.NewDecoder(data) + var o System + err := decoder.Decode(&o) + if err == nil { + return &o + } else { + return nil + } +} diff --git a/model/system_test.go b/model/system_test.go new file mode 100644 index 000000000..14ba0db2e --- /dev/null +++ b/model/system_test.go @@ -0,0 +1,19 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "strings" + "testing" +) + +func TestSystemJson(t *testing.T) { + system := System{Name: "test", Value: NewId()} + json := system.ToJson() + result := SystemFromJson(strings.NewReader(json)) + + if result.Name != "test" { + t.Fatal("Ids do not match") + } +} diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go index b58166fd6..bc887df87 100644 --- a/store/sql_channel_store.go +++ b/store/sql_channel_store.go @@ -37,7 +37,6 @@ func NewSqlChannelStore(sqlStore *SqlStore) ChannelStore { } func (s SqlChannelStore) UpgradeSchemaIfNeeded() { - s.CreateColumnIfNotExists("Channels", "CreatorId", "varchar(26)", "character varying(26)", "") } func (s SqlChannelStore) CreateIndexesIfNotExists() { diff --git a/store/sql_store.go b/store/sql_store.go index 6ba73a0e5..1ae722f16 100644 --- a/store/sql_store.go +++ b/store/sql_store.go @@ -39,6 +39,7 @@ type SqlStore struct { audit AuditStore session SessionStore oauth OAuthStore + system SystemStore } func NewSqlStore() Store { @@ -56,7 +57,24 @@ func NewSqlStore() Store { utils.Cfg.SqlSettings.Trace) } - //version := sqlStore.GetCurrentSchemaVersion() + schemaVersion := sqlStore.GetCurrentSchemaVersion() + + // If the version is already set then we are potentially in an 'upgrade needed' state + if schemaVersion != "" { + // 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.IsLastVersion(schemaVersion) { + 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.GetFullVersion()) + } else { + // If this is an 'upgrade needed' state but the user is attempting to skip a version then halt the world + l4g.Critical("The database schema version of " + schemaVersion + " cannot be upgraded. You must not skip a version.") + time.Sleep(time.Second) + panic("The database schema version of " + schemaVersion + " cannot be upgraded. You must not skip a version.") + } + } + } // Temporary upgrade code, remove after 0.8.0 release if sqlStore.DoesColumnExist("Sessions", "AltId") { @@ -70,6 +88,7 @@ func NewSqlStore() Store { sqlStore.audit = NewSqlAuditStore(sqlStore) sqlStore.session = NewSqlSessionStore(sqlStore) sqlStore.oauth = NewSqlOAuthStore(sqlStore) + sqlStore.system = NewSqlSystemStore(sqlStore) sqlStore.master.CreateTablesIfNotExists() @@ -80,6 +99,7 @@ func NewSqlStore() Store { sqlStore.audit.(*SqlAuditStore).UpgradeSchemaIfNeeded() sqlStore.session.(*SqlSessionStore).UpgradeSchemaIfNeeded() sqlStore.oauth.(*SqlOAuthStore).UpgradeSchemaIfNeeded() + sqlStore.system.(*SqlSystemStore).UpgradeSchemaIfNeeded() sqlStore.team.(*SqlTeamStore).CreateIndexesIfNotExists() sqlStore.channel.(*SqlChannelStore).CreateIndexesIfNotExists() @@ -88,6 +108,17 @@ func NewSqlStore() Store { sqlStore.audit.(*SqlAuditStore).CreateIndexesIfNotExists() sqlStore.session.(*SqlSessionStore).CreateIndexesIfNotExists() sqlStore.oauth.(*SqlOAuthStore).CreateIndexesIfNotExists() + sqlStore.system.(*SqlSystemStore).CreateIndexesIfNotExists() + + if model.IsLastVersion(schemaVersion) { + sqlStore.system.Update(&model.System{Name: "Version", Value: model.GetFullVersion()}) + l4g.Warn("The database schema has been upgraded to version " + model.GetFullVersion()) + } + + if schemaVersion == "" { + sqlStore.system.Save(&model.System{Name: "Version", Value: model.GetFullVersion()}) + l4g.Info("The database schema has been set to version " + model.GetFullVersion()) + } return sqlStore } @@ -134,7 +165,7 @@ func setupConnection(con_type string, driver string, dataSource string, maxIdle } func (ss SqlStore) GetCurrentSchemaVersion() string { - version, _ := ss.GetMaster().SelectStr("SELECT PropVal FROM MattermostSystem WHERE PropName='SchemaVersion'") + version, _ := ss.GetMaster().SelectStr("SELECT Value FROM Systems WHERE Name='Version'") return version } @@ -383,6 +414,10 @@ func (ss SqlStore) OAuth() OAuthStore { return ss.oauth } +func (ss SqlStore) System() SystemStore { + return ss.system +} + type mattermConverter struct{} func (me mattermConverter) ToDb(val interface{}) (interface{}, error) { diff --git a/store/sql_system_store.go b/store/sql_system_store.go new file mode 100644 index 000000000..ca22de2a6 --- /dev/null +++ b/store/sql_system_store.go @@ -0,0 +1,92 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +package store + +import ( + "github.com/mattermost/platform/model" +) + +type SqlSystemStore struct { + *SqlStore +} + +func NewSqlSystemStore(sqlStore *SqlStore) SystemStore { + s := &SqlSystemStore{sqlStore} + + for _, db := range sqlStore.GetAllConns() { + table := db.AddTableWithName(model.System{}, "Systems").SetKeys(false, "Name") + table.ColMap("Name").SetMaxSize(64) + table.ColMap("Value").SetMaxSize(1024) + } + + return s +} + +func (s SqlSystemStore) UpgradeSchemaIfNeeded() { +} + +func (s SqlSystemStore) CreateIndexesIfNotExists() { +} + +func (s SqlSystemStore) Save(system *model.System) StoreChannel { + + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + if err := s.GetMaster().Insert(system); err != nil { + result.Err = model.NewAppError("SqlSystemStore.Save", "We encounted an error saving the system property", "") + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} + +func (s SqlSystemStore) Update(system *model.System) StoreChannel { + + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + if _, err := s.GetMaster().Update(system); err != nil { + result.Err = model.NewAppError("SqlSystemStore.Save", "We encounted an error updating the system property", "") + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} + +func (s SqlSystemStore) Get() StoreChannel { + + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + var systems []model.System + props := make(model.StringMap) + if _, err := s.GetReplica().Select(&systems, "SELECT * FROM Systems"); err != nil { + result.Err = model.NewAppError("SqlSystemStore.Get", "We encounted an error finding the system properties", "") + } else { + for _, prop := range systems { + props[prop.Name] = prop.Value + } + + result.Data = props + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} diff --git a/store/sql_system_store_test.go b/store/sql_system_store_test.go new file mode 100644 index 000000000..0f03b8f0e --- /dev/null +++ b/store/sql_system_store_test.go @@ -0,0 +1,33 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +package store + +import ( + "github.com/mattermost/platform/model" + "testing" +) + +func TestSqlSystemStore(t *testing.T) { + Setup() + + system := &model.System{Name: model.NewId(), Value: "value"} + Must(store.System().Save(system)) + + result := <-store.System().Get() + systems := result.Data.(model.StringMap) + + if systems[system.Name] != system.Value { + t.Fatal() + } + + system.Value = "value2" + Must(store.System().Update(system)) + + result2 := <-store.System().Get() + systems2 := result2.Data.(model.StringMap) + + if systems2[system.Name] != system.Value { + t.Fatal() + } +} diff --git a/store/store.go b/store/store.go index 0218bc757..1344c4ebe 100644 --- a/store/store.go +++ b/store/store.go @@ -35,6 +35,7 @@ type Store interface { Audit() AuditStore Session() SessionStore OAuth() OAuthStore + System() SystemStore Close() } @@ -130,3 +131,9 @@ type OAuthStore interface { GetAccessDataByAuthCode(authCode string) StoreChannel RemoveAccessData(token string) StoreChannel } + +type SystemStore interface { + Save(system *model.System) StoreChannel + Update(system *model.System) StoreChannel + Get() StoreChannel +} -- cgit v1.2.3-1-g7c22 From 435211870096f6d31378c1b31c3d0818a7a4e710 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 16 Sep 2015 20:16:42 -0700 Subject: Adding version to UI --- config/config.json | 1 - web/react/components/user_settings_developer.jsx | 13 +++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/config/config.json b/config/config.json index 4c4fbb255..f0b859fad 100644 --- a/config/config.json +++ b/config/config.json @@ -13,7 +13,6 @@ "AllowTesting" : false, "UseSSL": false, "Port": "8065", - "Version": "developer", "Shards": { }, "InviteSalt": "gxHVDcKUyP2y1eiyW8S8na1UYQAfq6J6", diff --git a/web/react/components/user_settings_developer.jsx b/web/react/components/user_settings_developer.jsx index 1b04149dc..3e75e7ad8 100644 --- a/web/react/components/user_settings_developer.jsx +++ b/web/react/components/user_settings_developer.jsx @@ -77,6 +77,19 @@ export default class DeveloperTab extends React.Component {

{'Developer Settings'}

{appSection} +
+
    +
  • {'Version'}
  • +
  • + { + global.window.config.Version + ' (' + + global.window.config.BuildNumber + '/' + + global.window.config.BuildDate + ')' + } +
  • +
-- cgit v1.2.3-1-g7c22 From 51c3445e694e68fdecd809f17fbaa64751e5931c Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 16 Sep 2015 21:16:07 -0700 Subject: Fixing postgres issue and bumping version number --- model/version.go | 2 +- store/sql_store.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 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( -- cgit v1.2.3-1-g7c22 From af4deb2369ee6251d7f49db1d67808b773dd9db7 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Thu, 17 Sep 2015 13:01:40 -0700 Subject: Making changes to versioning --- .gitignore | 1 - Makefile | 3 ++ api/context.go | 2 +- mattermost.go | 9 ++-- model/utils.go | 2 +- model/version.go | 56 ++++++++++++++---------- model/version_test.go | 36 ++++++++------- store/sql_post_store.go | 4 +- store/sql_post_store_test.go | 8 ++-- store/sql_store.go | 14 +++--- store/sql_user_store.go | 4 +- utils/config.go | 7 +-- web/react/components/user_settings_developer.jsx | 9 ++-- 13 files changed, 86 insertions(+), 69 deletions(-) diff --git a/.gitignore b/.gitignore index e27362fdc..ebd5e4342 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,6 @@ bundle*.js model/version.go model/version.go.bak - # Compiled Object files, Static and Dynamic libs (Shared Objects) *.o *.a diff --git a/Makefile b/Makefile index 1e3ffa41c..eb9f69e49 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ GOPATH ?= $(GOPATH:) GOFLAGS ?= $(GOFLAGS:) BUILD_NUMBER ?= $(BUILD_NUMBER:) BUILD_DATE = $(shell date -u) +BUILD_HASH = $(shell git rev-parse HEAD) GO=$(GOPATH)/bin/godep go ESLINT=node_modules/eslint/bin/eslint.js @@ -52,6 +53,7 @@ travis: @sed -i'.bak' 's|_BUILD_NUMBER_|$(BUILD_NUMBER)|g' ./model/version.go @sed -i'.bak' 's|_BUILD_DATE_|$(BUILD_DATE)|g' ./model/version.go + @sed -i'.bak' 's|_BUILD_HASH_|$(BUILD_HASH)|g' ./model/version.go @$(GO) build $(GOFLAGS) ./... @$(GO) install $(GOFLAGS) ./... @@ -228,6 +230,7 @@ dist: install @sed -i'.bak' 's|_BUILD_NUMBER_|$(BUILD_NUMBER)|g' ./model/version.go @sed -i'.bak' 's|_BUILD_DATE_|$(BUILD_DATE)|g' ./model/version.go + @sed -i'.bak' 's|_BUILD_HASH_|$(BUILD_HASH)|g' ./model/version.go @$(GO) build $(GOFLAGS) -i ./... @$(GO) install $(GOFLAGS) ./... diff --git a/api/context.go b/api/context.go index f7dbeedee..02716bb33 100644 --- a/api/context.go +++ b/api/context.go @@ -125,7 +125,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { c.setSiteURL(protocol + "://" + r.Host) w.Header().Set(model.HEADER_REQUEST_ID, c.RequestId) - w.Header().Set(model.HEADER_VERSION_ID, fmt.Sprintf("%v.%v", model.GetFullVersion(), utils.CfgLastModified)) + w.Header().Set(model.HEADER_VERSION_ID, fmt.Sprintf("%v.%v", model.CurrentVersion, utils.CfgLastModified)) // Instruct the browser not to display us in an iframe for anti-clickjacking if !h.isApi { diff --git a/mattermost.go b/mattermost.go index b2b5f584b..f54bcf15f 100644 --- a/mattermost.go +++ b/mattermost.go @@ -43,7 +43,7 @@ func main() { } pwd, _ := os.Getwd() - l4g.Info("Current version is %v (%v/%v)", model.GetFullVersion(), model.BUILD_NUMBER, model.BUILD_DATE) + l4g.Info("Current version is %v (%v/%v/%v)", model.CurrentVersion, model.BuildNumber, model.BuildDate, model.BuildHash) l4g.Info("Current working directory is %v", pwd) l4g.Info("Loaded config file from %v", utils.FindConfigFile(flagConfigFile)) @@ -190,9 +190,10 @@ func cmdCreateUser() { func cmdVersion() { if flagCmdVersion { - fmt.Fprintln(os.Stderr, "Version: "+model.GetFullVersion()) - fmt.Fprintln(os.Stderr, "Build Number: "+model.BUILD_NUMBER) - fmt.Fprintln(os.Stderr, "Build Date: "+model.BUILD_DATE) + fmt.Fprintln(os.Stderr, "Version: "+model.CurrentVersion) + fmt.Fprintln(os.Stderr, "Build Number: "+model.BuildNumber) + fmt.Fprintln(os.Stderr, "Build Date: "+model.BuildDate) + fmt.Fprintln(os.Stderr, "Build Hash: "+model.BuildHash) os.Exit(0) } diff --git a/model/utils.go b/model/utils.go index ee94cafc3..e19cceba5 100644 --- a/model/utils.go +++ b/model/utils.go @@ -230,7 +230,7 @@ func IsValidAlphaNum(s string, allowUnderscores bool) bool { func Etag(parts ...interface{}) string { - etag := GetFullVersion() + etag := CurrentVersion for _, part := range parts { etag += fmt.Sprintf(".%v", part) diff --git a/model/version.go b/model/version.go index e3e6e14b9..8b5258ec1 100644 --- a/model/version.go +++ b/model/version.go @@ -4,23 +4,26 @@ package model import ( - "fmt" "strconv" "strings" ) -const ( - VERSION_MAJOR = 0 - VERSION_MINOR = 8 - VERSION_PATCH = 0 - BUILD_NUMBER = "_BUILD_NUMBER_" - BUILD_DATE = "_BUILD_DATE_" -) - -func GetFullVersion() string { - return fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH) +// This is a list of all the current viersions including any patches. +// It should be maitained in chronological order with most current +// release at the front of the list. +var versions = []string{ + "0.8.0", + "0.7.1", + "0.7.0", + "0.6.0", + "0.5.0", } +var CurrentVersion string = versions[0] +var BuildNumber = "developer" +var BuildDate = "unknown" +var BuildHash = "unknown" + func SplitVersion(version string) (int64, int64, int64) { parts := strings.Split(version, ".") @@ -43,32 +46,41 @@ func SplitVersion(version string) (int64, int64, int64) { return major, minor, patch } -func GetPreviousVersion(version string) (int64, int64) { - major, minor, _ := SplitVersion(version) +func GetPreviousVersion(currentVersion string) (int64, int64) { + currentIndex := -1 + currentMajor, currentMinor, _ := SplitVersion(currentVersion) - if minor == 0 { - major = major - 1 - minor = 9 - } else { - minor = minor - 1 + for index, version := range versions { + major, minor, _ := SplitVersion(version) + + if currentMajor == major && currentMinor == minor { + currentIndex = index + } + + if currentIndex >= 0 { + if currentMajor != major || currentMinor != minor { + return major, minor + } + } } - return major, minor + return 0, 0 } func IsCurrentVersion(versionToCheck string) bool { + currentMajor, currentMinor, _ := SplitVersion(CurrentVersion) toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck) - if toCheckMajor == VERSION_MAJOR && toCheckMinor == VERSION_MINOR { + if toCheckMajor == currentMajor && toCheckMinor == currentMinor { return true } else { return false } } -func IsLastVersion(versionToCheck string) bool { +func IsPreviousVersion(versionToCheck string) bool { toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck) - prevMajor, prevMinor := GetPreviousVersion(GetFullVersion()) + prevMajor, prevMinor := GetPreviousVersion(CurrentVersion) if toCheckMajor == prevMajor && toCheckMinor == prevMinor { return true diff --git a/model/version_test.go b/model/version_test.go index fb52d96a5..da40006be 100644 --- a/model/version_test.go +++ b/model/version_test.go @@ -8,9 +8,7 @@ import ( "testing" ) -func TestVersion(t *testing.T) { - GetFullVersion() - +func TestSplitVersion(t *testing.T) { major1, minor1, patch1 := SplitVersion("junk") if major1 != 0 || minor1 != 0 || patch1 != 0 { t.Fatal() @@ -35,38 +33,42 @@ func TestVersion(t *testing.T) { if major5 != 1 || minor5 != 2 || patch5 != 3 { t.Fatal() } +} - if IsLastVersion(GetFullVersion()) { - t.Fatal() +func TestGetPreviousVersion(t *testing.T) { + if major, minor := GetPreviousVersion("0.8.0"); major != 0 || minor != 7 { + t.Fatal(major, minor) } - if !IsLastVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR-1, VERSION_PATCH)) { - t.Fatal() + if major, minor := GetPreviousVersion("0.7.0"); major != 0 || minor != 6 { + t.Fatal(major, minor) } - // pacth should not affect current version check - if !IsLastVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR-1, VERSION_PATCH+1)) { - t.Fatal() + if major, minor := GetPreviousVersion("0.7.1"); major != 0 || minor != 6 { + t.Fatal(major, minor) } - if IsLastVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR+1, VERSION_PATCH)) { - t.Fatal() + if major, minor := GetPreviousVersion("0.7111.1"); major != 0 || minor != 0 { + t.Fatal(major, minor) } +} + +func TestIsCurrentVersion(t *testing.T) { + major, minor, patch := SplitVersion(CurrentVersion) - if !IsCurrentVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH)) { + if !IsCurrentVersion(CurrentVersion) { t.Fatal() } - // pacth should not affect current version check - if !IsCurrentVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH+1)) { + if !IsCurrentVersion(fmt.Sprintf("%v.%v.%v", major, minor, patch+100)) { t.Fatal() } - if IsCurrentVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR+1, VERSION_PATCH)) { + if IsCurrentVersion(fmt.Sprintf("%v.%v.%v", major, minor+1, patch)) { t.Fatal() } - if IsCurrentVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR+1, VERSION_MINOR, VERSION_PATCH)) { + if IsCurrentVersion(fmt.Sprintf("%v.%v.%v", major+1, minor, patch)) { t.Fatal() } } diff --git a/store/sql_post_store.go b/store/sql_post_store.go index 50e1c3c33..21e8e9d00 100644 --- a/store/sql_post_store.go +++ b/store/sql_post_store.go @@ -196,9 +196,9 @@ func (s SqlPostStore) GetEtag(channelId string) StoreChannel { var et etagPosts err := s.GetReplica().SelectOne(&et, "SELECT Id, UpdateAt FROM Posts WHERE ChannelId = :ChannelId ORDER BY UpdateAt DESC LIMIT 1", map[string]interface{}{"ChannelId": channelId}) if err != nil { - result.Data = fmt.Sprintf("%v.0.%v", model.GetFullVersion(), model.GetMillis()) + result.Data = fmt.Sprintf("%v.0.%v", model.CurrentVersion, model.GetMillis()) } else { - result.Data = fmt.Sprintf("%v.%v.%v", model.GetFullVersion(), et.Id, et.UpdateAt) + result.Data = fmt.Sprintf("%v.%v.%v", model.CurrentVersion, et.Id, et.UpdateAt) } storeChannel <- result diff --git a/store/sql_post_store_test.go b/store/sql_post_store_test.go index bec2ceb60..bc1cb2c2c 100644 --- a/store/sql_post_store_test.go +++ b/store/sql_post_store_test.go @@ -37,14 +37,14 @@ func TestPostStoreGet(t *testing.T) { o1.Message = "a" + model.NewId() + "b" etag1 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string) - if strings.Index(etag1, model.GetFullVersion()+".0.") != 0 { + if strings.Index(etag1, model.CurrentVersion+".0.") != 0 { t.Fatal("Invalid Etag") } o1 = (<-store.Post().Save(o1)).Data.(*model.Post) etag2 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string) - if strings.Index(etag2, model.GetFullVersion()+"."+o1.Id) != 0 { + if strings.Index(etag2, model.CurrentVersion+"."+o1.Id) != 0 { t.Fatal("Invalid Etag") } @@ -136,7 +136,7 @@ func TestPostStoreDelete(t *testing.T) { o1.Message = "a" + model.NewId() + "b" etag1 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string) - if strings.Index(etag1, model.GetFullVersion()+".0.") != 0 { + if strings.Index(etag1, model.CurrentVersion+".0.") != 0 { t.Fatal("Invalid Etag") } @@ -160,7 +160,7 @@ func TestPostStoreDelete(t *testing.T) { } etag2 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string) - if strings.Index(etag2, model.GetFullVersion()+"."+o1.Id) != 0 { + if strings.Index(etag2, model.CurrentVersion+"."+o1.Id) != 0 { t.Fatal("Invalid Etag") } } diff --git a/store/sql_store.go b/store/sql_store.go index 2e679b81a..3c41cb1fc 100644 --- a/store/sql_store.go +++ b/store/sql_store.go @@ -64,9 +64,9 @@ 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.IsLastVersion(schemaVersion) { + if model.IsPreviousVersion(schemaVersion) { 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.GetFullVersion()) + l4g.Warn("Attempting to upgrade the database schema version to " + model.CurrentVersion) } else { // If this is an 'upgrade needed' state but the user is attempting to skip a version then halt the world l4g.Critical("The database schema version of " + schemaVersion + " cannot be upgraded. You must not skip a version.") @@ -112,14 +112,14 @@ func NewSqlStore() Store { sqlStore.oauth.(*SqlOAuthStore).CreateIndexesIfNotExists() sqlStore.system.(*SqlSystemStore).CreateIndexesIfNotExists() - if model.IsLastVersion(schemaVersion) { - sqlStore.system.Update(&model.System{Name: "Version", Value: model.GetFullVersion()}) - l4g.Warn("The database schema has been upgraded to version " + model.GetFullVersion()) + if model.IsPreviousVersion(schemaVersion) { + sqlStore.system.Update(&model.System{Name: "Version", Value: model.CurrentVersion}) + l4g.Warn("The database schema has been upgraded to version " + model.CurrentVersion) } if schemaVersion == "" { - sqlStore.system.Save(&model.System{Name: "Version", Value: model.GetFullVersion()}) - l4g.Info("The database schema has been set to version " + model.GetFullVersion()) + sqlStore.system.Save(&model.System{Name: "Version", Value: model.CurrentVersion}) + l4g.Info("The database schema has been set to version " + model.CurrentVersion) } return sqlStore diff --git a/store/sql_user_store.go b/store/sql_user_store.go index 90e1343a8..778df367e 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -325,9 +325,9 @@ func (s SqlUserStore) GetEtagForProfiles(teamId string) StoreChannel { updateAt, err := s.GetReplica().SelectInt("SELECT UpdateAt FROM Users WHERE TeamId = :TeamId ORDER BY UpdateAt DESC LIMIT 1", map[string]interface{}{"TeamId": teamId}) if err != nil { - result.Data = fmt.Sprintf("%v.%v", model.GetFullVersion(), model.GetMillis()) + result.Data = fmt.Sprintf("%v.%v", model.CurrentVersion, model.GetMillis()) } else { - result.Data = fmt.Sprintf("%v.%v", model.GetFullVersion(), updateAt) + result.Data = fmt.Sprintf("%v.%v", model.CurrentVersion, updateAt) } storeChannel <- result diff --git a/utils/config.go b/utils/config.go index eed627448..6fd3a9ca7 100644 --- a/utils/config.go +++ b/utils/config.go @@ -276,9 +276,10 @@ func getSanitizeOptions(c *Config) map[string]bool { func getClientProperties(c *Config) map[string]string { props := make(map[string]string) - props["Version"] = model.GetFullVersion() - props["BuildNumber"] = model.BUILD_NUMBER - props["BuildDate"] = model.BUILD_DATE + props["Version"] = model.CurrentVersion + props["BuildNumber"] = model.BuildNumber + props["BuildDate"] = model.BuildDate + props["BuildHash"] = model.BuildHash props["SiteName"] = c.ServiceSettings.SiteName props["ByPassEmail"] = strconv.FormatBool(c.EmailSettings.ByPassEmail) diff --git a/web/react/components/user_settings_developer.jsx b/web/react/components/user_settings_developer.jsx index 3e75e7ad8..8b443499a 100644 --- a/web/react/components/user_settings_developer.jsx +++ b/web/react/components/user_settings_developer.jsx @@ -83,11 +83,10 @@ export default class DeveloperTab extends React.Component { >
  • {'Version'}
  • - { - global.window.config.Version + ' (' + - global.window.config.BuildNumber + '/' + - global.window.config.BuildDate + ')' - } + {'Version: ' + global.window.config.Version}
    + {'Build Number: ' + global.window.config.BuildNumber}
    + {'Build Date: ' + global.window.config.BuildDate}
    + {'Build Hash: ' + global.window.config.BuildHash}
  • -- cgit v1.2.3-1-g7c22 From 522e4934c92b274a9326469bd21a208f9fafad9e Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Thu, 17 Sep 2015 13:06:25 -0700 Subject: fixing versioning --- model/version.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/model/version.go b/model/version.go index 8b5258ec1..8f0c76ebe 100644 --- a/model/version.go +++ b/model/version.go @@ -20,9 +20,9 @@ var versions = []string{ } var CurrentVersion string = versions[0] -var BuildNumber = "developer" -var BuildDate = "unknown" -var BuildHash = "unknown" +var BuildNumber = "_BUILD_NUMBER_" +var BuildDate = "_BUILD_DATE_" +var BuildHash = "_BUILD_HASH_" func SplitVersion(version string) (int64, int64, int64) { parts := strings.Split(version, ".") -- cgit v1.2.3-1-g7c22 From c63da249640e50b1c93c5c5ff7b5d598aa737b1e Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Thu, 17 Sep 2015 13:24:55 -0700 Subject: moving to security tab --- web/react/components/user_settings_developer.jsx | 12 ------------ web/react/components/user_settings_security.jsx | 11 +++++++++++ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/web/react/components/user_settings_developer.jsx b/web/react/components/user_settings_developer.jsx index 8b443499a..1b04149dc 100644 --- a/web/react/components/user_settings_developer.jsx +++ b/web/react/components/user_settings_developer.jsx @@ -77,18 +77,6 @@ export default class DeveloperTab extends React.Component {

    {'Developer Settings'}

    {appSection} -
    -
      -
    • {'Version'}
    • -
    • - {'Version: ' + global.window.config.Version}
      - {'Build Number: ' + global.window.config.BuildNumber}
      - {'Build Date: ' + global.window.config.BuildDate}
      - {'Build Hash: ' + global.window.config.BuildHash}
      -
    • -
    diff --git a/web/react/components/user_settings_security.jsx b/web/react/components/user_settings_security.jsx index 6ccd09cb1..c10d790ae 100644 --- a/web/react/components/user_settings_security.jsx +++ b/web/react/components/user_settings_security.jsx @@ -251,6 +251,17 @@ export default class SecurityTab extends React.Component {
    {passwordSection}
    +
      +
    • {'Version ' + global.window.config.Version}
    • +
    • +
      {'Build Number: ' + global.window.config.BuildNumber}
      +
      {'Build Date: ' + global.window.config.BuildDate}
      +
      {'Build Hash: ' + global.window.config.BuildHash}
      +
    • +
    +


    Date: Thu, 17 Sep 2015 16:27:25 -0400 Subject: Adding go 1.5.1 and postgress to travis build --- .travis.yml | 11 +++++++++++ Makefile | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/.travis.yml b/.travis.yml index 877977dd4..02e1234d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,10 @@ language: go go: - 1.4.2 +- 1.5.1 +env: +- TRAVIS_DB=mysql +- TRAVIS_DB=postgres before_install: - gem install compass - sudo apt-get update -qq @@ -24,6 +28,9 @@ before_script: - mysql -e "CREATE DATABASE IF NOT EXISTS mattermost_test ;" -uroot - mysql -e "CREATE USER 'mmuser'@'%' IDENTIFIED BY 'mostest' ;" -uroot - mysql -e "GRANT ALL ON mattermost_test.* TO 'mmuser'@'%' ;" -uroot +- psql -c "create database mattermost_test ;" -U postgres +- psql -c "create user mmuser with password 'mostest' ;" -U postgres +- psql -c 'grant all privileges on database "mattermost_test" to mmuser ;' -U postgres services: - redis-server addons: @@ -38,6 +45,8 @@ deploy: on: repo: mattermost/platform tags: true + go: 1.4.2 + condition: $TRAVIS_DB = mysql - provider: s3 access_key_id: AKIAJCO3KJYEGWJIKDIQ @@ -52,3 +61,5 @@ deploy: on: repo: mattermost/platform branch: master + go: 1.4.2 + condition: $TRAVIS_DB = mysql diff --git a/Makefile b/Makefile index 972ebe960..a0c878e1d 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,11 @@ all: travis travis: @echo building for travis + if [ "$(TRAVIS_DB)" = "postgres" ]; then \ + sed -i'.bak' 's|mysql|postgres|g' config/config.json; \ + sed -i'.bak' 's|mmuser:mostest@tcp(dockerhost:3306)/mattermost_test?charset=utf8mb4,utf8|postgres://mmuser:mostest@dockerhost:5432/mattermost_test?sslmode=disable\&connect_timeout=10|g' config/config.json; \ + fi + rm -Rf $(DIST_ROOT) @$(GO) clean $(GOFLAGS) -i ./... -- cgit v1.2.3-1-g7c22 From bc8e69d99f5b7b22fd1b781fa1862c24e0de0b90 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Fri, 18 Sep 2015 11:56:23 -0400 Subject: Fixed incorrect check if a url starts with an explicit protocol --- web/react/utils/text_formatting.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/react/utils/text_formatting.jsx b/web/react/utils/text_formatting.jsx index 2025e16da..54d010dbf 100644 --- a/web/react/utils/text_formatting.jsx +++ b/web/react/utils/text_formatting.jsx @@ -56,7 +56,7 @@ function autolinkUrls(text, tokens) { const linkText = match.getMatchedText(); let url = linkText; - if (!url.lastIndexOf('http', 0) === 0) { + if (url.lastIndexOf('http', 0) !== 0) { url = `http://${linkText}`; } -- cgit v1.2.3-1-g7c22