MM-31063: Change constants to use CamelCase (#16608)
* MM-31063: Change constants to use CamelCase * store package * change allcaps to camel case (#16615) * New tools.mod Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
8b6ac5f5d2
Коммит
c1dd23a3c8
@@ -23,13 +23,13 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SIZE = model.SESSION_CACHE_SIZE
|
||||
ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_DURATION = 15 * time.Minute // 15 mins
|
||||
AllChannelMembersForUserCacheSize = model.SESSION_CACHE_SIZE
|
||||
AllChannelMembersForUserCacheDuration = 15 * time.Minute // 15 mins
|
||||
|
||||
ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_SIZE = model.SESSION_CACHE_SIZE
|
||||
ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_DURATION = 30 * time.Minute // 30 mins
|
||||
AllChannelMembersNotifyPropsForChannelCacheSize = model.SESSION_CACHE_SIZE
|
||||
AllChannelMembersNotifyPropsForChannelCacheDuration = 30 * time.Minute // 30 mins
|
||||
|
||||
CHANNEL_CACHE_DURATION = 15 * time.Minute // 15 mins
|
||||
ChannelCacheDuration = 15 * time.Minute // 15 mins
|
||||
)
|
||||
|
||||
type SqlChannelStore struct {
|
||||
@@ -335,10 +335,10 @@ type publicChannel struct {
|
||||
}
|
||||
|
||||
var allChannelMembersForUserCache = cache.NewLRU(cache.LRUOptions{
|
||||
Size: ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SIZE,
|
||||
Size: AllChannelMembersForUserCacheSize,
|
||||
})
|
||||
var allChannelMembersNotifyPropsForChannelCache = cache.NewLRU(cache.LRUOptions{
|
||||
Size: ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_SIZE,
|
||||
Size: AllChannelMembersNotifyPropsForChannelCacheSize,
|
||||
})
|
||||
var channelByNameCache = cache.NewLRU(cache.LRUOptions{
|
||||
Size: model.CHANNEL_CACHE_SIZE,
|
||||
@@ -1266,7 +1266,7 @@ func (s SqlChannelStore) GetByNames(teamId string, names []string, allowFromCach
|
||||
return nil, errors.Wrap(err, msg)
|
||||
}
|
||||
for _, channel := range dbChannels {
|
||||
channelByNameCache.SetWithExpiry(teamId+channel.Name, channel, CHANNEL_CACHE_DURATION)
|
||||
channelByNameCache.SetWithExpiry(teamId+channel.Name, channel, ChannelCacheDuration)
|
||||
channels = append(channels, channel)
|
||||
}
|
||||
// Not all channels are in cache. Increment aggregate miss counter.
|
||||
@@ -1316,7 +1316,7 @@ func (s SqlChannelStore) getByName(teamId string, name string, includeDeleted bo
|
||||
return nil, errors.Wrapf(err, "failed to find channel with TeamId=%s and Name=%s", teamId, name)
|
||||
}
|
||||
|
||||
channelByNameCache.SetWithExpiry(teamId+name, &channel, CHANNEL_CACHE_DURATION)
|
||||
channelByNameCache.SetWithExpiry(teamId+name, &channel, ChannelCacheDuration)
|
||||
return &channel, nil
|
||||
}
|
||||
|
||||
@@ -1360,7 +1360,7 @@ func (s SqlChannelStore) GetDeleted(teamId string, offset int, limit int, userId
|
||||
return channels, nil
|
||||
}
|
||||
|
||||
var CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY = `
|
||||
var ChannelMembersWithSchemeSelectQuery = `
|
||||
SELECT
|
||||
ChannelMembers.*,
|
||||
TeamScheme.DefaultChannelGuestRole TeamSchemeDefaultGuestRole,
|
||||
@@ -1586,7 +1586,7 @@ func (s SqlChannelStore) UpdateMultipleMembers(members []*model.ChannelMember) (
|
||||
|
||||
// TODO: Get this out of the transaction when is possible
|
||||
var dbMember channelMemberWithSchemeRoles
|
||||
if err := transaction.SelectOne(&dbMember, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.ChannelId = :ChannelId AND ChannelMembers.UserId = :UserId", map[string]interface{}{"ChannelId": member.ChannelId, "UserId": member.UserId}); err != nil {
|
||||
if err := transaction.SelectOne(&dbMember, ChannelMembersWithSchemeSelectQuery+"WHERE ChannelMembers.ChannelId = :ChannelId AND ChannelMembers.UserId = :UserId", map[string]interface{}{"ChannelId": member.ChannelId, "UserId": member.UserId}); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("ChannelMember", fmt.Sprintf("channelId=%s, userId=%s", member.ChannelId, member.UserId))
|
||||
}
|
||||
@@ -1611,7 +1611,7 @@ func (s SqlChannelStore) UpdateMember(member *model.ChannelMember) (*model.Chann
|
||||
|
||||
func (s SqlChannelStore) GetMembers(channelId string, offset, limit int) (*model.ChannelMembers, error) {
|
||||
var dbMembers channelMemberWithSchemeRolesList
|
||||
_, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelId = :ChannelId LIMIT :Limit OFFSET :Offset", map[string]interface{}{"ChannelId": channelId, "Limit": limit, "Offset": offset})
|
||||
_, err := s.GetReplica().Select(&dbMembers, ChannelMembersWithSchemeSelectQuery+"WHERE ChannelId = :ChannelId LIMIT :Limit OFFSET :Offset", map[string]interface{}{"ChannelId": channelId, "Limit": limit, "Offset": offset})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get ChannelMembers with channelId=%s", channelId)
|
||||
}
|
||||
@@ -1641,7 +1641,7 @@ func (s SqlChannelStore) GetChannelMembersTimezones(channelId string) ([]model.S
|
||||
func (s SqlChannelStore) GetMember(channelId string, userId string) (*model.ChannelMember, error) {
|
||||
var dbMember channelMemberWithSchemeRoles
|
||||
|
||||
if err := s.GetReplica().SelectOne(&dbMember, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.ChannelId = :ChannelId AND ChannelMembers.UserId = :UserId", map[string]interface{}{"ChannelId": channelId, "UserId": userId}); err != nil {
|
||||
if err := s.GetReplica().SelectOne(&dbMember, ChannelMembersWithSchemeSelectQuery+"WHERE ChannelMembers.ChannelId = :ChannelId AND ChannelMembers.UserId = :UserId", map[string]interface{}{"ChannelId": channelId, "UserId": userId}); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("ChannelMember", fmt.Sprintf("channelId=%s, userId=%s", channelId, userId))
|
||||
}
|
||||
@@ -1791,7 +1791,7 @@ func (s SqlChannelStore) GetAllChannelMembersForUser(userId string, allowFromCac
|
||||
ids := data.ToMapStringString()
|
||||
|
||||
if allowFromCache {
|
||||
allChannelMembersForUserCache.SetWithExpiry(cache_key, ids, ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_DURATION)
|
||||
allChannelMembersForUserCache.SetWithExpiry(cache_key, ids, AllChannelMembersForUserCacheDuration)
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
@@ -1838,7 +1838,7 @@ func (s SqlChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId str
|
||||
props[data[i].UserId] = data[i].NotifyProps
|
||||
}
|
||||
|
||||
allChannelMembersNotifyPropsForChannelCache.SetWithExpiry(channelId, props, ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_DURATION)
|
||||
allChannelMembersNotifyPropsForChannelCache.SetWithExpiry(channelId, props, AllChannelMembersNotifyPropsForChannelCacheDuration)
|
||||
|
||||
return props, nil
|
||||
}
|
||||
@@ -2363,7 +2363,7 @@ func (s SqlChannelStore) AnalyticsDeletedTypeCount(teamId string, channelType st
|
||||
|
||||
func (s SqlChannelStore) GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, error) {
|
||||
var dbMembers channelMemberWithSchemeRolesList
|
||||
_, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.UserId = :UserId AND (Teams.Id = :TeamId OR Teams.Id = '' OR Teams.Id IS NULL)", map[string]interface{}{"TeamId": teamId, "UserId": userId})
|
||||
_, err := s.GetReplica().Select(&dbMembers, ChannelMembersWithSchemeSelectQuery+"WHERE ChannelMembers.UserId = :UserId AND (Teams.Id = :TeamId OR Teams.Id = '' OR Teams.Id IS NULL)", map[string]interface{}{"TeamId": teamId, "UserId": userId})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find ChannelMembers data with teamId=%s and userId=%s", teamId, userId)
|
||||
}
|
||||
@@ -2374,7 +2374,7 @@ func (s SqlChannelStore) GetMembersForUser(teamId string, userId string) (*model
|
||||
func (s SqlChannelStore) GetMembersForUserWithPagination(teamId, userId string, page, perPage int) (*model.ChannelMembers, error) {
|
||||
var dbMembers channelMemberWithSchemeRolesList
|
||||
offset := page * perPage
|
||||
_, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.UserId = :UserId Limit :Limit Offset :Offset", map[string]interface{}{"TeamId": teamId, "UserId": userId, "Limit": perPage, "Offset": offset})
|
||||
_, err := s.GetReplica().Select(&dbMembers, ChannelMembersWithSchemeSelectQuery+"WHERE ChannelMembers.UserId = :UserId Limit :Limit Offset :Offset", map[string]interface{}{"TeamId": teamId, "UserId": userId, "Limit": perPage, "Offset": offset})
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find ChannelMembers data with teamId=%s and userId=%s", teamId, userId)
|
||||
@@ -2959,7 +2959,7 @@ func (s SqlChannelStore) GetMembersByIds(channelId string, userIds []string) (*m
|
||||
keys, props := MapStringsToQueryParams(userIds, "User")
|
||||
props["ChannelId"] = channelId
|
||||
|
||||
if _, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.ChannelId = :ChannelId AND ChannelMembers.UserId IN "+keys, props); err != nil {
|
||||
if _, err := s.GetReplica().Select(&dbMembers, ChannelMembersWithSchemeSelectQuery+"WHERE ChannelMembers.ChannelId = :ChannelId AND ChannelMembers.UserId IN "+keys, props); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find ChannelMembers with channelId=%s and userId in %v", channelId, userIds)
|
||||
}
|
||||
|
||||
@@ -2972,7 +2972,7 @@ func (s SqlChannelStore) GetMembersByChannelIds(channelIds []string, userId stri
|
||||
keys, props := MapStringsToQueryParams(channelIds, "Channel")
|
||||
props["UserId"] = userId
|
||||
|
||||
if _, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.UserId = :UserId AND ChannelMembers.ChannelId IN "+keys, props); err != nil {
|
||||
if _, err := s.GetReplica().Select(&dbMembers, ChannelMembersWithSchemeSelectQuery+"WHERE ChannelMembers.UserId = :UserId AND ChannelMembers.ChannelId IN "+keys, props); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find ChannelMembers with userId=%s and channelId in %v", userId, channelIds)
|
||||
}
|
||||
|
||||
|
||||
@@ -1378,8 +1378,8 @@ func (s *SqlPostStore) search(teamId string, userId string, params *model.Search
|
||||
}
|
||||
|
||||
func removeMysqlStopWordsFromTerms(terms string) (string, error) {
|
||||
stopWords := make([]string, len(searchlayer.MYSQL_STOP_WORDS))
|
||||
copy(stopWords, searchlayer.MYSQL_STOP_WORDS)
|
||||
stopWords := make([]string, len(searchlayer.MySQLStopWords))
|
||||
copy(stopWords, searchlayer.MySQLStopWords)
|
||||
re, err := regexp.Compile(fmt.Sprintf(`^(%s)$`, strings.Join(stopWords, "|")))
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -46,7 +46,7 @@ func (s SqlPreferenceStore) deleteUnusedFeatures() {
|
||||
WHERE
|
||||
Category = :Category
|
||||
AND Value = :Value
|
||||
AND Name LIKE '` + store.FEATURE_TOGGLE_PREFIX + `%'`
|
||||
AND Name LIKE '` + store.FeatureTogglePrefix + `%'`
|
||||
|
||||
queryParams := map[string]string{
|
||||
"Category": model.PREFERENCE_CATEGORY_ADVANCED_SETTINGS,
|
||||
|
||||
@@ -29,25 +29,25 @@ func TestDeleteUnusedFeatures(t *testing.T) {
|
||||
{
|
||||
UserId: userId1,
|
||||
Category: category,
|
||||
Name: store.FEATURE_TOGGLE_PREFIX + feature1,
|
||||
Name: store.FeatureTogglePrefix + feature1,
|
||||
Value: "true",
|
||||
},
|
||||
{
|
||||
UserId: userId2,
|
||||
Category: category,
|
||||
Name: store.FEATURE_TOGGLE_PREFIX + feature1,
|
||||
Name: store.FeatureTogglePrefix + feature1,
|
||||
Value: "false",
|
||||
},
|
||||
{
|
||||
UserId: userId1,
|
||||
Category: category,
|
||||
Name: store.FEATURE_TOGGLE_PREFIX + feature2,
|
||||
Name: store.FeatureTogglePrefix + feature2,
|
||||
Value: "false",
|
||||
},
|
||||
{
|
||||
UserId: userId2,
|
||||
Category: category,
|
||||
Name: store.FEATURE_TOGGLE_PREFIX + feature2,
|
||||
Name: store.FeatureTogglePrefix + feature2,
|
||||
Value: "true",
|
||||
},
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func TestDeleteUnusedFeatures(t *testing.T) {
|
||||
FROM Preferences
|
||||
WHERE Category = :Category
|
||||
AND Value = :Val
|
||||
AND Name LIKE '`+store.FEATURE_TOGGLE_PREFIX+`%'`, map[string]interface{}{"Category": model.PREFERENCE_CATEGORY_ADVANCED_SETTINGS, "Val": "false"}); err != nil {
|
||||
AND Name LIKE '`+store.FeatureTogglePrefix+`%'`, map[string]interface{}{"Category": model.PREFERENCE_CATEGORY_ADVANCED_SETTINGS, "Val": "false"}); err != nil {
|
||||
require.Nil(t, err)
|
||||
} else if val != 0 {
|
||||
require.Fail(t, "Found %d features with value 'false', expected all to be deleted", val)
|
||||
@@ -73,7 +73,7 @@ func TestDeleteUnusedFeatures(t *testing.T) {
|
||||
FROM Preferences
|
||||
WHERE Category = :Category
|
||||
AND Value = :Val
|
||||
AND Name LIKE '`+store.FEATURE_TOGGLE_PREFIX+`%'`, map[string]interface{}{"Category": model.PREFERENCE_CATEGORY_ADVANCED_SETTINGS, "Val": "true"}); err != nil {
|
||||
AND Name LIKE '`+store.FeatureTogglePrefix+`%'`, map[string]interface{}{"Category": model.PREFERENCE_CATEGORY_ADVANCED_SETTINGS, "Val": "true"}); err != nil {
|
||||
require.Nil(t, err)
|
||||
} else if val == 0 {
|
||||
require.Fail(t, "Found %d features with value 'true', expected to find at least %d features", val, 2)
|
||||
|
||||
@@ -132,7 +132,7 @@ func (s *SqlReactionStore) DeleteAllWithEmojiName(emojiName string) error {
|
||||
|
||||
for _, reaction := range reactions {
|
||||
reaction := reaction
|
||||
_, err := s.GetMaster().Exec(UPDATE_POST_HAS_REACTIONS_ON_DELETE_QUERY,
|
||||
_, err := s.GetMaster().Exec(UpdatePostHasReactionsOnDeleteQuery,
|
||||
map[string]interface{}{
|
||||
"PostId": reaction.PostId,
|
||||
"UpdateAt": model.GetMillis(),
|
||||
@@ -191,7 +191,7 @@ func deleteReactionAndUpdatePost(transaction *gorp.Transaction, reaction *model.
|
||||
}
|
||||
|
||||
const (
|
||||
UPDATE_POST_HAS_REACTIONS_ON_DELETE_QUERY = `UPDATE
|
||||
UpdatePostHasReactionsOnDeleteQuery = `UPDATE
|
||||
Posts
|
||||
SET
|
||||
UpdateAt = :UpdateAt,
|
||||
@@ -202,7 +202,7 @@ const (
|
||||
|
||||
func updatePostForReactionsOnDelete(transaction *gorp.Transaction, postId string) error {
|
||||
updateAt := model.GetMillis()
|
||||
_, err := transaction.Exec(UPDATE_POST_HAS_REACTIONS_ON_DELETE_QUERY, map[string]interface{}{"PostId": postId, "UpdateAt": updateAt})
|
||||
_, err := transaction.Exec(UpdatePostHasReactionsOnDeleteQuery, map[string]interface{}{"PostId": postId, "UpdateAt": updateAt})
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
SESSIONS_CLEANUP_DELAY_MILLISECONDS = 100
|
||||
SessionsCleanupDelayMilliseconds = 100
|
||||
)
|
||||
|
||||
type SqlSessionStore struct {
|
||||
@@ -304,6 +304,6 @@ func (me SqlSessionStore) Cleanup(expiryTime int64, batchSize int64) {
|
||||
return
|
||||
}
|
||||
|
||||
time.Sleep(SESSIONS_CLEANUP_DELAY_MILLISECONDS * time.Millisecond)
|
||||
time.Sleep(SessionsCleanupDelayMilliseconds * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,52 +33,52 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
INDEX_TYPE_FULL_TEXT = "full_text"
|
||||
INDEX_TYPE_DEFAULT = "default"
|
||||
PG_DUP_TABLE_ERROR_CODE = "42P07" // see https://github.com/lib/pq/blob/master/error.go#L268
|
||||
MYSQL_DUP_TABLE_ERROR_CODE = uint16(1050) // see https://dev.mysql.com/doc/mysql-errors/5.7/en/server-error-reference.html#error_er_table_exists_error
|
||||
DB_PING_ATTEMPTS = 18
|
||||
DB_PING_TIMEOUT_SECS = 10
|
||||
IndexTypeFullText = "full_text"
|
||||
IndexTypeDefault = "default"
|
||||
PGDupTableErrorCode = "42P07" // see https://github.com/lib/pq/blob/master/error.go#L268
|
||||
MySQLDupTableErrorCode = uint16(1050) // see https://dev.mysql.com/doc/mysql-errors/5.7/en/server-error-reference.html#error_er_table_exists_error
|
||||
DBPingAttempts = 18
|
||||
DBPingTimeoutSecs = 10
|
||||
// This is a numerical version string by postgres. The format is
|
||||
// 2 characters for major, minor, and patch version prior to 10.
|
||||
// After 10, it's major and minor only.
|
||||
// 10.1 would be 100001.
|
||||
// 9.6.3 would be 90603.
|
||||
MINIMUM_REQUIRED_POSTGRES_VERSION = 100000
|
||||
MinimumRequiredPostgresVersion = 100000
|
||||
)
|
||||
|
||||
const (
|
||||
EXIT_GENERIC_FAILURE = 1
|
||||
EXIT_CREATE_TABLE = 100
|
||||
EXIT_DB_OPEN = 101
|
||||
EXIT_PING = 102
|
||||
EXIT_NO_DRIVER = 103
|
||||
EXIT_TABLE_EXISTS = 104
|
||||
EXIT_TABLE_EXISTS_MYSQL = 105
|
||||
EXIT_COLUMN_EXISTS = 106
|
||||
EXIT_DOES_COLUMN_EXISTS_POSTGRES = 107
|
||||
EXIT_DOES_COLUMN_EXISTS_MYSQL = 108
|
||||
EXIT_DOES_COLUMN_EXISTS_MISSING = 109
|
||||
EXIT_CREATE_COLUMN_POSTGRES = 110
|
||||
EXIT_CREATE_COLUMN_MYSQL = 111
|
||||
EXIT_CREATE_COLUMN_MISSING = 112
|
||||
EXIT_REMOVE_COLUMN = 113
|
||||
EXIT_RENAME_COLUMN = 114
|
||||
EXIT_MAX_COLUMN = 115
|
||||
EXIT_ALTER_COLUMN = 116
|
||||
EXIT_CREATE_INDEX_POSTGRES = 117
|
||||
EXIT_CREATE_INDEX_MYSQL = 118
|
||||
EXIT_CREATE_INDEX_FULL_MYSQL = 119
|
||||
EXIT_CREATE_INDEX_MISSING = 120
|
||||
EXIT_REMOVE_INDEX_POSTGRES = 121
|
||||
EXIT_REMOVE_INDEX_MYSQL = 122
|
||||
EXIT_REMOVE_INDEX_MISSING = 123
|
||||
EXIT_REMOVE_TABLE = 134
|
||||
EXIT_CREATE_INDEX_SQLITE = 135
|
||||
EXIT_REMOVE_INDEX_SQLITE = 136
|
||||
EXIT_TABLE_EXISTS_SQLITE = 137
|
||||
EXIT_DOES_COLUMN_EXISTS_SQLITE = 138
|
||||
EXIT_ALTER_PRIMARY_KEY = 139
|
||||
ExitGenericFailure = 1
|
||||
ExitCreateTable = 100
|
||||
ExitDBOpen = 101
|
||||
ExitPing = 102
|
||||
ExitNoDriver = 103
|
||||
ExitTableExists = 104
|
||||
ExitTableExistsMySQL = 105
|
||||
ExitColumnExists = 106
|
||||
ExitDoesColumnExistsPostgres = 107
|
||||
ExitDoesColumnExistsMySQL = 108
|
||||
ExitDoesColumnExistsMissing = 109
|
||||
ExitCreateColumnPostgres = 110
|
||||
ExitCreateColumnMySQL = 111
|
||||
ExitCreateColumnMissing = 112
|
||||
ExitRemoveColumn = 113
|
||||
ExitRenameColumn = 114
|
||||
ExitMaxColumn = 115
|
||||
ExitAlterColumn = 116
|
||||
ExitCreateIndexPostgres = 117
|
||||
ExitCreateIndexMySQL = 118
|
||||
ExitCreateIndexFullMySQL = 119
|
||||
ExitCreateIndexMissing = 120
|
||||
ExitRemoveIndexPostgres = 121
|
||||
ExitRemoveIndexMySQL = 122
|
||||
ExitRemoveIndexMissing = 123
|
||||
ExitRemoveTable = 134
|
||||
ExitCreateIndexSqlite = 135
|
||||
ExitRemoveIndexSqlite = 136
|
||||
ExitTableExists_SQLITE = 137
|
||||
ExitDoesColumnExistsSqlite = 138
|
||||
ExitAlterPrimaryKey = 139
|
||||
)
|
||||
|
||||
type SqlStoreStores struct {
|
||||
@@ -193,7 +193,7 @@ func New(settings model.SqlSettings, metrics einterfaces.MetricsInterface) *SqlS
|
||||
mlog.Warn("Duplicate key error occurred; assuming table already created and proceeding.", mlog.Err(err))
|
||||
} else {
|
||||
mlog.Critical("Error creating database tables.", mlog.Err(err))
|
||||
os.Exit(EXIT_CREATE_TABLE)
|
||||
os.Exit(ExitCreateTable)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ func New(settings model.SqlSettings, metrics einterfaces.MetricsInterface) *SqlS
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to upgrade database.", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
os.Exit(ExitGenericFailure)
|
||||
}
|
||||
|
||||
store.stores.team.(*SqlTeamStore).createIndexesIfNotExists()
|
||||
@@ -244,24 +244,24 @@ func setupConnection(con_type string, dataSource string, settings *model.SqlSett
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to open SQL connection to err.", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_DB_OPEN)
|
||||
os.Exit(ExitDBOpen)
|
||||
}
|
||||
|
||||
for i := 0; i < DB_PING_ATTEMPTS; i++ {
|
||||
for i := 0; i < DBPingAttempts; i++ {
|
||||
mlog.Info("Pinging SQL", mlog.String("database", con_type))
|
||||
ctx, cancel := context.WithTimeout(context.Background(), DB_PING_TIMEOUT_SECS*time.Second)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), DBPingTimeoutSecs*time.Second)
|
||||
defer cancel()
|
||||
err = db.PingContext(ctx)
|
||||
if err == nil {
|
||||
break
|
||||
} else {
|
||||
if i == DB_PING_ATTEMPTS-1 {
|
||||
if i == DBPingAttempts-1 {
|
||||
mlog.Critical("Failed to ping DB, server will exit.", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_PING)
|
||||
os.Exit(ExitPing)
|
||||
} else {
|
||||
mlog.Error("Failed to ping DB", mlog.Err(err), mlog.Int("retrying in seconds", DB_PING_TIMEOUT_SECS))
|
||||
time.Sleep(DB_PING_TIMEOUT_SECS * time.Second)
|
||||
mlog.Error("Failed to ping DB", mlog.Err(err), mlog.Int("retrying in seconds", DBPingTimeoutSecs))
|
||||
time.Sleep(DBPingTimeoutSecs * time.Second)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -283,7 +283,7 @@ func setupConnection(con_type string, dataSource string, settings *model.SqlSett
|
||||
} else {
|
||||
mlog.Critical("Failed to create dialect specific driver")
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_NO_DRIVER)
|
||||
os.Exit(ExitNoDriver)
|
||||
}
|
||||
|
||||
if settings.Trace != nil && *settings.Trace {
|
||||
@@ -441,7 +441,7 @@ func (ss *SqlStore) DoesTableExist(tableName string) bool {
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to check if table exists", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_TABLE_EXISTS)
|
||||
os.Exit(ExitTableExists)
|
||||
}
|
||||
|
||||
return count > 0
|
||||
@@ -463,7 +463,7 @@ func (ss *SqlStore) DoesTableExist(tableName string) bool {
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to check if table exists", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_TABLE_EXISTS_MYSQL)
|
||||
os.Exit(ExitTableExistsMySQL)
|
||||
}
|
||||
|
||||
return count > 0
|
||||
@@ -477,7 +477,7 @@ func (ss *SqlStore) DoesTableExist(tableName string) bool {
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to check if table exists", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_TABLE_EXISTS_SQLITE)
|
||||
os.Exit(ExitTableExists_SQLITE)
|
||||
}
|
||||
|
||||
return count > 0
|
||||
@@ -485,7 +485,7 @@ func (ss *SqlStore) DoesTableExist(tableName string) bool {
|
||||
} else {
|
||||
mlog.Critical("Failed to check if column exists because of missing driver")
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_COLUMN_EXISTS)
|
||||
os.Exit(ExitColumnExists)
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -509,7 +509,7 @@ func (ss *SqlStore) DoesColumnExist(tableName string, columnName string) bool {
|
||||
|
||||
mlog.Critical("Failed to check if column exists", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_DOES_COLUMN_EXISTS_POSTGRES)
|
||||
os.Exit(ExitDoesColumnExistsPostgres)
|
||||
}
|
||||
|
||||
return count > 0
|
||||
@@ -532,7 +532,7 @@ func (ss *SqlStore) DoesColumnExist(tableName string, columnName string) bool {
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to check if column exists", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_DOES_COLUMN_EXISTS_MYSQL)
|
||||
os.Exit(ExitDoesColumnExistsMySQL)
|
||||
}
|
||||
|
||||
return count > 0
|
||||
@@ -547,7 +547,7 @@ func (ss *SqlStore) DoesColumnExist(tableName string, columnName string) bool {
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to check if column exists", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_DOES_COLUMN_EXISTS_SQLITE)
|
||||
os.Exit(ExitDoesColumnExistsSqlite)
|
||||
}
|
||||
|
||||
return count > 0
|
||||
@@ -555,7 +555,7 @@ func (ss *SqlStore) DoesColumnExist(tableName string, columnName string) bool {
|
||||
} else {
|
||||
mlog.Critical("Failed to check if column exists because of missing driver")
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_DOES_COLUMN_EXISTS_MISSING)
|
||||
os.Exit(ExitDoesColumnExistsMissing)
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -574,7 +574,7 @@ func (ss *SqlStore) DoesTriggerExist(triggerName string) bool {
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to check if trigger exists", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
os.Exit(ExitGenericFailure)
|
||||
}
|
||||
|
||||
return count > 0
|
||||
@@ -593,7 +593,7 @@ func (ss *SqlStore) DoesTriggerExist(triggerName string) bool {
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to check if trigger exists", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
os.Exit(ExitGenericFailure)
|
||||
}
|
||||
|
||||
return count > 0
|
||||
@@ -601,7 +601,7 @@ func (ss *SqlStore) DoesTriggerExist(triggerName string) bool {
|
||||
} else {
|
||||
mlog.Critical("Failed to check if column exists because of missing driver")
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
os.Exit(ExitGenericFailure)
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -617,7 +617,7 @@ func (ss *SqlStore) CreateColumnIfNotExists(tableName string, columnName string,
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to create column", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_COLUMN_POSTGRES)
|
||||
os.Exit(ExitCreateColumnPostgres)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -627,7 +627,7 @@ func (ss *SqlStore) CreateColumnIfNotExists(tableName string, columnName string,
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to create column", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_COLUMN_MYSQL)
|
||||
os.Exit(ExitCreateColumnMySQL)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -635,7 +635,7 @@ func (ss *SqlStore) CreateColumnIfNotExists(tableName string, columnName string,
|
||||
} else {
|
||||
mlog.Critical("Failed to create column because of missing driver")
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_COLUMN_MISSING)
|
||||
os.Exit(ExitCreateColumnMissing)
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -651,7 +651,7 @@ func (ss *SqlStore) CreateColumnIfNotExistsNoDefault(tableName string, columnNam
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to create column", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_COLUMN_POSTGRES)
|
||||
os.Exit(ExitCreateColumnPostgres)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -661,7 +661,7 @@ func (ss *SqlStore) CreateColumnIfNotExistsNoDefault(tableName string, columnNam
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to create column", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_COLUMN_MYSQL)
|
||||
os.Exit(ExitCreateColumnMySQL)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -669,7 +669,7 @@ func (ss *SqlStore) CreateColumnIfNotExistsNoDefault(tableName string, columnNam
|
||||
} else {
|
||||
mlog.Critical("Failed to create column because of missing driver")
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_COLUMN_MISSING)
|
||||
os.Exit(ExitCreateColumnMissing)
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -684,7 +684,7 @@ func (ss *SqlStore) RemoveColumnIfExists(tableName string, columnName string) bo
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to drop column", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_REMOVE_COLUMN)
|
||||
os.Exit(ExitRemoveColumn)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -699,7 +699,7 @@ func (ss *SqlStore) RemoveTableIfExists(tableName string) bool {
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to drop table", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_REMOVE_TABLE)
|
||||
os.Exit(ExitRemoveTable)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -720,7 +720,7 @@ func (ss *SqlStore) RenameColumnIfExists(tableName string, oldColumnName string,
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to rename column", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_RENAME_COLUMN)
|
||||
os.Exit(ExitRenameColumn)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -742,7 +742,7 @@ func (ss *SqlStore) GetMaxLengthOfColumnIfExists(tableName string, columnName st
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to get max length of column", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_MAX_COLUMN)
|
||||
os.Exit(ExitMaxColumn)
|
||||
}
|
||||
|
||||
return result
|
||||
@@ -763,7 +763,7 @@ func (ss *SqlStore) AlterColumnTypeIfExists(tableName string, columnName string,
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to alter column type", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_ALTER_COLUMN)
|
||||
os.Exit(ExitAlterColumn)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -798,7 +798,7 @@ func (ss *SqlStore) AlterColumnDefaultIfExists(tableName string, columnName stri
|
||||
} else {
|
||||
mlog.Critical("Failed to alter column default because of missing driver")
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
os.Exit(ExitGenericFailure)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -812,7 +812,7 @@ func (ss *SqlStore) AlterColumnDefaultIfExists(tableName string, columnName stri
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to alter column", mlog.String("table", tableName), mlog.String("column", columnName), mlog.String("default value", defaultValue), mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
os.Exit(ExitGenericFailure)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -857,7 +857,7 @@ func (ss *SqlStore) AlterPrimaryKey(tableName string, columnNames []string) bool
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to get current primary key", mlog.String("table", tableName), mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_ALTER_PRIMARY_KEY)
|
||||
os.Exit(ExitAlterPrimaryKey)
|
||||
}
|
||||
|
||||
primaryKey := strings.Join(columnNames, ",")
|
||||
@@ -875,29 +875,29 @@ func (ss *SqlStore) AlterPrimaryKey(tableName string, columnNames []string) bool
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to alter primary key", mlog.String("table", tableName), mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_ALTER_PRIMARY_KEY)
|
||||
os.Exit(ExitAlterPrimaryKey)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (ss *SqlStore) CreateUniqueIndexIfNotExists(indexName string, tableName string, columnName string) bool {
|
||||
return ss.createIndexIfNotExists(indexName, tableName, []string{columnName}, INDEX_TYPE_DEFAULT, true)
|
||||
return ss.createIndexIfNotExists(indexName, tableName, []string{columnName}, IndexTypeDefault, true)
|
||||
}
|
||||
|
||||
func (ss *SqlStore) CreateIndexIfNotExists(indexName string, tableName string, columnName string) bool {
|
||||
return ss.createIndexIfNotExists(indexName, tableName, []string{columnName}, INDEX_TYPE_DEFAULT, false)
|
||||
return ss.createIndexIfNotExists(indexName, tableName, []string{columnName}, IndexTypeDefault, false)
|
||||
}
|
||||
|
||||
func (ss *SqlStore) CreateCompositeIndexIfNotExists(indexName string, tableName string, columnNames []string) bool {
|
||||
return ss.createIndexIfNotExists(indexName, tableName, columnNames, INDEX_TYPE_DEFAULT, false)
|
||||
return ss.createIndexIfNotExists(indexName, tableName, columnNames, IndexTypeDefault, false)
|
||||
}
|
||||
|
||||
func (ss *SqlStore) CreateUniqueCompositeIndexIfNotExists(indexName string, tableName string, columnNames []string) bool {
|
||||
return ss.createIndexIfNotExists(indexName, tableName, columnNames, INDEX_TYPE_DEFAULT, true)
|
||||
return ss.createIndexIfNotExists(indexName, tableName, columnNames, IndexTypeDefault, true)
|
||||
}
|
||||
|
||||
func (ss *SqlStore) CreateFullTextIndexIfNotExists(indexName string, tableName string, columnName string) bool {
|
||||
return ss.createIndexIfNotExists(indexName, tableName, []string{columnName}, INDEX_TYPE_FULL_TEXT, false)
|
||||
return ss.createIndexIfNotExists(indexName, tableName, []string{columnName}, IndexTypeFullText, false)
|
||||
}
|
||||
|
||||
func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, columnNames []string, indexType string, unique bool) bool {
|
||||
@@ -915,10 +915,10 @@ func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, c
|
||||
}
|
||||
|
||||
query := ""
|
||||
if indexType == INDEX_TYPE_FULL_TEXT {
|
||||
if indexType == IndexTypeFullText {
|
||||
if len(columnNames) != 1 {
|
||||
mlog.Critical("Unable to create multi column full text index")
|
||||
os.Exit(EXIT_CREATE_INDEX_POSTGRES)
|
||||
os.Exit(ExitCreateIndexPostgres)
|
||||
}
|
||||
columnName := columnNames[0]
|
||||
postgresColumnNames := convertMySQLFullTextColumnsToPostgres(columnName)
|
||||
@@ -931,7 +931,7 @@ func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, c
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to create index", mlog.Err(errExists), mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_INDEX_POSTGRES)
|
||||
os.Exit(ExitCreateIndexPostgres)
|
||||
}
|
||||
} else if ss.DriverName() == model.DATABASE_DRIVER_MYSQL {
|
||||
|
||||
@@ -939,7 +939,7 @@ func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, c
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to check index", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_INDEX_MYSQL)
|
||||
os.Exit(ExitCreateIndexMySQL)
|
||||
}
|
||||
|
||||
if count > 0 {
|
||||
@@ -947,7 +947,7 @@ func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, c
|
||||
}
|
||||
|
||||
fullTextIndex := ""
|
||||
if indexType == INDEX_TYPE_FULL_TEXT {
|
||||
if indexType == IndexTypeFullText {
|
||||
fullTextIndex = " FULLTEXT "
|
||||
}
|
||||
|
||||
@@ -955,19 +955,19 @@ func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, c
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to create index", mlog.String("table", tableName), mlog.String("index_name", indexName), mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_INDEX_FULL_MYSQL)
|
||||
os.Exit(ExitCreateIndexFullMySQL)
|
||||
}
|
||||
} else if ss.DriverName() == model.DATABASE_DRIVER_SQLITE {
|
||||
_, err := ss.GetMaster().ExecNoTimeout("CREATE INDEX IF NOT EXISTS " + indexName + " ON " + tableName + " (" + strings.Join(columnNames, ", ") + ")")
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to create index", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_INDEX_SQLITE)
|
||||
os.Exit(ExitCreateIndexSqlite)
|
||||
}
|
||||
} else {
|
||||
mlog.Critical("Failed to create index because of missing driver")
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_INDEX_MISSING)
|
||||
os.Exit(ExitCreateIndexMissing)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -986,7 +986,7 @@ func (ss *SqlStore) RemoveIndexIfExists(indexName string, tableName string) bool
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to remove index", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_REMOVE_INDEX_POSTGRES)
|
||||
os.Exit(ExitRemoveIndexPostgres)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -996,7 +996,7 @@ func (ss *SqlStore) RemoveIndexIfExists(indexName string, tableName string) bool
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to check index", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_REMOVE_INDEX_MYSQL)
|
||||
os.Exit(ExitRemoveIndexMySQL)
|
||||
}
|
||||
|
||||
if count <= 0 {
|
||||
@@ -1007,19 +1007,19 @@ func (ss *SqlStore) RemoveIndexIfExists(indexName string, tableName string) bool
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to remove index", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_REMOVE_INDEX_MYSQL)
|
||||
os.Exit(ExitRemoveIndexMySQL)
|
||||
}
|
||||
} else if ss.DriverName() == model.DATABASE_DRIVER_SQLITE {
|
||||
_, err := ss.GetMaster().ExecNoTimeout("DROP INDEX IF EXISTS " + indexName)
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to remove index", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_REMOVE_INDEX_SQLITE)
|
||||
os.Exit(ExitRemoveIndexSqlite)
|
||||
}
|
||||
} else {
|
||||
mlog.Critical("Failed to create index because of missing driver")
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_REMOVE_INDEX_MISSING)
|
||||
os.Exit(ExitRemoveIndexMissing)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -1350,11 +1350,11 @@ func IsDuplicate(err error) bool {
|
||||
var mysqlErr *mysql.MySQLError
|
||||
switch {
|
||||
case errors.As(errors.Cause(err), &pqErr):
|
||||
if pqErr.Code == PG_DUP_TABLE_ERROR_CODE {
|
||||
if pqErr.Code == PGDupTableErrorCode {
|
||||
return true
|
||||
}
|
||||
case errors.As(errors.Cause(err), &mysqlErr):
|
||||
if mysqlErr.Number == MYSQL_DUP_TABLE_ERROR_CODE {
|
||||
if mysqlErr.Number == MySQLDupTableErrorCode {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,11 +456,11 @@ func TestGetAllConns(t *testing.T) {
|
||||
|
||||
func TestIsDuplicate(t *testing.T) {
|
||||
testErrors := map[error]bool{
|
||||
&pq.Error{Code: "42P06"}: false,
|
||||
&pq.Error{Code: PG_DUP_TABLE_ERROR_CODE}: true,
|
||||
&mysql.MySQLError{Number: uint16(1000)}: false,
|
||||
&mysql.MySQLError{Number: MYSQL_DUP_TABLE_ERROR_CODE}: true,
|
||||
errors.New("Random error"): false,
|
||||
&pq.Error{Code: "42P06"}: false,
|
||||
&pq.Error{Code: PGDupTableErrorCode}: true,
|
||||
&mysql.MySQLError{Number: uint16(1000)}: false,
|
||||
&mysql.MySQLError{Number: MySQLDupTableErrorCode}: true,
|
||||
errors.New("Random error"): false,
|
||||
}
|
||||
|
||||
for err, expected := range testErrors {
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
TEAM_MEMBER_EXISTS_ERROR = "store.sql_team.save_member.exists.app_error"
|
||||
TeamMemberExistsError = "store.sql_team.save_member.exists.app_error"
|
||||
)
|
||||
|
||||
type SqlTeamStore struct {
|
||||
|
||||
@@ -19,73 +19,73 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
CURRENT_SCHEMA_VERSION = VERSION_5_31_0
|
||||
VERSION_5_32_0 = "5.32.0"
|
||||
VERSION_5_31_0 = "5.31.0"
|
||||
VERSION_5_30_0 = "5.30.0"
|
||||
VERSION_5_29_0 = "5.29.0"
|
||||
VERSION_5_28_1 = "5.28.1"
|
||||
VERSION_5_28_0 = "5.28.0"
|
||||
VERSION_5_27_0 = "5.27.0"
|
||||
VERSION_5_26_0 = "5.26.0"
|
||||
VERSION_5_25_0 = "5.25.0"
|
||||
VERSION_5_24_0 = "5.24.0"
|
||||
VERSION_5_23_0 = "5.23.0"
|
||||
VERSION_5_22_0 = "5.22.0"
|
||||
VERSION_5_21_0 = "5.21.0"
|
||||
VERSION_5_20_0 = "5.20.0"
|
||||
VERSION_5_19_0 = "5.19.0"
|
||||
VERSION_5_18_0 = "5.18.0"
|
||||
VERSION_5_17_0 = "5.17.0"
|
||||
VERSION_5_16_0 = "5.16.0"
|
||||
VERSION_5_15_0 = "5.15.0"
|
||||
VERSION_5_14_0 = "5.14.0"
|
||||
VERSION_5_13_0 = "5.13.0"
|
||||
VERSION_5_12_0 = "5.12.0"
|
||||
VERSION_5_11_0 = "5.11.0"
|
||||
VERSION_5_10_0 = "5.10.0"
|
||||
VERSION_5_9_0 = "5.9.0"
|
||||
VERSION_5_8_0 = "5.8.0"
|
||||
VERSION_5_7_0 = "5.7.0"
|
||||
VERSION_5_6_0 = "5.6.0"
|
||||
VERSION_5_5_0 = "5.5.0"
|
||||
VERSION_5_4_0 = "5.4.0"
|
||||
VERSION_5_3_0 = "5.3.0"
|
||||
VERSION_5_2_0 = "5.2.0"
|
||||
VERSION_5_1_0 = "5.1.0"
|
||||
VERSION_5_0_0 = "5.0.0"
|
||||
VERSION_4_10_0 = "4.10.0"
|
||||
VERSION_4_9_0 = "4.9.0"
|
||||
VERSION_4_8_1 = "4.8.1"
|
||||
VERSION_4_8_0 = "4.8.0"
|
||||
VERSION_4_7_2 = "4.7.2"
|
||||
VERSION_4_7_1 = "4.7.1"
|
||||
VERSION_4_7_0 = "4.7.0"
|
||||
VERSION_4_6_0 = "4.6.0"
|
||||
VERSION_4_5_0 = "4.5.0"
|
||||
VERSION_4_4_0 = "4.4.0"
|
||||
VERSION_4_3_0 = "4.3.0"
|
||||
VERSION_4_2_0 = "4.2.0"
|
||||
VERSION_4_1_0 = "4.1.0"
|
||||
VERSION_4_0_0 = "4.0.0"
|
||||
VERSION_3_10_0 = "3.10.0"
|
||||
VERSION_3_9_0 = "3.9.0"
|
||||
VERSION_3_8_0 = "3.8.0"
|
||||
VERSION_3_7_0 = "3.7.0"
|
||||
VERSION_3_6_0 = "3.6.0"
|
||||
VERSION_3_5_0 = "3.5.0"
|
||||
VERSION_3_4_0 = "3.4.0"
|
||||
VERSION_3_3_0 = "3.3.0"
|
||||
VERSION_3_2_0 = "3.2.0"
|
||||
VERSION_3_1_0 = "3.1.0"
|
||||
VERSION_3_0_0 = "3.0.0"
|
||||
OLDEST_SUPPORTED_VERSION = VERSION_3_0_0
|
||||
CurrentSchemaVersion = Version5310
|
||||
Version5320 = "5.32.0"
|
||||
Version5310 = "5.31.0"
|
||||
Version5300 = "5.30.0"
|
||||
Version5290 = "5.29.0"
|
||||
Version5281 = "5.28.1"
|
||||
Version5280 = "5.28.0"
|
||||
Version5270 = "5.27.0"
|
||||
Version5260 = "5.26.0"
|
||||
Version5250 = "5.25.0"
|
||||
Version5240 = "5.24.0"
|
||||
Version5230 = "5.23.0"
|
||||
Version5220 = "5.22.0"
|
||||
Version5210 = "5.21.0"
|
||||
Version5200 = "5.20.0"
|
||||
Version5190 = "5.19.0"
|
||||
Version5180 = "5.18.0"
|
||||
Version5170 = "5.17.0"
|
||||
Version5160 = "5.16.0"
|
||||
Version5150 = "5.15.0"
|
||||
Version5140 = "5.14.0"
|
||||
Version5130 = "5.13.0"
|
||||
Version5120 = "5.12.0"
|
||||
Version5110 = "5.11.0"
|
||||
Version5100 = "5.10.0"
|
||||
Version590 = "5.9.0"
|
||||
Version580 = "5.8.0"
|
||||
Version570 = "5.7.0"
|
||||
Version560 = "5.6.0"
|
||||
Version550 = "5.5.0"
|
||||
Version540 = "5.4.0"
|
||||
Version530 = "5.3.0"
|
||||
Version520 = "5.2.0"
|
||||
Version510 = "5.1.0"
|
||||
Version500 = "5.0.0"
|
||||
Version4100 = "4.10.0"
|
||||
Version490 = "4.9.0"
|
||||
Version481 = "4.8.1"
|
||||
Version480 = "4.8.0"
|
||||
Version472 = "4.7.2"
|
||||
Version471 = "4.7.1"
|
||||
Version470 = "4.7.0"
|
||||
Version460 = "4.6.0"
|
||||
Version450 = "4.5.0"
|
||||
Version440 = "4.4.0"
|
||||
Version430 = "4.3.0"
|
||||
Version420 = "4.2.0"
|
||||
Version410 = "4.1.0"
|
||||
Version400 = "4.0.0"
|
||||
Version3100 = "3.10.0"
|
||||
Version390 = "3.9.0"
|
||||
Version380 = "3.8.0"
|
||||
Version370 = "3.7.0"
|
||||
Version360 = "3.6.0"
|
||||
Version350 = "3.5.0"
|
||||
Version340 = "3.4.0"
|
||||
Version330 = "3.3.0"
|
||||
Version320 = "3.2.0"
|
||||
Version310 = "3.1.0"
|
||||
Version300 = "3.0.0"
|
||||
OldestSupportedVersion = Version300
|
||||
)
|
||||
|
||||
const (
|
||||
EXIT_VERSION_SAVE = 1003
|
||||
EXIT_THEME_MIGRATION = 1004
|
||||
EXIT_TEAM_INVITEID_MIGRATION_FAILED = 1006
|
||||
ExitVersionSave = 1003
|
||||
ExitThemeMigration = 1004
|
||||
ExitTeamInviteIDMigrationFailed = 1006
|
||||
)
|
||||
|
||||
// upgradeDatabase attempts to migrate the schema to the latest supported version.
|
||||
@@ -101,9 +101,9 @@ func upgradeDatabase(sqlStore *SqlStore, currentModelVersionString string) error
|
||||
Major: currentModelVersion.Major + 1,
|
||||
}
|
||||
|
||||
oldestSupportedVersion, err := semver.Parse(OLDEST_SUPPORTED_VERSION)
|
||||
oldestSupportedVersion, err := semver.Parse(OldestSupportedVersion)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to parse oldest supported version %s", OLDEST_SUPPORTED_VERSION)
|
||||
return errors.Wrapf(err, "failed to parse oldest supported version %s", OldestSupportedVersion)
|
||||
}
|
||||
|
||||
var currentSchemaVersion *semver.Version
|
||||
@@ -206,7 +206,7 @@ func saveSchemaVersion(sqlStore *SqlStore, version string) {
|
||||
if err := sqlStore.System().SaveOrUpdate(&model.System{Name: "Version", Value: version}); err != nil {
|
||||
mlog.Critical(err.Error())
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_VERSION_SAVE)
|
||||
os.Exit(ExitVersionSave)
|
||||
}
|
||||
|
||||
mlog.Warn("The database schema version has been upgraded", mlog.String("version", version))
|
||||
@@ -223,28 +223,28 @@ func shouldPerformUpgrade(sqlStore *SqlStore, currentSchemaVersion string, expec
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion31(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_0_0, VERSION_3_1_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version300, Version310) {
|
||||
sqlStore.CreateColumnIfNotExists("OutgoingWebhooks", "ContentType", "varchar(128)", "varchar(128)", "")
|
||||
saveSchemaVersion(sqlStore, VERSION_3_1_0)
|
||||
saveSchemaVersion(sqlStore, Version310)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion32(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_1_0, VERSION_3_2_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version310, Version320) {
|
||||
sqlStore.CreateColumnIfNotExists("TeamMembers", "DeleteAt", "bigint(20)", "bigint", "0")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_3_2_0)
|
||||
saveSchemaVersion(sqlStore, Version320)
|
||||
}
|
||||
}
|
||||
|
||||
func themeMigrationFailed(err error) {
|
||||
mlog.Critical("Failed to migrate User.ThemeProps to Preferences table", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_THEME_MIGRATION)
|
||||
os.Exit(ExitThemeMigration)
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion33(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_2_0, VERSION_3_3_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version320, Version330) {
|
||||
if sqlStore.DoesColumnExist("Users", "ThemeProps") {
|
||||
params := map[string]interface{}{
|
||||
"Category": model.PREFERENCE_CATEGORY_THEME,
|
||||
@@ -322,21 +322,21 @@ func upgradeDatabaseToVersion33(sqlStore *SqlStore) {
|
||||
|
||||
sqlStore.CreateColumnIfNotExists("OutgoingWebhooks", "TriggerWhen", "tinyint", "integer", "0")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_3_3_0)
|
||||
saveSchemaVersion(sqlStore, Version330)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion34(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_3_0, VERSION_3_4_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version330, Version340) {
|
||||
sqlStore.CreateColumnIfNotExists("Status", "Manual", "BOOLEAN", "BOOLEAN", "0")
|
||||
sqlStore.CreateColumnIfNotExists("Status", "ActiveChannel", "varchar(26)", "varchar(26)", "")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_3_4_0)
|
||||
saveSchemaVersion(sqlStore, Version340)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion35(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_4_0, VERSION_3_5_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version340, Version350) {
|
||||
sqlStore.GetMaster().Exec("UPDATE Users SET Roles = 'system_user' WHERE Roles = ''")
|
||||
sqlStore.GetMaster().Exec("UPDATE Users SET Roles = 'system_user system_admin' WHERE Roles = 'system_admin'")
|
||||
sqlStore.GetMaster().Exec("UPDATE TeamMembers SET Roles = 'team_user' WHERE Roles = ''")
|
||||
@@ -354,12 +354,12 @@ func upgradeDatabaseToVersion35(sqlStore *SqlStore) {
|
||||
|
||||
sqlStore.Session().RemoveAllSessions()
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_3_5_0)
|
||||
saveSchemaVersion(sqlStore, Version350)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion36(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_5_0, VERSION_3_6_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version350, Version360) {
|
||||
sqlStore.CreateColumnIfNotExists("Posts", "HasReactions", "tinyint", "boolean", "0")
|
||||
|
||||
// Create Team Description column
|
||||
@@ -371,51 +371,51 @@ func upgradeDatabaseToVersion36(sqlStore *SqlStore) {
|
||||
// Remove ActiveChannel column from Status
|
||||
sqlStore.RemoveColumnIfExists("Status", "ActiveChannel")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_3_6_0)
|
||||
saveSchemaVersion(sqlStore, Version360)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion37(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_6_0, VERSION_3_7_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version360, Version370) {
|
||||
// Add EditAt column to Posts
|
||||
sqlStore.CreateColumnIfNotExists("Posts", "EditAt", " bigint", " bigint", "0")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_3_7_0)
|
||||
saveSchemaVersion(sqlStore, Version370)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion38(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_7_0, VERSION_3_8_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version370, Version380) {
|
||||
// Add the IsPinned column to posts.
|
||||
sqlStore.CreateColumnIfNotExists("Posts", "IsPinned", "boolean", "boolean", "0")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_3_8_0)
|
||||
saveSchemaVersion(sqlStore, Version380)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion39(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_8_0, VERSION_3_9_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version380, Version390) {
|
||||
sqlStore.CreateColumnIfNotExists("OAuthAccessData", "Scope", "varchar(128)", "varchar(128)", model.DEFAULT_SCOPE)
|
||||
sqlStore.RemoveTableIfExists("PasswordRecovery")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_3_9_0)
|
||||
saveSchemaVersion(sqlStore, Version390)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion310(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_9_0, VERSION_3_10_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_3_10_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version390, Version3100) {
|
||||
saveSchemaVersion(sqlStore, Version3100)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion40(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_10_0, VERSION_4_0_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_4_0_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version3100, Version400) {
|
||||
saveSchemaVersion(sqlStore, Version400)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion41(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_0_0, VERSION_4_1_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version400, Version410) {
|
||||
// Increase maximum length of the Users table Roles column.
|
||||
if sqlStore.GetMaxLengthOfColumnIfExists("Users", "Roles") != "256" {
|
||||
sqlStore.AlterColumnTypeIfExists("Users", "Roles", "varchar(256)", "varchar(256)")
|
||||
@@ -423,52 +423,52 @@ func upgradeDatabaseToVersion41(sqlStore *SqlStore) {
|
||||
|
||||
sqlStore.RemoveTableIfExists("JobStatuses")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_4_1_0)
|
||||
saveSchemaVersion(sqlStore, Version410)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion42(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_1_0, VERSION_4_2_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_4_2_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version410, Version420) {
|
||||
saveSchemaVersion(sqlStore, Version420)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion43(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_2_0, VERSION_4_3_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_4_3_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version420, Version430) {
|
||||
saveSchemaVersion(sqlStore, Version430)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion44(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_3_0, VERSION_4_4_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version430, Version440) {
|
||||
// Add the IsActive column to UserAccessToken.
|
||||
sqlStore.CreateColumnIfNotExists("UserAccessTokens", "IsActive", "boolean", "boolean", "1")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_4_4_0)
|
||||
saveSchemaVersion(sqlStore, Version440)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion45(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_4_0, VERSION_4_5_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_4_5_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version440, Version450) {
|
||||
saveSchemaVersion(sqlStore, Version450)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion46(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_5_0, VERSION_4_6_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version450, Version460) {
|
||||
sqlStore.CreateColumnIfNotExists("IncomingWebhooks", "Username", "varchar(64)", "varchar(64)", "")
|
||||
sqlStore.CreateColumnIfNotExists("IncomingWebhooks", "IconURL", "varchar(1024)", "varchar(1024)", "")
|
||||
saveSchemaVersion(sqlStore, VERSION_4_6_0)
|
||||
saveSchemaVersion(sqlStore, Version460)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion47(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_6_0, VERSION_4_7_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version460, Version470) {
|
||||
sqlStore.AlterColumnTypeIfExists("Users", "Position", "varchar(128)", "varchar(128)")
|
||||
sqlStore.AlterColumnTypeIfExists("OAuthAuthData", "State", "varchar(1024)", "varchar(1024)")
|
||||
sqlStore.RemoveColumnIfExists("ChannelMemberHistory", "Email")
|
||||
sqlStore.RemoveColumnIfExists("ChannelMemberHistory", "Username")
|
||||
saveSchemaVersion(sqlStore, VERSION_4_7_0)
|
||||
saveSchemaVersion(sqlStore, Version470)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -476,29 +476,29 @@ func upgradeDatabaseToVersion471(sqlStore *SqlStore) {
|
||||
// If any new instances started with 4.7, they would have the bad Email column on the
|
||||
// ChannelMemberHistory table. So for those cases we need to do an upgrade between
|
||||
// 4.7.0 and 4.7.1
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_7_0, VERSION_4_7_1) {
|
||||
if shouldPerformUpgrade(sqlStore, Version470, Version471) {
|
||||
sqlStore.RemoveColumnIfExists("ChannelMemberHistory", "Email")
|
||||
saveSchemaVersion(sqlStore, VERSION_4_7_1)
|
||||
saveSchemaVersion(sqlStore, Version471)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion472(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_7_1, VERSION_4_7_2) {
|
||||
if shouldPerformUpgrade(sqlStore, Version471, Version472) {
|
||||
sqlStore.RemoveIndexIfExists("idx_channels_displayname", "Channels")
|
||||
saveSchemaVersion(sqlStore, VERSION_4_7_2)
|
||||
saveSchemaVersion(sqlStore, Version472)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion48(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_7_2, VERSION_4_8_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_4_8_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version472, Version480) {
|
||||
saveSchemaVersion(sqlStore, Version480)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion481(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_8_0, VERSION_4_8_1) {
|
||||
if shouldPerformUpgrade(sqlStore, Version480, Version481) {
|
||||
sqlStore.RemoveIndexIfExists("idx_channels_displayname", "Channels")
|
||||
saveSchemaVersion(sqlStore, VERSION_4_8_1)
|
||||
saveSchemaVersion(sqlStore, Version481)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,7 +507,7 @@ func upgradeDatabaseToVersion49(sqlStore *SqlStore) {
|
||||
// a number of parameters in `config.json` to a `Roles` table in the database. The migration code can be seen
|
||||
// in the file `app/app.go` in the function `DoAdvancedPermissionsMigration()`.
|
||||
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_8_1, VERSION_4_9_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version481, Version490) {
|
||||
sqlStore.CreateColumnIfNotExists("Teams", "LastTeamIconUpdate", "bigint", "bigint", "0")
|
||||
defaultTimezone := timezones.DefaultUserTimezone()
|
||||
defaultTimezoneValue, err := json.Marshal(defaultTimezone)
|
||||
@@ -516,18 +516,18 @@ func upgradeDatabaseToVersion49(sqlStore *SqlStore) {
|
||||
}
|
||||
sqlStore.CreateColumnIfNotExists("Users", "Timezone", "varchar(256)", "varchar(256)", string(defaultTimezoneValue))
|
||||
sqlStore.RemoveIndexIfExists("idx_channels_displayname", "Channels")
|
||||
saveSchemaVersion(sqlStore, VERSION_4_9_0)
|
||||
saveSchemaVersion(sqlStore, Version490)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion410(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_9_0, VERSION_4_10_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version490, Version4100) {
|
||||
|
||||
sqlStore.RemoveIndexIfExists("Name_2", "Channels")
|
||||
sqlStore.RemoveIndexIfExists("Name_2", "Emoji")
|
||||
sqlStore.RemoveIndexIfExists("ClientId_2", "OAuthAccessData")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_4_10_0)
|
||||
saveSchemaVersion(sqlStore, Version4100)
|
||||
sqlStore.GetMaster().Exec("UPDATE Users SET AuthData=LOWER(AuthData) WHERE AuthService = 'saml'")
|
||||
}
|
||||
}
|
||||
@@ -550,7 +550,7 @@ func upgradeDatabaseToVersion50(sqlStore *SqlStore) {
|
||||
// UPDATE ChannelMembers SET Roles = CONCAT(Roles, ' channel_admin'), SchemeAdmin = NULL where SchemeAdmin = 1;
|
||||
// DELETE from Systems WHERE Name = 'migration_advanced_permissions_phase_2';
|
||||
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_10_0, VERSION_5_0_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version4100, Version500) {
|
||||
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("Teams", "SchemeId", "varchar(26)", "varchar(26)")
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("Channels", "SchemeId", "varchar(26)", "varchar(26)")
|
||||
@@ -567,51 +567,51 @@ func upgradeDatabaseToVersion50(sqlStore *SqlStore) {
|
||||
|
||||
sqlStore.RemoveIndexIfExists("idx_channels_txt", "Channels")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_0_0)
|
||||
saveSchemaVersion(sqlStore, Version500)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion51(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_0_0, VERSION_5_1_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_1_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version500, Version510) {
|
||||
saveSchemaVersion(sqlStore, Version510)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion52(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_1_0, VERSION_5_2_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version510, Version520) {
|
||||
sqlStore.CreateColumnIfNotExists("OutgoingWebhooks", "Username", "varchar(64)", "varchar(64)", "")
|
||||
sqlStore.CreateColumnIfNotExists("OutgoingWebhooks", "IconURL", "varchar(1024)", "varchar(1024)", "")
|
||||
saveSchemaVersion(sqlStore, VERSION_5_2_0)
|
||||
saveSchemaVersion(sqlStore, Version520)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion53(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_2_0, VERSION_5_3_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_3_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version520, Version530) {
|
||||
saveSchemaVersion(sqlStore, Version530)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion54(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_3_0, VERSION_5_4_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version530, Version540) {
|
||||
sqlStore.AlterColumnTypeIfExists("OutgoingWebhooks", "Description", "varchar(500)", "varchar(500)")
|
||||
sqlStore.AlterColumnTypeIfExists("IncomingWebhooks", "Description", "varchar(500)", "varchar(500)")
|
||||
if err := sqlStore.Channel().MigratePublicChannels(); err != nil {
|
||||
mlog.Critical("Failed to migrate PublicChannels table", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
os.Exit(ExitGenericFailure)
|
||||
}
|
||||
saveSchemaVersion(sqlStore, VERSION_5_4_0)
|
||||
saveSchemaVersion(sqlStore, Version540)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion55(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_4_0, VERSION_5_5_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_5_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version540, Version550) {
|
||||
saveSchemaVersion(sqlStore, Version550)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion56(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_5_0, VERSION_5_6_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version550, Version560) {
|
||||
sqlStore.CreateColumnIfNotExists("PluginKeyValueStore", "ExpireAt", "bigint(20)", "bigint", "0")
|
||||
|
||||
// migrating user's accepted terms of service data into the new table
|
||||
@@ -625,19 +625,19 @@ func upgradeDatabaseToVersion56(sqlStore *SqlStore) {
|
||||
sqlStore.RemoveIndexIfExists("idx_users_lastname_lower", "lower(LastName)")
|
||||
}
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_6_0)
|
||||
saveSchemaVersion(sqlStore, Version560)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion57(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_6_0, VERSION_5_7_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_7_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version560, Version570) {
|
||||
saveSchemaVersion(sqlStore, Version570)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion58(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_7_0, VERSION_5_8_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version570, Version580) {
|
||||
// idx_channels_txt was removed in `upgradeDatabaseToVersion50`, but merged as part of
|
||||
// v5.1, so the migration wouldn't apply to anyone upgrading from v5.0. Remove it again to
|
||||
// bring the upgraded (from v5.0) and fresh install schemas back in sync.
|
||||
@@ -652,30 +652,30 @@ func upgradeDatabaseToVersion58(sqlStore *SqlStore) {
|
||||
sqlStore.AlterColumnDefaultIfExists("OutgoingWebhooks", "IconURL", nil, model.NewString(""))
|
||||
sqlStore.AlterColumnDefaultIfExists("PluginKeyValueStore", "ExpireAt", model.NewString("NULL"), model.NewString("NULL"))
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_8_0)
|
||||
saveSchemaVersion(sqlStore, Version580)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion59(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_8_0, VERSION_5_9_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_9_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version580, Version590) {
|
||||
saveSchemaVersion(sqlStore, Version590)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion510(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_9_0, VERSION_5_10_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version590, Version5100) {
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("Channels", "GroupConstrained", "tinyint(4)", "boolean")
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("Teams", "GroupConstrained", "tinyint(4)", "boolean")
|
||||
|
||||
sqlStore.CreateIndexIfNotExists("idx_groupteams_teamid", "GroupTeams", "TeamId")
|
||||
sqlStore.CreateIndexIfNotExists("idx_groupchannels_channelid", "GroupChannels", "ChannelId")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_10_0)
|
||||
saveSchemaVersion(sqlStore, Version5100)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion511(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_10_0, VERSION_5_11_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5100, Version5110) {
|
||||
// Enforce all teams have an InviteID set
|
||||
var teams []*model.Team
|
||||
if _, err := sqlStore.GetReplica().Select(&teams, "SELECT * FROM Teams WHERE InviteId = ''"); err != nil {
|
||||
@@ -689,12 +689,12 @@ func upgradeDatabaseToVersion511(sqlStore *SqlStore) {
|
||||
}
|
||||
}
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_11_0)
|
||||
saveSchemaVersion(sqlStore, Version5110)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion512(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_11_0, VERSION_5_12_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5110, Version5120) {
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("TeamMembers", "SchemeGuest", "boolean", "boolean")
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("ChannelMembers", "SchemeGuest", "boolean", "boolean")
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("Schemes", "DefaultTeamGuestRole", "text", "VARCHAR(64)")
|
||||
@@ -705,39 +705,39 @@ func upgradeDatabaseToVersion512(sqlStore *SqlStore) {
|
||||
// Saturday, January 24, 2065 5:20:00 AM GMT. To remove all personal access token sessions.
|
||||
sqlStore.GetMaster().Exec("DELETE FROM Sessions WHERE ExpiresAt > 3000000000000")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_12_0)
|
||||
saveSchemaVersion(sqlStore, Version5120)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion513(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_12_0, VERSION_5_13_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5120, Version5130) {
|
||||
// The previous jobs ran once per minute, cluttering the Jobs table with somewhat useless entries. Clean that up.
|
||||
sqlStore.GetMaster().Exec("DELETE FROM Jobs WHERE Type = 'plugins'")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_13_0)
|
||||
saveSchemaVersion(sqlStore, Version5130)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion514(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_13_0, VERSION_5_14_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_14_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version5130, Version5140) {
|
||||
saveSchemaVersion(sqlStore, Version5140)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion515(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_14_0, VERSION_5_15_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_15_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version5140, Version5150) {
|
||||
saveSchemaVersion(sqlStore, Version5150)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion516(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_15_0, VERSION_5_16_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5150, Version5160) {
|
||||
if sqlStore.DriverName() == model.DATABASE_DRIVER_POSTGRES {
|
||||
sqlStore.GetMaster().Exec("ALTER TABLE Tokens ALTER COLUMN Extra TYPE varchar(2048)")
|
||||
} else if sqlStore.DriverName() == model.DATABASE_DRIVER_MYSQL {
|
||||
sqlStore.GetMaster().Exec("ALTER TABLE Tokens MODIFY Extra text")
|
||||
}
|
||||
saveSchemaVersion(sqlStore, VERSION_5_16_0)
|
||||
saveSchemaVersion(sqlStore, Version5160)
|
||||
|
||||
// Fix mismatches between the canonical and migrated schemas.
|
||||
sqlStore.AlterColumnTypeIfExists("TeamMembers", "SchemeGuest", "tinyint(4)", "boolean")
|
||||
@@ -758,25 +758,25 @@ func upgradeDatabaseToVersion516(sqlStore *SqlStore) {
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion517(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_16_0, VERSION_5_17_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_17_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version5160, Version5170) {
|
||||
saveSchemaVersion(sqlStore, Version5170)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion518(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_17_0, VERSION_5_18_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_18_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version5170, Version5180) {
|
||||
saveSchemaVersion(sqlStore, Version5180)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion519(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_18_0, VERSION_5_19_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_19_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version5180, Version5190) {
|
||||
saveSchemaVersion(sqlStore, Version5190)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion520(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_19_0, VERSION_5_20_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5190, Version5200) {
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("Bots", "LastIconUpdate", "bigint", "bigint")
|
||||
|
||||
sqlStore.CreateColumnIfNotExists("GroupTeams", "SchemeAdmin", "boolean", "boolean", "0")
|
||||
@@ -785,18 +785,18 @@ func upgradeDatabaseToVersion520(sqlStore *SqlStore) {
|
||||
sqlStore.CreateColumnIfNotExists("GroupChannels", "SchemeAdmin", "boolean", "boolean", "0")
|
||||
sqlStore.CreateIndexIfNotExists("idx_groupchannels_schemeadmin", "GroupChannels", "SchemeAdmin")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_20_0)
|
||||
saveSchemaVersion(sqlStore, Version5200)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion521(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_20_0, VERSION_5_21_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_21_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version5200, Version5210) {
|
||||
saveSchemaVersion(sqlStore, Version5210)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion522(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_21_0, VERSION_5_22_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5210, Version5220) {
|
||||
sqlStore.CreateIndexIfNotExists("idx_teams_scheme_id", "Teams", "SchemeId")
|
||||
sqlStore.CreateIndexIfNotExists("idx_channels_scheme_id", "Channels", "SchemeId")
|
||||
sqlStore.CreateIndexIfNotExists("idx_channels_scheme_id", "Channels", "SchemeId")
|
||||
@@ -804,51 +804,51 @@ func upgradeDatabaseToVersion522(sqlStore *SqlStore) {
|
||||
sqlStore.CreateIndexIfNotExists("idx_schemes_channel_user_role", "Schemes", "DefaultChannelUserRole")
|
||||
sqlStore.CreateIndexIfNotExists("idx_schemes_channel_admin_role", "Schemes", "DefaultChannelAdminRole")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_22_0)
|
||||
saveSchemaVersion(sqlStore, Version5220)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion523(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_22_0, VERSION_5_23_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_23_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version5220, Version5230) {
|
||||
saveSchemaVersion(sqlStore, Version5230)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion524(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_23_0, VERSION_5_24_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5230, Version5240) {
|
||||
sqlStore.CreateColumnIfNotExists("UserGroups", "AllowReference", "boolean", "boolean", "0")
|
||||
sqlStore.GetMaster().Exec("UPDATE UserGroups SET Name = null, AllowReference = false")
|
||||
sqlStore.AlterPrimaryKey("Reactions", []string{"PostId", "UserId", "EmojiName"})
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_24_0)
|
||||
saveSchemaVersion(sqlStore, Version5240)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion525(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_24_0, VERSION_5_25_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_25_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version5240, Version5250) {
|
||||
saveSchemaVersion(sqlStore, Version5250)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion526(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_25_0, VERSION_5_26_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5250, Version5260) {
|
||||
sqlStore.CreateColumnIfNotExists("Sessions", "ExpiredNotify", "boolean", "boolean", "0")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_26_0)
|
||||
saveSchemaVersion(sqlStore, Version5260)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion527(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_26_0, VERSION_5_27_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_27_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version5260, Version5270) {
|
||||
saveSchemaVersion(sqlStore, Version5270)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion528(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_27_0, VERSION_5_28_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5270, Version5280) {
|
||||
if err := precheckMigrationToVersion528(sqlStore); err != nil {
|
||||
mlog.Critical("Error upgrading DB schema to 5.28.0", mlog.Err(err))
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
os.Exit(ExitGenericFailure)
|
||||
}
|
||||
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("Commands", "PluginId", "VARCHAR(190)", "VARCHAR(190)")
|
||||
@@ -859,15 +859,15 @@ func upgradeDatabaseToVersion528(sqlStore *SqlStore) {
|
||||
sqlStore.AlterColumnTypeIfExists("IncomingWebhooks", "Username", "varchar(255)", "varchar(255)")
|
||||
sqlStore.AlterColumnTypeIfExists("IncomingWebhooks", "IconURL", "text", "varchar(1024)")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_28_0)
|
||||
saveSchemaVersion(sqlStore, Version5280)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion5281(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_28_0, VERSION_5_28_1) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5280, Version5281) {
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("FileInfo", "MiniPreview", "MEDIUMBLOB", "bytea")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_28_1)
|
||||
saveSchemaVersion(sqlStore, Version5281)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -925,7 +925,7 @@ func precheckMigrationToVersion528(sqlStore *SqlStore) error {
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion529(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_28_1, VERSION_5_29_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5281, Version5290) {
|
||||
sqlStore.AlterColumnTypeIfExists("SidebarCategories", "Id", "VARCHAR(128)", "VARCHAR(128)")
|
||||
sqlStore.AlterColumnDefaultIfExists("SidebarCategories", "Id", model.NewString(""), nil)
|
||||
sqlStore.AlterColumnTypeIfExists("SidebarChannels", "CategoryId", "VARCHAR(128)", "VARCHAR(128)")
|
||||
@@ -941,30 +941,30 @@ func upgradeDatabaseToVersion529(sqlStore *SqlStore) {
|
||||
mlog.Error("Error updating ChannelId in Threads table", mlog.Err(err))
|
||||
}
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_29_0)
|
||||
saveSchemaVersion(sqlStore, Version5290)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion530(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_29_0, VERSION_5_30_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5290, Version5300) {
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("FileInfo", "Content", "longtext", "text")
|
||||
|
||||
sqlStore.CreateColumnIfNotExists("SidebarCategories", "Muted", "tinyint(1)", "boolean", "0")
|
||||
saveSchemaVersion(sqlStore, VERSION_5_30_0)
|
||||
saveSchemaVersion(sqlStore, Version5300)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion531(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_30_0, VERSION_5_31_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_31_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version5300, Version5310) {
|
||||
saveSchemaVersion(sqlStore, Version5310)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion532(sqlStore *SqlStore) {
|
||||
// if shouldPerformUpgrade(sqlStore, VERSION_5_31_0, VERSION_5_32_0) {
|
||||
// if shouldPerformUpgrade(sqlStore, Version5310, Version5320) {
|
||||
// allow 10 files per post
|
||||
sqlStore.AlterColumnTypeIfExists("Posts", "FileIds", "text", "varchar(300)")
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("Channels", "Shared", "tinyint(1)", "boolean")
|
||||
// saveSchemaVersion(sqlStore, VERSION_5_32_0)
|
||||
// saveSchemaVersion(sqlStore, Version5320)
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -34,26 +34,26 @@ func TestStoreUpgrade(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("upgrade from earliest supported version", func(t *testing.T) {
|
||||
saveSchemaVersion(sqlStore, VERSION_3_0_0)
|
||||
err := upgradeDatabase(sqlStore, CURRENT_SCHEMA_VERSION)
|
||||
saveSchemaVersion(sqlStore, Version300)
|
||||
err := upgradeDatabase(sqlStore, CurrentSchemaVersion)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CURRENT_SCHEMA_VERSION, sqlStore.GetCurrentSchemaVersion())
|
||||
require.Equal(t, CurrentSchemaVersion, sqlStore.GetCurrentSchemaVersion())
|
||||
})
|
||||
|
||||
t.Run("upgrade from no existing version", func(t *testing.T) {
|
||||
saveSchemaVersion(sqlStore, "")
|
||||
err := upgradeDatabase(sqlStore, CURRENT_SCHEMA_VERSION)
|
||||
err := upgradeDatabase(sqlStore, CurrentSchemaVersion)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CURRENT_SCHEMA_VERSION, sqlStore.GetCurrentSchemaVersion())
|
||||
require.Equal(t, CurrentSchemaVersion, sqlStore.GetCurrentSchemaVersion())
|
||||
})
|
||||
|
||||
t.Run("upgrade schema running earlier minor version", func(t *testing.T) {
|
||||
saveSchemaVersion(sqlStore, "5.1.0")
|
||||
err := upgradeDatabase(sqlStore, "5.8.0")
|
||||
require.NoError(t, err)
|
||||
// Assert CURRENT_SCHEMA_VERSION, not 5.8.0, since the migrations will move
|
||||
// Assert CurrentSchemaVersion, not 5.8.0, since the migrations will move
|
||||
// past 5.8.0 regardless of the input parameter.
|
||||
require.Equal(t, CURRENT_SCHEMA_VERSION, sqlStore.GetCurrentSchemaVersion())
|
||||
require.Equal(t, CurrentSchemaVersion, sqlStore.GetCurrentSchemaVersion())
|
||||
})
|
||||
|
||||
t.Run("upgrade schema running later minor version", func(t *testing.T) {
|
||||
@@ -65,9 +65,9 @@ func TestStoreUpgrade(t *testing.T) {
|
||||
|
||||
t.Run("upgrade schema running earlier major version", func(t *testing.T) {
|
||||
saveSchemaVersion(sqlStore, "4.1.0")
|
||||
err := upgradeDatabase(sqlStore, CURRENT_SCHEMA_VERSION)
|
||||
err := upgradeDatabase(sqlStore, CurrentSchemaVersion)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CURRENT_SCHEMA_VERSION, sqlStore.GetCurrentSchemaVersion())
|
||||
require.Equal(t, CurrentSchemaVersion, sqlStore.GetCurrentSchemaVersion())
|
||||
})
|
||||
|
||||
t.Run("upgrade schema running later major version", func(t *testing.T) {
|
||||
@@ -84,21 +84,21 @@ func TestSaveSchemaVersion(t *testing.T) {
|
||||
sqlStore := ss.(*SqlStore)
|
||||
|
||||
t.Run("set earliest version", func(t *testing.T) {
|
||||
saveSchemaVersion(sqlStore, VERSION_3_0_0)
|
||||
saveSchemaVersion(sqlStore, Version300)
|
||||
props, err := ss.System().Get()
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Equal(t, VERSION_3_0_0, props["Version"])
|
||||
require.Equal(t, VERSION_3_0_0, sqlStore.GetCurrentSchemaVersion())
|
||||
require.Equal(t, Version300, props["Version"])
|
||||
require.Equal(t, Version300, sqlStore.GetCurrentSchemaVersion())
|
||||
})
|
||||
|
||||
t.Run("set current version", func(t *testing.T) {
|
||||
saveSchemaVersion(sqlStore, CURRENT_SCHEMA_VERSION)
|
||||
saveSchemaVersion(sqlStore, CurrentSchemaVersion)
|
||||
props, err := ss.System().Get()
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Equal(t, CURRENT_SCHEMA_VERSION, props["Version"])
|
||||
require.Equal(t, CURRENT_SCHEMA_VERSION, sqlStore.GetCurrentSchemaVersion())
|
||||
require.Equal(t, CurrentSchemaVersion, props["Version"])
|
||||
require.Equal(t, CurrentSchemaVersion, sqlStore.GetCurrentSchemaVersion())
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -20,14 +20,14 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
MAX_GROUP_CHANNELS_FOR_PROFILES = 50
|
||||
MaxGroupChannelsForProfiles = 50
|
||||
)
|
||||
|
||||
var (
|
||||
USER_SEARCH_TYPE_NAMES_NO_FULL_NAME = []string{"Username", "Nickname"}
|
||||
USER_SEARCH_TYPE_NAMES = []string{"Username", "FirstName", "LastName", "Nickname"}
|
||||
USER_SEARCH_TYPE_ALL_NO_FULL_NAME = []string{"Username", "Nickname", "Email"}
|
||||
USER_SEARCH_TYPE_ALL = []string{"Username", "FirstName", "LastName", "Nickname", "Email"}
|
||||
UserSearchTypeNames_NO_FULL_NAME = []string{"Username", "Nickname"}
|
||||
UserSearchTypeNames = []string{"Username", "FirstName", "LastName", "Nickname"}
|
||||
UserSearchTypeAll_NO_FULL_NAME = []string{"Username", "Nickname", "Email"}
|
||||
UserSearchTypeAll = []string{"Username", "FirstName", "LastName", "Nickname", "Email"}
|
||||
)
|
||||
|
||||
type SqlUserStore struct {
|
||||
@@ -92,10 +92,10 @@ func (us SqlUserStore) createIndexesIfNotExists() {
|
||||
us.CreateIndexIfNotExists("idx_users_lastname_lower_textpattern", "Users", "lower(LastName) text_pattern_ops")
|
||||
}
|
||||
|
||||
us.CreateFullTextIndexIfNotExists("idx_users_all_txt", "Users", strings.Join(USER_SEARCH_TYPE_ALL, ", "))
|
||||
us.CreateFullTextIndexIfNotExists("idx_users_all_no_full_name_txt", "Users", strings.Join(USER_SEARCH_TYPE_ALL_NO_FULL_NAME, ", "))
|
||||
us.CreateFullTextIndexIfNotExists("idx_users_names_txt", "Users", strings.Join(USER_SEARCH_TYPE_NAMES, ", "))
|
||||
us.CreateFullTextIndexIfNotExists("idx_users_names_no_full_name_txt", "Users", strings.Join(USER_SEARCH_TYPE_NAMES_NO_FULL_NAME, ", "))
|
||||
us.CreateFullTextIndexIfNotExists("idx_users_all_txt", "Users", strings.Join(UserSearchTypeAll, ", "))
|
||||
us.CreateFullTextIndexIfNotExists("idx_users_all_no_full_name_txt", "Users", strings.Join(UserSearchTypeAll_NO_FULL_NAME, ", "))
|
||||
us.CreateFullTextIndexIfNotExists("idx_users_names_txt", "Users", strings.Join(UserSearchTypeNames, ", "))
|
||||
us.CreateFullTextIndexIfNotExists("idx_users_names_no_full_name_txt", "Users", strings.Join(UserSearchTypeNames_NO_FULL_NAME, ", "))
|
||||
}
|
||||
|
||||
func (us SqlUserStore) Save(user *model.User) (*model.User, error) {
|
||||
@@ -936,8 +936,8 @@ type UserWithChannel struct {
|
||||
}
|
||||
|
||||
func (us SqlUserStore) GetProfileByGroupChannelIdsForUser(userId string, channelIds []string) (map[string][]*model.User, error) {
|
||||
if len(channelIds) > MAX_GROUP_CHANNELS_FOR_PROFILES {
|
||||
channelIds = channelIds[0:MAX_GROUP_CHANNELS_FOR_PROFILES]
|
||||
if len(channelIds) > MaxGroupChannelsForProfiles {
|
||||
channelIds = channelIds[0:MaxGroupChannelsForProfiles]
|
||||
}
|
||||
|
||||
isMemberQuery := fmt.Sprintf(`
|
||||
@@ -1402,15 +1402,15 @@ func (us SqlUserStore) performSearch(query sq.SelectBuilder, term string, option
|
||||
var searchType []string
|
||||
if options.AllowEmails {
|
||||
if options.AllowFullNames {
|
||||
searchType = USER_SEARCH_TYPE_ALL
|
||||
searchType = UserSearchTypeAll
|
||||
} else {
|
||||
searchType = USER_SEARCH_TYPE_ALL_NO_FULL_NAME
|
||||
searchType = UserSearchTypeAll_NO_FULL_NAME
|
||||
}
|
||||
} else {
|
||||
if options.AllowFullNames {
|
||||
searchType = USER_SEARCH_TYPE_NAMES
|
||||
searchType = UserSearchTypeNames
|
||||
} else {
|
||||
searchType = USER_SEARCH_TYPE_NAMES_NO_FULL_NAME
|
||||
searchType = UserSearchTypeNames_NO_FULL_NAME
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user