Merge pull request #2016 from mattermost/PLT-1765
PLT-1765 allowing support of 2 previous versions
Этот коммит содержится в:
@@ -4,6 +4,7 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -29,6 +30,22 @@ var BuildNumber = "_BUILD_NUMBER_"
|
|||||||
var BuildDate = "_BUILD_DATE_"
|
var BuildDate = "_BUILD_DATE_"
|
||||||
var BuildHash = "_BUILD_HASH_"
|
var BuildHash = "_BUILD_HASH_"
|
||||||
var BuildEnterpriseReady = "_BUILD_ENTERPRISE_READY_"
|
var BuildEnterpriseReady = "_BUILD_ENTERPRISE_READY_"
|
||||||
|
var versionsWithoutHotFixes []string
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
versionsWithoutHotFixes = make([]string, 0, len(versions))
|
||||||
|
seen := make(map[string]string)
|
||||||
|
|
||||||
|
for _, version := range versions {
|
||||||
|
maj, min, _ := SplitVersion(version)
|
||||||
|
verStr := fmt.Sprintf("%v.%v.0", maj, min)
|
||||||
|
|
||||||
|
if seen[verStr] == "" {
|
||||||
|
versionsWithoutHotFixes = append(versionsWithoutHotFixes, verStr)
|
||||||
|
seen[verStr] = verStr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func SplitVersion(version string) (int64, int64, int64) {
|
func SplitVersion(version string) (int64, int64, int64) {
|
||||||
parts := strings.Split(version, ".")
|
parts := strings.Split(version, ".")
|
||||||
@@ -52,25 +69,17 @@ func SplitVersion(version string) (int64, int64, int64) {
|
|||||||
return major, minor, patch
|
return major, minor, patch
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPreviousVersion(currentVersion string) (int64, int64) {
|
func GetPreviousVersion(version string) string {
|
||||||
currentIndex := -1
|
verMajor, verMinor, _ := SplitVersion(version)
|
||||||
currentMajor, currentMinor, _ := SplitVersion(currentVersion)
|
verStr := fmt.Sprintf("%v.%v.0", verMajor, verMinor)
|
||||||
|
|
||||||
for index, version := range versions {
|
for index, v := range versionsWithoutHotFixes {
|
||||||
major, minor, _ := SplitVersion(version)
|
if v == verStr && len(versionsWithoutHotFixes) > index+1 {
|
||||||
|
return versionsWithoutHotFixes[index+1]
|
||||||
if currentMajor == major && currentMinor == minor {
|
|
||||||
currentIndex = index
|
|
||||||
}
|
|
||||||
|
|
||||||
if currentIndex >= 0 {
|
|
||||||
if currentMajor != major || currentMinor != minor {
|
|
||||||
return major, minor
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0, 0
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsOfficalBuild() bool {
|
func IsOfficalBuild() bool {
|
||||||
@@ -88,13 +97,24 @@ func IsCurrentVersion(versionToCheck string) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsPreviousVersion(versionToCheck string) bool {
|
func IsPreviousVersionsSupported(versionToCheck string) bool {
|
||||||
toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck)
|
toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck)
|
||||||
prevMajor, prevMinor := GetPreviousVersion(CurrentVersion)
|
versionToCheckStr := fmt.Sprintf("%v.%v.0", toCheckMajor, toCheckMinor)
|
||||||
|
|
||||||
if toCheckMajor == prevMajor && toCheckMinor == prevMinor {
|
// Current Supported
|
||||||
|
if versionsWithoutHotFixes[0] == versionToCheckStr {
|
||||||
return true
|
return true
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Current - 1 Supported
|
||||||
|
if versionsWithoutHotFixes[1] == versionToCheckStr {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Current - 2 Supported
|
||||||
|
if versionsWithoutHotFixes[2] == versionToCheckStr {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,20 +36,28 @@ func TestSplitVersion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetPreviousVersion(t *testing.T) {
|
func TestGetPreviousVersion(t *testing.T) {
|
||||||
if major, minor := GetPreviousVersion("1.0.0"); major != 0 || minor != 7 {
|
if GetPreviousVersion("1.3.0") != "1.2.0" {
|
||||||
t.Fatal(major, minor)
|
t.Fatal()
|
||||||
}
|
}
|
||||||
|
|
||||||
if major, minor := GetPreviousVersion("0.7.0"); major != 0 || minor != 6 {
|
if GetPreviousVersion("1.2.1") != "1.1.0" {
|
||||||
t.Fatal(major, minor)
|
t.Fatal()
|
||||||
}
|
}
|
||||||
|
|
||||||
if major, minor := GetPreviousVersion("0.7.1"); major != 0 || minor != 6 {
|
if GetPreviousVersion("1.1.0") != "1.0.0" {
|
||||||
t.Fatal(major, minor)
|
t.Fatal()
|
||||||
}
|
}
|
||||||
|
|
||||||
if major, minor := GetPreviousVersion("0.7111.1"); major != 0 || minor != 0 {
|
if GetPreviousVersion("1.0.0") != "0.7.0" {
|
||||||
t.Fatal(major, minor)
|
t.Fatal()
|
||||||
|
}
|
||||||
|
|
||||||
|
if GetPreviousVersion("0.7.1") != "0.6.0" {
|
||||||
|
t.Fatal()
|
||||||
|
}
|
||||||
|
|
||||||
|
if GetPreviousVersion("0.5.0") != "" {
|
||||||
|
t.Fatal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,3 +80,31 @@ func TestIsCurrentVersion(t *testing.T) {
|
|||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIsPreviousVersionsSupported(t *testing.T) {
|
||||||
|
|
||||||
|
// 1.4.0 CURRENT RELEASED VERSION
|
||||||
|
if !IsPreviousVersionsSupported(versions[0]) {
|
||||||
|
t.Fatal()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1.3.0
|
||||||
|
if !IsPreviousVersionsSupported(versions[1]) {
|
||||||
|
t.Fatal()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1.2.1
|
||||||
|
if !IsPreviousVersionsSupported(versions[2]) {
|
||||||
|
t.Fatal()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1.2.0
|
||||||
|
if !IsPreviousVersionsSupported(versions[3]) {
|
||||||
|
t.Fatal()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1.1.0 NOT SUPPORTED
|
||||||
|
if IsPreviousVersionsSupported(versions[4]) {
|
||||||
|
t.Fatal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -38,6 +38,11 @@ func NewSqlPostStore(sqlStore *SqlStore) PostStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlPostStore) UpgradeSchemaIfNeeded() {
|
func (s SqlPostStore) UpgradeSchemaIfNeeded() {
|
||||||
|
// ADDED for 1.3 REMOVE for 1.6
|
||||||
|
s.RemoveColumnIfExists("Posts", "ImgCount")
|
||||||
|
|
||||||
|
// ADDED for 1.3 REMOVE for 1.6
|
||||||
|
s.GetMaster().Exec(`UPDATE Preferences SET Type = :NewType WHERE Type = :CurrentType`, map[string]string{"NewType": model.POST_JOIN_LEAVE, "CurrentType": "join_leave"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlPostStore) CreateIndexesIfNotExists() {
|
func (s SqlPostStore) CreateIndexesIfNotExists() {
|
||||||
|
|||||||
@@ -73,25 +73,13 @@ func NewSqlStore() Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
schemaVersion := sqlStore.GetCurrentSchemaVersion()
|
schemaVersion := sqlStore.GetCurrentSchemaVersion()
|
||||||
isSchemaVersion07 := false // REMOVE AFTER 1.2 SHIP see PLT-828
|
|
||||||
isSchemaVersion10 := false // REMOVE AFTER 1.2 SHIP see PLT-828
|
|
||||||
|
|
||||||
// If the version is already set then we are potentially in an 'upgrade needed' state
|
// If the version is already set then we are potentially in an 'upgrade needed' state
|
||||||
if schemaVersion != "" {
|
if schemaVersion != "" {
|
||||||
// Check to see if it's the most current database schema version
|
// Check to see if it's the most current database schema version
|
||||||
if !model.IsCurrentVersion(schemaVersion) {
|
if !model.IsCurrentVersion(schemaVersion) {
|
||||||
// If we are upgrading from the previous version then print a warning and continue
|
// If we are upgrading from the previous version then print a warning and continue
|
||||||
|
if model.IsPreviousVersionsSupported(schemaVersion) {
|
||||||
// Special case
|
|
||||||
if schemaVersion == "0.7.1" || schemaVersion == "0.7.0" {
|
|
||||||
isSchemaVersion07 = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if schemaVersion == "1.0.0" {
|
|
||||||
isSchemaVersion10 = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if model.IsPreviousVersion(schemaVersion) || isSchemaVersion07 || isSchemaVersion10 {
|
|
||||||
l4g.Warn(utils.T("store.sql.schema_out_of_date.warn"), schemaVersion)
|
l4g.Warn(utils.T("store.sql.schema_out_of_date.warn"), schemaVersion)
|
||||||
l4g.Warn(utils.T("store.sql.schema_upgrade_attempt.warn"), model.CurrentVersion)
|
l4g.Warn(utils.T("store.sql.schema_upgrade_attempt.warn"), model.CurrentVersion)
|
||||||
} else {
|
} else {
|
||||||
@@ -103,13 +91,6 @@ func NewSqlStore() Store {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// REMOVE AFTER 1.2 SHIP see PLT-828
|
|
||||||
if sqlStore.DoesTableExist("Sessions") {
|
|
||||||
if sqlStore.DoesColumnExist("Sessions", "AltId") {
|
|
||||||
sqlStore.GetMaster().Exec("DROP TABLE IF EXISTS Sessions")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sqlStore.team = NewSqlTeamStore(sqlStore)
|
sqlStore.team = NewSqlTeamStore(sqlStore)
|
||||||
sqlStore.channel = NewSqlChannelStore(sqlStore)
|
sqlStore.channel = NewSqlChannelStore(sqlStore)
|
||||||
sqlStore.post = NewSqlPostStore(sqlStore)
|
sqlStore.post = NewSqlPostStore(sqlStore)
|
||||||
@@ -150,7 +131,7 @@ func NewSqlStore() Store {
|
|||||||
|
|
||||||
sqlStore.preference.(*SqlPreferenceStore).DeleteUnusedFeatures()
|
sqlStore.preference.(*SqlPreferenceStore).DeleteUnusedFeatures()
|
||||||
|
|
||||||
if model.IsPreviousVersion(schemaVersion) || isSchemaVersion07 || isSchemaVersion10 {
|
if model.IsPreviousVersionsSupported(schemaVersion) {
|
||||||
sqlStore.system.Update(&model.System{Name: "Version", Value: model.CurrentVersion})
|
sqlStore.system.Update(&model.System{Name: "Version", Value: model.CurrentVersion})
|
||||||
l4g.Warn(utils.T("store.sql.upgraded.warn"), model.CurrentVersion)
|
l4g.Warn(utils.T("store.sql.upgraded.warn"), model.CurrentVersion)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ func NewSqlUserStore(sqlStore *SqlStore) UserStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) UpgradeSchemaIfNeeded() {
|
func (us SqlUserStore) UpgradeSchemaIfNeeded() {
|
||||||
us.CreateColumnIfNotExists("Users", "Locale", "varchar(5)", "character varying(5)", model.DEFAULT_LOCALE) // Added After 1.4
|
// ADDED for 1.5 REMOVE for 1.8
|
||||||
|
us.CreateColumnIfNotExists("Users", "Locale", "varchar(5)", "character varying(5)", model.DEFAULT_LOCALE)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) CreateIndexesIfNotExists() {
|
func (us SqlUserStore) CreateIndexesIfNotExists() {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user