Этот коммит содержится в:
Claudio Costa
2021-06-08 18:08:43 +02:00
коммит произвёл GitHub
родитель fb452d8565
Коммит ff745fcff7
21 изменённых файлов: 60 добавлений и 32 удалений

Просмотреть файл

@@ -421,7 +421,6 @@ func newSqlChannelStore(sqlStore *SqlStore, metrics einterfaces.MetricsInterface
func (s SqlChannelStore) createIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_channels_team_id", "Channels", "TeamId")
s.CreateIndexIfNotExists("idx_channels_name", "Channels", "Name")
s.CreateIndexIfNotExists("idx_channels_update_at", "Channels", "UpdateAt")
s.CreateIndexIfNotExists("idx_channels_create_at", "Channels", "CreateAt")
s.CreateIndexIfNotExists("idx_channels_delete_at", "Channels", "DeleteAt")
@@ -431,13 +430,11 @@ func (s SqlChannelStore) createIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_channels_displayname_lower", "Channels", "lower(DisplayName)")
}
s.CreateIndexIfNotExists("idx_channelmembers_channel_id", "ChannelMembers", "ChannelId")
s.CreateIndexIfNotExists("idx_channelmembers_user_id", "ChannelMembers", "UserId")
s.CreateFullTextIndexIfNotExists("idx_channel_search_txt", "Channels", "Name, DisplayName, Purpose")
s.CreateIndexIfNotExists("idx_publicchannels_team_id", "PublicChannels", "TeamId")
s.CreateIndexIfNotExists("idx_publicchannels_name", "PublicChannels", "Name")
s.CreateIndexIfNotExists("idx_publicchannels_delete_at", "PublicChannels", "DeleteAt")
if s.DriverName() == model.DATABASE_DRIVER_POSTGRES {
s.CreateIndexIfNotExists("idx_publicchannels_name_lower", "PublicChannels", "lower(Name)")

Просмотреть файл

@@ -42,7 +42,6 @@ func (es SqlEmojiStore) createIndexesIfNotExists() {
es.CreateIndexIfNotExists("idx_emoji_update_at", "Emoji", "UpdateAt")
es.CreateIndexIfNotExists("idx_emoji_create_at", "Emoji", "CreateAt")
es.CreateIndexIfNotExists("idx_emoji_delete_at", "Emoji", "DeleteAt")
es.CreateIndexIfNotExists("idx_emoji_name", "Emoji", "Name")
}
func (es SqlEmojiStore) Save(emoji *model.Emoji) (*model.Emoji, error) {

Просмотреть файл

@@ -55,10 +55,8 @@ func newSqlOAuthStore(sqlStore *SqlStore) store.OAuthStore {
func (as SqlOAuthStore) createIndexesIfNotExists() {
as.CreateIndexIfNotExists("idx_oauthapps_creator_id", "OAuthApps", "CreatorId")
as.CreateIndexIfNotExists("idx_oauthaccessdata_client_id", "OAuthAccessData", "ClientId")
as.CreateIndexIfNotExists("idx_oauthaccessdata_user_id", "OAuthAccessData", "UserId")
as.CreateIndexIfNotExists("idx_oauthaccessdata_refresh_token", "OAuthAccessData", "RefreshToken")
as.CreateIndexIfNotExists("idx_oauthauthdata_client_id", "OAuthAuthData", "Code")
}
func (as SqlOAuthStore) SaveApp(app *model.OAuthApp) (*model.OAuthApp, error) {

Просмотреть файл

@@ -101,7 +101,6 @@ func (s *SqlPostStore) createIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_posts_update_at", "Posts", "UpdateAt")
s.CreateIndexIfNotExists("idx_posts_create_at", "Posts", "CreateAt")
s.CreateIndexIfNotExists("idx_posts_delete_at", "Posts", "DeleteAt")
s.CreateIndexIfNotExists("idx_posts_channel_id", "Posts", "ChannelId")
s.CreateIndexIfNotExists("idx_posts_root_id", "Posts", "RootId")
s.CreateIndexIfNotExists("idx_posts_user_id", "Posts", "UserId")
s.CreateIndexIfNotExists("idx_posts_is_pinned", "Posts", "IsPinned")

Просмотреть файл

@@ -33,7 +33,6 @@ func newSqlPreferenceStore(sqlStore *SqlStore) store.PreferenceStore {
}
func (s SqlPreferenceStore) createIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_preferences_user_id", "Preferences", "UserId")
s.CreateIndexIfNotExists("idx_preferences_category", "Preferences", "Category")
s.CreateIndexIfNotExists("idx_preferences_name", "Preferences", "Name")
}

Просмотреть файл

@@ -31,11 +31,7 @@ func newSqlProductNoticesStore(sqlStore *SqlStore) store.ProductNoticesStore {
func (s SqlProductNoticesStore) createIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_notice_views_timestamp", "ProductNoticeViewState", "Timestamp")
s.CreateIndexIfNotExists("idx_notice_views_user_id", "ProductNoticeViewState", "UserId")
s.CreateIndexIfNotExists("idx_notice_views_notice_id", "ProductNoticeViewState", "NoticeId")
s.CreateCompositeIndexIfNotExists("idx_notice_views_user_notice", "ProductNoticeViewState", []string{"UserId", "NoticeId"})
}
func (s SqlProductNoticesStore) Clear(notices []string) error {

Просмотреть файл

@@ -48,8 +48,7 @@ func newSqlRetentionPolicyStore(sqlStore *SqlStore, metrics einterfaces.MetricsI
}
func (s *SqlRetentionPolicyStore) createIndexesIfNotExists() {
s.CreateCompositeIndexIfNotExists("IDX_RetentionPolicies_DisplayName_Id", "RetentionPolicies",
[]string{"DisplayName", "Id"})
s.CreateIndexIfNotExists("IDX_RetentionPolicies_DisplayName", "RetentionPolicies", "DisplayName")
s.CreateIndexIfNotExists("IDX_RetentionPoliciesChannels_PolicyId", "RetentionPoliciesChannels", "PolicyId")
s.CreateIndexIfNotExists("IDX_RetentionPoliciesTeams_PolicyId", "RetentionPoliciesTeams", "PolicyId")
s.CreateForeignKeyIfNotExists("RetentionPoliciesChannels", "PolicyId", "RetentionPolicies", "Id", true)

Просмотреть файл

@@ -65,7 +65,6 @@ func newSqlSharedChannelStore(sqlStore *SqlStore) store.SharedChannelStore {
}
func (s SqlSharedChannelStore) createIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_sharedchannelusers_user_id", "SharedChannelUsers", "UserId")
s.CreateIndexIfNotExists("idx_sharedchannelusers_remote_id", "SharedChannelUsers", "RemoteId")
}

Просмотреть файл

@@ -33,7 +33,6 @@ func newSqlStatusStore(sqlStore *SqlStore) store.StatusStore {
}
func (s SqlStatusStore) createIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_status_user_id", "Status", "UserId")
s.CreateIndexIfNotExists("idx_status_status", "Status", "Status")
}

Просмотреть файл

@@ -740,6 +740,30 @@ func TestMySQLReadTimeout(t *testing.T) {
require.NoError(t, err)
}
func TestRemoveIndexIfExists(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
sqlStore := ss.(*SqlStore)
_, err := sqlStore.GetMaster().ExecNoTimeout(`CREATE INDEX idx_posts_create_at ON Posts (CreateAt)`)
require.Error(t, err)
ok := sqlStore.RemoveIndexIfExists("idx_posts_create_at", "Posts")
require.True(t, ok)
ok = sqlStore.RemoveIndexIfExists("idx_posts_create_at", "Posts")
require.False(t, ok)
_, err = sqlStore.GetMaster().ExecNoTimeout(`CREATE INDEX idx_posts_create_at ON Posts (CreateAt)`)
require.NoError(t, err)
ok = sqlStore.RemoveIndexIfExists("idx_posts_create_at", "Posts")
require.True(t, ok)
ok = sqlStore.RemoveIndexIfExists("idx_posts_create_at", "Posts")
require.False(t, ok)
})
}
func TestAlterDefaultIfColumnExists(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
var query string

Просмотреть файл

@@ -20,6 +20,7 @@ import (
const (
CurrentSchemaVersion = Version5360
Version5370 = "5.37.0"
Version5360 = "5.36.0"
Version5350 = "5.35.0"
Version5340 = "5.34.0"
@@ -208,6 +209,7 @@ func upgradeDatabase(sqlStore *SqlStore, currentModelVersionString string) error
upgradeDatabaseToVersion534(sqlStore)
upgradeDatabaseToVersion535(sqlStore)
upgradeDatabaseToVersion536(sqlStore)
upgradeDatabaseToVersion537(sqlStore)
return nil
}
@@ -1133,7 +1135,7 @@ func rootCountMigration(sqlStore *SqlStore) {
forceIndex := ""
if sqlStore.DriverName() == model.DATABASE_DRIVER_MYSQL {
forceIndex = "FORCE INDEX(idx_posts_channel_id)"
forceIndex = "FORCE INDEX(idx_posts_channel_id_update_at)"
}
totalMsgCountRootCTE := `
SELECT Channels.Id channelid, COALESCE(COUNT(*),0) newcount, COALESCE(MAX(Posts.CreateAt), 0) as lastpost
@@ -1179,3 +1181,29 @@ func rootCountMigration(sqlStore *SqlStore) {
}
}
}
func upgradeDatabaseToVersion537(sqlStore *SqlStore) {
// if shouldPerformUpgrade(sqlStore, Version5360, Version5370) {
sqlStore.RemoveIndexIfExists("idx_posts_channel_id", "Posts")
sqlStore.RemoveIndexIfExists("idx_channels_name", "Channels")
sqlStore.RemoveIndexIfExists("idx_publicchannels_name", "PublicChannels")
sqlStore.RemoveIndexIfExists("idx_channelmembers_channel_id", "ChannelMembers")
sqlStore.RemoveIndexIfExists("idx_emoji_name", "Emoji")
sqlStore.RemoveIndexIfExists("idx_oauthaccessdata_client_id", "OAuthAccessData")
sqlStore.RemoveIndexIfExists("idx_oauthauthdata_client_id", "OAuthAuthData")
sqlStore.RemoveIndexIfExists("idx_preferences_user_id", "Preferences")
sqlStore.RemoveIndexIfExists("idx_notice_views_user_id", "ProductNoticeViewState")
sqlStore.RemoveIndexIfExists("idx_notice_views_user_notice", "ProductNoticeViewState")
sqlStore.RemoveIndexIfExists("idx_status_user_id", "Status")
sqlStore.RemoveIndexIfExists("idx_teammembers_team_id", "TeamMembers")
sqlStore.RemoveIndexIfExists("idx_teams_name", "Teams")
sqlStore.RemoveIndexIfExists("idx_user_access_tokens_token", "UserAccessTokens")
sqlStore.RemoveIndexIfExists("idx_user_terms_of_service_user_id", "UserTermsOfService")
sqlStore.RemoveIndexIfExists("idx_users_email", "Users")
sqlStore.RemoveIndexIfExists("idx_sharedchannelusers_user_id", "SharedChannelUsers")
sqlStore.RemoveIndexIfExists("IDX_RetentionPolicies_DisplayName_Id", "RetentionPolicies")
sqlStore.CreateIndexIfNotExists("IDX_RetentionPolicies_DisplayName", "RetentionPolicies", "DisplayName")
// saveSchemaVersion(sqlStore, Version5370)
// }
}

Просмотреть файл

@@ -33,7 +33,6 @@ func newSqlUserAccessTokenStore(sqlStore *SqlStore) store.UserAccessTokenStore {
}
func (s SqlUserAccessTokenStore) createIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_user_access_tokens_token", "UserAccessTokens", "Token")
s.CreateIndexIfNotExists("idx_user_access_tokens_user_id", "UserAccessTokens", "UserId")
}

Просмотреть файл

@@ -82,7 +82,6 @@ func newSqlUserStore(sqlStore *SqlStore, metrics einterfaces.MetricsInterface) s
}
func (us SqlUserStore) createIndexesIfNotExists() {
us.CreateIndexIfNotExists("idx_users_email", "Users", "Email")
us.CreateIndexIfNotExists("idx_users_update_at", "Users", "UpdateAt")
us.CreateIndexIfNotExists("idx_users_create_at", "Users", "CreateAt")
us.CreateIndexIfNotExists("idx_users_delete_at", "Users", "DeleteAt")

Просмотреть файл

@@ -29,7 +29,6 @@ func newSqlUserTermsOfServiceStore(sqlStore *SqlStore) store.UserTermsOfServiceS
}
func (s SqlUserTermsOfServiceStore) createIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_user_terms_of_service_user_id", "UserTermsOfService", "UserId")
}
func (s SqlUserTermsOfServiceStore) GetByUser(userId string) (*model.UserTermsOfService, error) {