From 56e889a3fc18d1ab5c66489608e3bd32c37ab4b2 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Tue, 15 Feb 2022 11:44:04 +0530 Subject: [PATCH] Remove ColMap (#19544) Now that gorp is gone, this is no longer required. ```release-note NONE ``` --- store/sqlstore/audit_store.go | 14 +- store/sqlstore/bot_store.go | 11 +- .../sqlstore/channel_member_history_store.go | 11 +- store/sqlstore/channel_store.go | 47 +--- store/sqlstore/cluster_discovery_store.go | 12 +- store/sqlstore/command_store.go | 18 -- store/sqlstore/command_webhook_store.go | 13 +- store/sqlstore/compliance_store.go | 15 +- store/sqlstore/emoji_store.go | 13 +- store/sqlstore/file_info_store.go | 15 -- store/sqlstore/group_store.go | 24 +- store/sqlstore/integrity_test.go | 205 +++++++++--------- store/sqlstore/job_store.go | 12 +- store/sqlstore/license_store.go | 10 +- store/sqlstore/link_metadata_store.go | 11 +- store/sqlstore/oauth_store.go | 33 +-- store/sqlstore/plugin_store.go | 11 +- store/sqlstore/post_store.go | 20 +- store/sqlstore/preference_store.go | 9 - store/sqlstore/product_notices_store.go | 10 +- store/sqlstore/reaction_store.go | 12 +- store/sqlstore/remote_cluster_store.go | 16 +- store/sqlstore/retention_policy_store.go | 21 +- store/sqlstore/role_store.go | 12 +- store/sqlstore/scheme_store.go | 23 +- store/sqlstore/session_store.go | 14 +- store/sqlstore/shared_channel_store.go | 38 +--- store/sqlstore/status_store.go | 12 +- store/sqlstore/store.go | 27 ++- store/sqlstore/store_test.go | 2 +- store/sqlstore/system_store.go | 10 +- store/sqlstore/team_store.go | 20 -- store/sqlstore/terms_of_service_store.go | 11 +- store/sqlstore/thread_store.go | 14 +- store/sqlstore/tokens_store.go | 11 +- store/sqlstore/upload_session_store.go | 14 +- store/sqlstore/user_access_token_store.go | 12 +- store/sqlstore/user_store.go | 21 -- store/sqlstore/webhook_store.go | 31 +-- 39 files changed, 154 insertions(+), 681 deletions(-) diff --git a/store/sqlstore/audit_store.go b/store/sqlstore/audit_store.go index 8c991c0187..8b99f13475 100644 --- a/store/sqlstore/audit_store.go +++ b/store/sqlstore/audit_store.go @@ -16,19 +16,7 @@ type SqlAuditStore struct { } func newSqlAuditStore(sqlStore *SqlStore) store.AuditStore { - s := &SqlAuditStore{sqlStore} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.Audit{}, "Audits").SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("UserId").SetMaxSize(26) - table.ColMap("Action").SetMaxSize(512) - table.ColMap("ExtraInfo").SetMaxSize(1024) - table.ColMap("IpAddress").SetMaxSize(64) - table.ColMap("SessionId").SetMaxSize(26) - } - - return s + return &SqlAuditStore{sqlStore} } func (s SqlAuditStore) Save(audit *model.Audit) error { diff --git a/store/sqlstore/bot_store.go b/store/sqlstore/bot_store.go index 67735d8b77..b2e20a6835 100644 --- a/store/sqlstore/bot_store.go +++ b/store/sqlstore/bot_store.go @@ -48,19 +48,10 @@ type SqlBotStore struct { // newSqlBotStore creates an instance of SqlBotStore, registering the table schema in question. func newSqlBotStore(sqlStore *SqlStore, metrics einterfaces.MetricsInterface) store.BotStore { - us := &SqlBotStore{ + return &SqlBotStore{ SqlStore: sqlStore, metrics: metrics, } - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(bot{}, "Bots").SetKeys(false, "UserId") - table.ColMap("UserId").SetMaxSize(26) - table.ColMap("Description").SetMaxSize(1024) - table.ColMap("OwnerId").SetMaxSize(model.BotCreatorIdMaxRunes) - } - - return us } // Get fetches the given bot in the database. diff --git a/store/sqlstore/channel_member_history_store.go b/store/sqlstore/channel_member_history_store.go index 2b6186068a..07e46f5aa3 100644 --- a/store/sqlstore/channel_member_history_store.go +++ b/store/sqlstore/channel_member_history_store.go @@ -20,18 +20,9 @@ type SqlChannelMemberHistoryStore struct { } func newSqlChannelMemberHistoryStore(sqlStore *SqlStore) store.ChannelMemberHistoryStore { - s := &SqlChannelMemberHistoryStore{ + return &SqlChannelMemberHistoryStore{ SqlStore: sqlStore, } - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.ChannelMemberHistory{}, "ChannelMemberHistory").SetKeys(false, "ChannelId", "UserId", "JoinTime") - table.ColMap("ChannelId").SetMaxSize(26) - table.ColMap("UserId").SetMaxSize(26) - table.ColMap("JoinTime").SetNotNull(true) - } - - return s } func (s SqlChannelMemberHistoryStore) LogJoinEvent(userId string, channelId string, joinTime int64) error { diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go index cd198c70dc..ec1d1dbd5f 100644 --- a/store/sqlstore/channel_store.go +++ b/store/sqlstore/channel_store.go @@ -454,55 +454,10 @@ func (s SqlChannelStore) ClearCaches() { } func newSqlChannelStore(sqlStore *SqlStore, metrics einterfaces.MetricsInterface) store.ChannelStore { - s := &SqlChannelStore{ + return &SqlChannelStore{ SqlStore: sqlStore, metrics: metrics, } - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.Channel{}, "Channels").SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("TeamId").SetMaxSize(26) - table.ColMap("Type").SetMaxSize(1) - table.ColMap("DisplayName").SetMaxSize(64) - table.ColMap("Name").SetMaxSize(64) - table.SetUniqueTogether("Name", "TeamId") - table.ColMap("Header").SetMaxSize(1024) - table.ColMap("Purpose").SetMaxSize(250) - table.ColMap("CreatorId").SetMaxSize(26) - table.ColMap("SchemeId").SetMaxSize(26) - table.ColMap("LastRootPostAt").SetDefaultConstraint(model.NewString("0")) - - tablem := db.AddTableWithName(channelMember{}, "ChannelMembers").SetKeys(false, "ChannelId", "UserId") - tablem.ColMap("ChannelId").SetMaxSize(26) - tablem.ColMap("UserId").SetMaxSize(26) - tablem.ColMap("Roles").SetMaxSize(model.UserRolesMaxLength) - tablem.ColMap("NotifyProps").SetDataType(sqlStore.jsonDataType()) - - tablePublicChannels := db.AddTableWithName(publicChannel{}, "PublicChannels").SetKeys(false, "Id") - tablePublicChannels.ColMap("Id").SetMaxSize(26) - tablePublicChannels.ColMap("TeamId").SetMaxSize(26) - tablePublicChannels.ColMap("DisplayName").SetMaxSize(64) - tablePublicChannels.ColMap("Name").SetMaxSize(64) - tablePublicChannels.SetUniqueTogether("Name", "TeamId") - tablePublicChannels.ColMap("Header").SetMaxSize(1024) - tablePublicChannels.ColMap("Purpose").SetMaxSize(250) - - tableSidebarCategories := db.AddTableWithName(model.SidebarCategory{}, "SidebarCategories").SetKeys(false, "Id") - tableSidebarCategories.ColMap("Id").SetMaxSize(128) - tableSidebarCategories.ColMap("UserId").SetMaxSize(26) - tableSidebarCategories.ColMap("TeamId").SetMaxSize(26) - tableSidebarCategories.ColMap("Sorting").SetMaxSize(64) - tableSidebarCategories.ColMap("Type").SetMaxSize(64) - tableSidebarCategories.ColMap("DisplayName").SetMaxSize(64) - - tableSidebarChannels := db.AddTableWithName(model.SidebarChannel{}, "SidebarChannels").SetKeys(false, "ChannelId", "UserId", "CategoryId") - tableSidebarChannels.ColMap("ChannelId").SetMaxSize(26) - tableSidebarChannels.ColMap("UserId").SetMaxSize(26) - tableSidebarChannels.ColMap("CategoryId").SetMaxSize(128) - } - - return s } func (s SqlChannelStore) upsertPublicChannelT(transaction *sqlxTxWrapper, channel *model.Channel) error { diff --git a/store/sqlstore/cluster_discovery_store.go b/store/sqlstore/cluster_discovery_store.go index e6df9574c8..818ed39701 100644 --- a/store/sqlstore/cluster_discovery_store.go +++ b/store/sqlstore/cluster_discovery_store.go @@ -16,17 +16,7 @@ type sqlClusterDiscoveryStore struct { } func newSqlClusterDiscoveryStore(sqlStore *SqlStore) store.ClusterDiscoveryStore { - s := &sqlClusterDiscoveryStore{sqlStore} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.ClusterDiscovery{}, "ClusterDiscovery").SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("Type").SetMaxSize(64) - table.ColMap("ClusterName").SetMaxSize(64) - table.ColMap("Hostname").SetMaxSize(512) - } - - return s + return &sqlClusterDiscoveryStore{sqlStore} } func (s sqlClusterDiscoveryStore) Save(ClusterDiscovery *model.ClusterDiscovery) error { diff --git a/store/sqlstore/command_store.go b/store/sqlstore/command_store.go index be0343315f..f72b8c100c 100644 --- a/store/sqlstore/command_store.go +++ b/store/sqlstore/command_store.go @@ -26,24 +26,6 @@ func newSqlCommandStore(sqlStore *SqlStore) store.CommandStore { s.commandsQuery = s.getQueryBuilder(). Select("*"). From("Commands") - for _, db := range sqlStore.GetAllConns() { - tableo := db.AddTableWithName(model.Command{}, "Commands").SetKeys(false, "Id") - tableo.ColMap("Id").SetMaxSize(26) - tableo.ColMap("Token").SetMaxSize(26) - tableo.ColMap("CreatorId").SetMaxSize(26) - tableo.ColMap("TeamId").SetMaxSize(26) - tableo.ColMap("Trigger").SetMaxSize(128) - tableo.ColMap("URL").SetMaxSize(1024) - tableo.ColMap("Method").SetMaxSize(1) - tableo.ColMap("Username").SetMaxSize(64) - tableo.ColMap("IconURL").SetMaxSize(1024) - tableo.ColMap("AutoCompleteDesc").SetMaxSize(1024) - tableo.ColMap("AutoCompleteHint").SetMaxSize(1024) - tableo.ColMap("DisplayName").SetMaxSize(64) - tableo.ColMap("Description").SetMaxSize(128) - tableo.ColMap("PluginId").SetMaxSize(190) - } - return s } diff --git a/store/sqlstore/command_webhook_store.go b/store/sqlstore/command_webhook_store.go index 12df5d2c34..f53c97dff2 100644 --- a/store/sqlstore/command_webhook_store.go +++ b/store/sqlstore/command_webhook_store.go @@ -19,18 +19,7 @@ type SqlCommandWebhookStore struct { } func newSqlCommandWebhookStore(sqlStore *SqlStore) store.CommandWebhookStore { - s := &SqlCommandWebhookStore{sqlStore} - - for _, db := range sqlStore.GetAllConns() { - tablec := db.AddTableWithName(model.CommandWebhook{}, "CommandWebhooks").SetKeys(false, "Id") - tablec.ColMap("Id").SetMaxSize(26) - tablec.ColMap("CommandId").SetMaxSize(26) - tablec.ColMap("UserId").SetMaxSize(26) - tablec.ColMap("ChannelId").SetMaxSize(26) - tablec.ColMap("RootId").SetMaxSize(26) - } - - return s + return &SqlCommandWebhookStore{sqlStore} } func (s SqlCommandWebhookStore) Save(webhook *model.CommandWebhook) (*model.CommandWebhook, error) { diff --git a/store/sqlstore/compliance_store.go b/store/sqlstore/compliance_store.go index 45a121fd07..7b6d4b515a 100644 --- a/store/sqlstore/compliance_store.go +++ b/store/sqlstore/compliance_store.go @@ -20,20 +20,7 @@ type SqlComplianceStore struct { } func newSqlComplianceStore(sqlStore *SqlStore) store.ComplianceStore { - s := &SqlComplianceStore{sqlStore} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.Compliance{}, "Compliances").SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("UserId").SetMaxSize(26) - table.ColMap("Status").SetMaxSize(64) - table.ColMap("Desc").SetMaxSize(512) - table.ColMap("Type").SetMaxSize(64) - table.ColMap("Keywords").SetMaxSize(512) - table.ColMap("Emails").SetMaxSize(1024) - } - - return s + return &SqlComplianceStore{sqlStore} } func (s SqlComplianceStore) Save(compliance *model.Compliance) (*model.Compliance, error) { diff --git a/store/sqlstore/emoji_store.go b/store/sqlstore/emoji_store.go index 60b54a7f28..a3bdc5b900 100644 --- a/store/sqlstore/emoji_store.go +++ b/store/sqlstore/emoji_store.go @@ -22,21 +22,10 @@ type SqlEmojiStore struct { } func newSqlEmojiStore(sqlStore *SqlStore, metrics einterfaces.MetricsInterface) store.EmojiStore { - s := &SqlEmojiStore{ + return &SqlEmojiStore{ SqlStore: sqlStore, metrics: metrics, } - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.Emoji{}, "Emoji").SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("CreatorId").SetMaxSize(26) - table.ColMap("Name").SetMaxSize(64) - - table.SetUniqueTogether("Name", "DeleteAt") - } - - return s } func (es SqlEmojiStore) Save(emoji *model.Emoji) (*model.Emoji, error) { diff --git a/store/sqlstore/file_info_store.go b/store/sqlstore/file_info_store.go index 2ddd5fda99..8353571e83 100644 --- a/store/sqlstore/file_info_store.go +++ b/store/sqlstore/file_info_store.go @@ -104,21 +104,6 @@ func newSqlFileInfoStore(sqlStore *SqlStore, metrics einterfaces.MetricsInterfac "Coalesce(FileInfo.RemoteId, '') AS RemoteId", } - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.FileInfo{}, "FileInfo").SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("CreatorId").SetMaxSize(26) - table.ColMap("PostId").SetMaxSize(26) - table.ColMap("Path").SetMaxSize(512) - table.ColMap("ThumbnailPath").SetMaxSize(512) - table.ColMap("PreviewPath").SetMaxSize(512) - table.ColMap("Name").SetMaxSize(256) - table.ColMap("Content").SetMaxSize(0) - table.ColMap("Extension").SetMaxSize(64) - table.ColMap("MimeType").SetMaxSize(256) - table.ColMap("RemoteId").SetMaxSize(26) - } - return s } diff --git a/store/sqlstore/group_store.go b/store/sqlstore/group_store.go index 248a997e6f..d5aab1e6b4 100644 --- a/store/sqlstore/group_store.go +++ b/store/sqlstore/group_store.go @@ -52,29 +52,7 @@ type SqlGroupStore struct { } func newSqlGroupStore(sqlStore *SqlStore) store.GroupStore { - s := &SqlGroupStore{SqlStore: sqlStore} - for _, db := range sqlStore.GetAllConns() { - groups := db.AddTableWithName(model.Group{}, "UserGroups").SetKeys(false, "Id") - groups.ColMap("Id").SetMaxSize(26) - groups.ColMap("Name").SetMaxSize(model.GroupNameMaxLength).SetUnique(true) - groups.ColMap("DisplayName").SetMaxSize(model.GroupDisplayNameMaxLength) - groups.ColMap("Description").SetMaxSize(model.GroupDescriptionMaxLength) - groups.ColMap("Source").SetMaxSize(model.GroupSourceMaxLength) - groups.ColMap("RemoteId").SetMaxSize(model.GroupRemoteIDMaxLength) - - groupMembers := db.AddTableWithName(model.GroupMember{}, "GroupMembers").SetKeys(false, "GroupId", "UserId") - groupMembers.ColMap("GroupId").SetMaxSize(26) - groupMembers.ColMap("UserId").SetMaxSize(26) - - groupTeams := db.AddTableWithName(groupTeam{}, "GroupTeams").SetKeys(false, "GroupId", "TeamId") - groupTeams.ColMap("GroupId").SetMaxSize(26) - groupTeams.ColMap("TeamId").SetMaxSize(26) - - groupChannels := db.AddTableWithName(groupChannel{}, "GroupChannels").SetKeys(false, "GroupId", "ChannelId") - groupChannels.ColMap("GroupId").SetMaxSize(26) - groupChannels.ColMap("ChannelId").SetMaxSize(26) - } - return s + return &SqlGroupStore{SqlStore: sqlStore} } func (s *SqlGroupStore) Create(group *model.Group) (*model.Group, error) { diff --git a/store/sqlstore/integrity_test.go b/store/sqlstore/integrity_test.go index f292833d3b..1e331bc151 100644 --- a/store/sqlstore/integrity_test.go +++ b/store/sqlstore/integrity_test.go @@ -411,15 +411,15 @@ func TestCheckParentChildIntegrity(t *testing.T) { func TestCheckChannelsCommandWebhooksIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkChannelsCommandWebhooksIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) require.Empty(t, data.Records) - }) + }) t.Run("should generate a report with one record", func(t *testing.T) { channelId := model.NewId() cwh := createCommandWebhook(ss, model.NewId(), model.NewId(), channelId) @@ -431,7 +431,7 @@ func TestCheckChannelsCommandWebhooksIntegrity(t *testing.T) { ParentId: &channelId, ChildId: &cwh.Id, }, data.Records[0]) - dbmap.Delete(cwh) + dbmap.Exec(`DELETE FROM CommandWebhooks Where Id=?`, cwh.Id) }) }) } @@ -439,7 +439,7 @@ func TestCheckChannelsCommandWebhooksIntegrity(t *testing.T) { func TestCheckChannelsChannelMemberHistoryIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkChannelsChannelMemberHistoryIntegrity(store) @@ -452,7 +452,8 @@ func TestCheckChannelsChannelMemberHistoryIntegrity(t *testing.T) { channel := createChannel(ss, model.NewId(), model.NewId()) user := createUser(ss) cmh := createChannelMemberHistory(ss, channel.Id, user.Id) - dbmap.Delete(channel) + + dbmap.Exec(`DELETE FROM Channels Where Id=?`, channel.Id) result := checkChannelsChannelMemberHistoryIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -460,7 +461,7 @@ func TestCheckChannelsChannelMemberHistoryIntegrity(t *testing.T) { require.Equal(t, model.OrphanedRecord{ ParentId: &cmh.ChannelId, }, data.Records[0]) - dbmap.Delete(user) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, user.Id) dbmap.Exec(`DELETE FROM ChannelMemberHistory`) }) }) @@ -469,7 +470,7 @@ func TestCheckChannelsChannelMemberHistoryIntegrity(t *testing.T) { func TestCheckChannelsChannelMembersIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkChannelsChannelMembersIntegrity(store) @@ -481,7 +482,7 @@ func TestCheckChannelsChannelMembersIntegrity(t *testing.T) { t.Run("should generate a report with one record", func(t *testing.T) { channel := createChannel(ss, model.NewId(), model.NewId()) member := createChannelMemberWithChannelId(ss, channel.Id) - dbmap.Delete(channel) + dbmap.Exec(`DELETE FROM Channels Where Id=?`, channel.Id) result := checkChannelsChannelMembersIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -497,7 +498,7 @@ func TestCheckChannelsChannelMembersIntegrity(t *testing.T) { func TestCheckChannelsIncomingWebhooksIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkChannelsIncomingWebhooksIntegrity(store) @@ -517,7 +518,7 @@ func TestCheckChannelsIncomingWebhooksIntegrity(t *testing.T) { ParentId: &channelId, ChildId: &wh.Id, }, data.Records[0]) - dbmap.Delete(wh) + dbmap.Exec(`DELETE FROM IncomingWebhooks WHERE Id=?`, wh.Id) }) }) } @@ -525,7 +526,7 @@ func TestCheckChannelsIncomingWebhooksIntegrity(t *testing.T) { func TestCheckChannelsOutgoingWebhooksIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkChannelsOutgoingWebhooksIntegrity(store) @@ -538,7 +539,7 @@ func TestCheckChannelsOutgoingWebhooksIntegrity(t *testing.T) { channel := createChannel(ss, model.NewId(), model.NewId()) channelId := channel.Id wh := createOutgoingWebhook(ss, model.NewId(), channelId, model.NewId()) - dbmap.Delete(channel) + dbmap.Exec(`DELETE FROM Channels Where Id=?`, channel.Id) result := checkChannelsOutgoingWebhooksIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -547,7 +548,7 @@ func TestCheckChannelsOutgoingWebhooksIntegrity(t *testing.T) { ParentId: &channelId, ChildId: &wh.Id, }, data.Records[0]) - dbmap.Delete(wh) + dbmap.Exec(`DELETE FROM OutgoingWebhooks WHERE Id=?`, wh.Id) }) }) } @@ -555,7 +556,7 @@ func TestCheckChannelsOutgoingWebhooksIntegrity(t *testing.T) { func TestCheckChannelsPostsIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkChannelsPostsIntegrity(store) @@ -574,7 +575,7 @@ func TestCheckChannelsPostsIntegrity(t *testing.T) { ParentId: &post.ChannelId, ChildId: &post.Id, }, data.Records[0]) - dbmap.Delete(post) + dbmap.Exec(`DELETE FROM Posts WHERE Id=?`, post.Id) }) }) } @@ -582,7 +583,7 @@ func TestCheckChannelsPostsIntegrity(t *testing.T) { func TestCheckCommandsCommandWebhooksIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkCommandsCommandWebhooksIntegrity(store) @@ -602,7 +603,7 @@ func TestCheckCommandsCommandWebhooksIntegrity(t *testing.T) { ParentId: &commandId, ChildId: &cwh.Id, }, data.Records[0]) - dbmap.Delete(cwh) + dbmap.Exec(`DELETE FROM CommandWebhooks Where Id=?`, cwh.Id) }) }) } @@ -610,7 +611,7 @@ func TestCheckCommandsCommandWebhooksIntegrity(t *testing.T) { func TestCheckPostsFileInfoIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkPostsFileInfoIntegrity(store) @@ -630,7 +631,7 @@ func TestCheckPostsFileInfoIntegrity(t *testing.T) { ParentId: &postId, ChildId: &info.Id, }, data.Records[0]) - dbmap.Delete(info) + dbmap.Exec(`DELETE FROM FileInfo WHERE Id=?`, info.Id) }) }) } @@ -638,7 +639,7 @@ func TestCheckPostsFileInfoIntegrity(t *testing.T) { func TestCheckPostsPostsRootIdIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkPostsPostsRootIdIntegrity(store) @@ -651,7 +652,7 @@ func TestCheckPostsPostsRootIdIntegrity(t *testing.T) { root := createPost(ss, model.NewId(), model.NewId(), "", "") rootId := root.Id post := createPost(ss, model.NewId(), model.NewId(), root.Id, root.Id) - dbmap.Delete(root) + dbmap.Exec(`DELETE FROM Posts WHERE Id=?`, root.Id) result := checkPostsPostsRootIdIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -660,7 +661,7 @@ func TestCheckPostsPostsRootIdIntegrity(t *testing.T) { ParentId: &rootId, ChildId: &post.Id, }, data.Records[0]) - dbmap.Delete(post) + dbmap.Exec(`DELETE FROM Posts WHERE Id=?`, post.Id) }) }) } @@ -668,7 +669,7 @@ func TestCheckPostsPostsRootIdIntegrity(t *testing.T) { func TestCheckPostsReactionsIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkPostsReactionsIntegrity(store) @@ -687,7 +688,7 @@ func TestCheckPostsReactionsIntegrity(t *testing.T) { require.Equal(t, model.OrphanedRecord{ ParentId: &postId, }, data.Records[0]) - dbmap.Delete(reaction) + dbmap.Exec(`DELETE FROM Reactions WHERE PostId=? AND UserId=? AND EmojiName=?`, reaction.PostId, reaction.UserId, reaction.EmojiName) }) }) } @@ -695,7 +696,7 @@ func TestCheckPostsReactionsIntegrity(t *testing.T) { func TestCheckSchemesChannelsIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkSchemesChannelsIntegrity(store) @@ -709,7 +710,7 @@ func TestCheckSchemesChannelsIntegrity(t *testing.T) { scheme := createScheme(ss) schemeId := scheme.Id channel := createChannelWithSchemeId(ss, &schemeId) - dbmap.Delete(scheme) + dbmap.Exec(`DELETE FROM Schemes WHERE Id=?`, scheme.Id) result := checkSchemesChannelsIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -718,7 +719,7 @@ func TestCheckSchemesChannelsIntegrity(t *testing.T) { ParentId: &schemeId, ChildId: &channel.Id, }, data.Records[0]) - dbmap.Delete(channel) + dbmap.Exec(`DELETE FROM Channels WHERE Id=?`, channel.Id) }) }) } @@ -726,7 +727,7 @@ func TestCheckSchemesChannelsIntegrity(t *testing.T) { func TestCheckSchemesTeamsIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkSchemesTeamsIntegrity(store) @@ -740,7 +741,7 @@ func TestCheckSchemesTeamsIntegrity(t *testing.T) { scheme := createScheme(ss) schemeId := scheme.Id team := createTeamWithSchemeId(ss, &schemeId) - dbmap.Delete(scheme) + dbmap.Exec(`DELETE FROM Schemes WHERE Id=?`, scheme.Id) result := checkSchemesTeamsIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -749,7 +750,7 @@ func TestCheckSchemesTeamsIntegrity(t *testing.T) { ParentId: &schemeId, ChildId: &team.Id, }, data.Records[0]) - dbmap.Delete(team) + dbmap.Exec(`DELETE FROM Teams WHERE Id=?`, team.Id) }) }) } @@ -757,7 +758,7 @@ func TestCheckSchemesTeamsIntegrity(t *testing.T) { func TestCheckSessionsAuditsIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkSessionsAuditsIntegrity(store) @@ -771,7 +772,7 @@ func TestCheckSessionsAuditsIntegrity(t *testing.T) { session := createSession(ss, model.NewId()) sessionId := session.Id audit := createAudit(ss, userId, sessionId) - dbmap.Delete(session) + dbmap.Exec(`DELETE FROM Sessions WHERE Id=?`, session.Id) result := checkSessionsAuditsIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -788,7 +789,7 @@ func TestCheckSessionsAuditsIntegrity(t *testing.T) { func TestCheckTeamsChannelsIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkTeamsChannelsIntegrity(store) @@ -807,7 +808,7 @@ func TestCheckTeamsChannelsIntegrity(t *testing.T) { ParentId: &channel.TeamId, ChildId: &channel.Id, }, data.Records[0]) - dbmap.Delete(channel) + dbmap.Exec(`DELETE FROM Channels WHERE Id=?`, channel.Id) }) t.Run("should not include direct channel with empty teamid", func(t *testing.T) { @@ -825,10 +826,10 @@ func TestCheckTeamsChannelsIntegrity(t *testing.T) { ParentId: &channel.TeamId, ChildId: &channel.Id, }, data.Records[0]) - dbmap.Delete(channel) - dbmap.Delete(userA) - dbmap.Delete(userB) - dbmap.Delete(direct) + dbmap.Exec(`DELETE FROM Channels WHERE Id=?`, channel.Id) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, userA.Id) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, userB.Id) + dbmap.Exec(`DELETE FROM Channels WHERE Id=?`, direct.Id) }) t.Run("should include direct channel with non empty teamid", func(t *testing.T) { @@ -852,10 +853,10 @@ func TestCheckTeamsChannelsIntegrity(t *testing.T) { ParentId: model.NewString("test"), ChildId: &direct.Id, }, data.Records[1]) - dbmap.Delete(channel) - dbmap.Delete(userA) - dbmap.Delete(userB) - dbmap.Delete(direct) + dbmap.Exec(`DELETE FROM Channels WHERE Id=?`, channel.Id) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, userA.Id) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, userB.Id) + dbmap.Exec(`DELETE FROM Channels WHERE Id=?`, direct.Id) dbmap.Exec("DELETE FROM ChannelMembers") }) }) @@ -864,7 +865,7 @@ func TestCheckTeamsChannelsIntegrity(t *testing.T) { func TestCheckTeamsCommandsIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkTeamsCommandsIntegrity(store) @@ -884,7 +885,7 @@ func TestCheckTeamsCommandsIntegrity(t *testing.T) { ParentId: &teamId, ChildId: &cmd.Id, }, data.Records[0]) - dbmap.Delete(cmd) + dbmap.Exec(`DELETE FROM Commands WHERE Id=?`, cmd.Id) }) }) } @@ -892,7 +893,7 @@ func TestCheckTeamsCommandsIntegrity(t *testing.T) { func TestCheckTeamsIncomingWebhooksIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkTeamsIncomingWebhooksIntegrity(store) @@ -912,7 +913,7 @@ func TestCheckTeamsIncomingWebhooksIntegrity(t *testing.T) { ParentId: &teamId, ChildId: &wh.Id, }, data.Records[0]) - dbmap.Delete(wh) + dbmap.Exec(`DELETE FROM IncomingWebhooks WHERE Id=?`, wh.Id) }) }) } @@ -920,7 +921,7 @@ func TestCheckTeamsIncomingWebhooksIntegrity(t *testing.T) { func TestCheckTeamsOutgoingWebhooksIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkTeamsOutgoingWebhooksIntegrity(store) @@ -940,7 +941,7 @@ func TestCheckTeamsOutgoingWebhooksIntegrity(t *testing.T) { ParentId: &teamId, ChildId: &wh.Id, }, data.Records[0]) - dbmap.Delete(wh) + dbmap.Exec(`DELETE FROM OutgoingWebhooks WHERE Id=?`, wh.Id) }) }) } @@ -948,7 +949,7 @@ func TestCheckTeamsOutgoingWebhooksIntegrity(t *testing.T) { func TestCheckTeamsTeamMembersIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkTeamsTeamMembersIntegrity(store) @@ -960,7 +961,7 @@ func TestCheckTeamsTeamMembersIntegrity(t *testing.T) { t.Run("should generate a report with one record", func(t *testing.T) { team := createTeam(ss) member := createTeamMember(ss, team.Id, model.NewId()) - dbmap.Delete(team) + dbmap.Exec(`DELETE FROM Teams WHERE Id=?`, team.Id) result := checkTeamsTeamMembersIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -976,7 +977,7 @@ func TestCheckTeamsTeamMembersIntegrity(t *testing.T) { func TestCheckUsersAuditsIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersAuditsIntegrity(store) @@ -989,7 +990,7 @@ func TestCheckUsersAuditsIntegrity(t *testing.T) { user := createUser(ss) userId := user.Id audit := createAudit(ss, userId, model.NewId()) - dbmap.Delete(user) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, user.Id) result := checkUsersAuditsIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -1006,7 +1007,7 @@ func TestCheckUsersAuditsIntegrity(t *testing.T) { func TestCheckUsersCommandWebhooksIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersCommandWebhooksIntegrity(store) @@ -1026,7 +1027,7 @@ func TestCheckUsersCommandWebhooksIntegrity(t *testing.T) { ParentId: &userId, ChildId: &cwh.Id, }, data.Records[0]) - dbmap.Delete(cwh) + dbmap.Exec(`DELETE FROM CommandWebhooks WHERE Id=?`, cwh.Id) }) }) } @@ -1034,7 +1035,7 @@ func TestCheckUsersCommandWebhooksIntegrity(t *testing.T) { func TestCheckUsersChannelsIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersChannelsIntegrity(store) @@ -1053,7 +1054,7 @@ func TestCheckUsersChannelsIntegrity(t *testing.T) { ParentId: &channel.CreatorId, ChildId: &channel.Id, }, data.Records[0]) - dbmap.Delete(channel) + dbmap.Exec(`DELETE FROM Channels WHERE Id=?`, channel.Id) }) }) } @@ -1061,7 +1062,7 @@ func TestCheckUsersChannelsIntegrity(t *testing.T) { func TestCheckUsersChannelMemberHistoryIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersChannelMemberHistoryIntegrity(store) @@ -1074,7 +1075,7 @@ func TestCheckUsersChannelMemberHistoryIntegrity(t *testing.T) { user := createUser(ss) channel := createChannel(ss, model.NewId(), model.NewId()) cmh := createChannelMemberHistory(ss, channel.Id, user.Id) - dbmap.Delete(user) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, user.Id) result := checkUsersChannelMemberHistoryIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -1082,7 +1083,7 @@ func TestCheckUsersChannelMemberHistoryIntegrity(t *testing.T) { require.Equal(t, model.OrphanedRecord{ ParentId: &cmh.UserId, }, data.Records[0]) - dbmap.Delete(channel) + dbmap.Exec(`DELETE FROM Channels WHERE Id=?`, channel.Id) dbmap.Exec(`DELETE FROM ChannelMemberHistory`) }) }) @@ -1091,7 +1092,7 @@ func TestCheckUsersChannelMemberHistoryIntegrity(t *testing.T) { func TestCheckUsersChannelMembersIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersChannelMembersIntegrity(store) @@ -1104,7 +1105,7 @@ func TestCheckUsersChannelMembersIntegrity(t *testing.T) { user := createUser(ss) channel := createChannelWithCreatorId(ss, user.Id) member := createChannelMember(ss, channel.Id, user.Id) - dbmap.Delete(user) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, user.Id) result := checkUsersChannelMembersIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -1112,7 +1113,7 @@ func TestCheckUsersChannelMembersIntegrity(t *testing.T) { require.Equal(t, model.OrphanedRecord{ ParentId: &member.UserId, }, data.Records[0]) - dbmap.Delete(channel) + dbmap.Exec(`DELETE FROM Channels WHERE Id=?`, channel.Id) ss.Channel().PermanentDeleteMembersByUser(member.UserId) }) }) @@ -1121,7 +1122,7 @@ func TestCheckUsersChannelMembersIntegrity(t *testing.T) { func TestCheckUsersCommandsIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersCommandsIntegrity(store) @@ -1141,7 +1142,7 @@ func TestCheckUsersCommandsIntegrity(t *testing.T) { ParentId: &userId, ChildId: &cmd.Id, }, data.Records[0]) - dbmap.Delete(cmd) + dbmap.Exec(`DELETE FROM Commands WHERE Id=?`, cmd.Id) }) }) } @@ -1149,7 +1150,7 @@ func TestCheckUsersCommandsIntegrity(t *testing.T) { func TestCheckUsersCompliancesIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersCompliancesIntegrity(store) @@ -1162,7 +1163,7 @@ func TestCheckUsersCompliancesIntegrity(t *testing.T) { user := createUser(ss) userId := user.Id compliance := createCompliance(ss, userId) - dbmap.Delete(user) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, user.Id) result := checkUsersCompliancesIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -1171,7 +1172,7 @@ func TestCheckUsersCompliancesIntegrity(t *testing.T) { ParentId: &userId, ChildId: &compliance.Id, }, data.Records[0]) - dbmap.Delete(compliance) + dbmap.Exec(`DELETE FROM Compliances WHERE Id=?`, compliance.Id) }) }) } @@ -1179,7 +1180,7 @@ func TestCheckUsersCompliancesIntegrity(t *testing.T) { func TestCheckUsersEmojiIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersEmojiIntegrity(store) @@ -1192,7 +1193,7 @@ func TestCheckUsersEmojiIntegrity(t *testing.T) { user := createUser(ss) userId := user.Id emoji := createEmoji(ss, userId) - dbmap.Delete(user) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, user.Id) result := checkUsersEmojiIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -1201,7 +1202,7 @@ func TestCheckUsersEmojiIntegrity(t *testing.T) { ParentId: &userId, ChildId: &emoji.Id, }, data.Records[0]) - dbmap.Delete(emoji) + dbmap.Exec(`DELETE FROM Emoji WHERE Id=?`, emoji.Id) }) }) } @@ -1209,7 +1210,7 @@ func TestCheckUsersEmojiIntegrity(t *testing.T) { func TestCheckUsersFileInfoIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersFileInfoIntegrity(store) @@ -1222,7 +1223,7 @@ func TestCheckUsersFileInfoIntegrity(t *testing.T) { user := createUser(ss) userId := user.Id info := createFileInfo(ss, model.NewId(), userId) - dbmap.Delete(user) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, user.Id) result := checkUsersFileInfoIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -1231,7 +1232,7 @@ func TestCheckUsersFileInfoIntegrity(t *testing.T) { ParentId: &userId, ChildId: &info.Id, }, data.Records[0]) - dbmap.Delete(info) + dbmap.Exec(`DELETE FROM FileInfo WHERE Id=?`, info.Id) }) }) } @@ -1239,7 +1240,7 @@ func TestCheckUsersFileInfoIntegrity(t *testing.T) { func TestCheckUsersIncomingWebhooksIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersIncomingWebhooksIntegrity(store) @@ -1259,7 +1260,7 @@ func TestCheckUsersIncomingWebhooksIntegrity(t *testing.T) { ParentId: &userId, ChildId: &wh.Id, }, data.Records[0]) - dbmap.Delete(wh) + dbmap.Exec(`DELETE FROM IncomingWebhooks WHERE Id=?`, wh.Id) }) }) } @@ -1267,7 +1268,7 @@ func TestCheckUsersIncomingWebhooksIntegrity(t *testing.T) { func TestCheckUsersOAuthAccessDataIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersOAuthAccessDataIntegrity(store) @@ -1280,7 +1281,7 @@ func TestCheckUsersOAuthAccessDataIntegrity(t *testing.T) { user := createUser(ss) userId := user.Id ad := createOAuthAccessData(ss, userId) - dbmap.Delete(user) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, user.Id) result := checkUsersOAuthAccessDataIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -1297,7 +1298,7 @@ func TestCheckUsersOAuthAccessDataIntegrity(t *testing.T) { func TestCheckUsersOAuthAppsIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersOAuthAppsIntegrity(store) @@ -1310,7 +1311,7 @@ func TestCheckUsersOAuthAppsIntegrity(t *testing.T) { user := createUser(ss) userId := user.Id app := createOAuthApp(ss, userId) - dbmap.Delete(user) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, user.Id) result := checkUsersOAuthAppsIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -1327,7 +1328,7 @@ func TestCheckUsersOAuthAppsIntegrity(t *testing.T) { func TestCheckUsersOAuthAuthDataIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersOAuthAuthDataIntegrity(store) @@ -1340,7 +1341,7 @@ func TestCheckUsersOAuthAuthDataIntegrity(t *testing.T) { user := createUser(ss) userId := user.Id ad := createOAuthAuthData(ss, userId) - dbmap.Delete(user) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, user.Id) result := checkUsersOAuthAuthDataIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -1357,7 +1358,7 @@ func TestCheckUsersOAuthAuthDataIntegrity(t *testing.T) { func TestCheckUsersOutgoingWebhooksIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersOutgoingWebhooksIntegrity(store) @@ -1377,7 +1378,7 @@ func TestCheckUsersOutgoingWebhooksIntegrity(t *testing.T) { ParentId: &userId, ChildId: &wh.Id, }, data.Records[0]) - dbmap.Delete(wh) + dbmap.Exec(`DELETE FROM OutgoingWebhooks WHERE Id=?`, wh.Id) }) }) } @@ -1385,7 +1386,7 @@ func TestCheckUsersOutgoingWebhooksIntegrity(t *testing.T) { func TestCheckUsersPostsIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersPostsIntegrity(store) @@ -1404,7 +1405,7 @@ func TestCheckUsersPostsIntegrity(t *testing.T) { ParentId: &post.UserId, ChildId: &post.Id, }, data.Records[0]) - dbmap.Delete(post) + dbmap.Exec(`DELETE FROM Posts WHERE Id=?`, post.Id) }) }) } @@ -1412,7 +1413,7 @@ func TestCheckUsersPostsIntegrity(t *testing.T) { func TestCheckUsersPreferencesIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersPreferencesIntegrity(store) @@ -1432,7 +1433,7 @@ func TestCheckUsersPreferencesIntegrity(t *testing.T) { data := result.Data.(model.RelationalIntegrityCheckData) require.Empty(t, data.Records) dbmap.Exec(`DELETE FROM Preferences`) - dbmap.Delete(user) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, user.Id) }) t.Run("should generate a report with one record", func(t *testing.T) { @@ -1441,7 +1442,7 @@ func TestCheckUsersPreferencesIntegrity(t *testing.T) { userId := user.Id preferences := createPreferences(ss, userId) require.NotNil(t, preferences) - dbmap.Delete(user) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, user.Id) result := checkUsersPreferencesIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -1450,7 +1451,7 @@ func TestCheckUsersPreferencesIntegrity(t *testing.T) { ParentId: &userId, }, data.Records[0]) dbmap.Exec(`DELETE FROM Preferences`) - dbmap.Delete(user) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, user.Id) }) }) } @@ -1458,7 +1459,7 @@ func TestCheckUsersPreferencesIntegrity(t *testing.T) { func TestCheckUsersReactionsIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersReactionsIntegrity(store) @@ -1471,7 +1472,7 @@ func TestCheckUsersReactionsIntegrity(t *testing.T) { user := createUser(ss) userId := user.Id reaction := createReaction(ss, user.Id, model.NewId()) - dbmap.Delete(user) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, user.Id) result := checkUsersReactionsIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -1479,7 +1480,7 @@ func TestCheckUsersReactionsIntegrity(t *testing.T) { require.Equal(t, model.OrphanedRecord{ ParentId: &userId, }, data.Records[0]) - dbmap.Delete(reaction) + dbmap.Exec(`DELETE FROM Reactions WHERE PostId=? AND UserId=? AND EmojiName=?`, reaction.PostId, reaction.UserId, reaction.EmojiName) }) }) } @@ -1487,7 +1488,7 @@ func TestCheckUsersReactionsIntegrity(t *testing.T) { func TestCheckUsersSessionsIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersSessionsIntegrity(store) @@ -1507,7 +1508,7 @@ func TestCheckUsersSessionsIntegrity(t *testing.T) { ParentId: &userId, ChildId: &session.Id, }, data.Records[0]) - dbmap.Delete(session) + dbmap.Exec(`DELETE FROM Sessions WHERE Id=?`, session.Id) }) }) } @@ -1515,7 +1516,7 @@ func TestCheckUsersSessionsIntegrity(t *testing.T) { func TestCheckUsersStatusIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersStatusIntegrity(store) @@ -1528,7 +1529,7 @@ func TestCheckUsersStatusIntegrity(t *testing.T) { user := createUser(ss) userId := user.Id status := createStatus(ss, user.Id) - dbmap.Delete(user) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, user.Id) result := checkUsersStatusIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -1536,7 +1537,7 @@ func TestCheckUsersStatusIntegrity(t *testing.T) { require.Equal(t, model.OrphanedRecord{ ParentId: &userId, }, data.Records[0]) - dbmap.Delete(status) + dbmap.Exec(`DELETE FROM Status WHERE Id=?`, status.UserId) }) }) } @@ -1544,7 +1545,7 @@ func TestCheckUsersStatusIntegrity(t *testing.T) { func TestCheckUsersTeamMembersIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersTeamMembersIntegrity(store) @@ -1557,7 +1558,7 @@ func TestCheckUsersTeamMembersIntegrity(t *testing.T) { user := createUser(ss) team := createTeam(ss) member := createTeamMember(ss, team.Id, user.Id) - dbmap.Delete(user) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, user.Id) result := checkUsersTeamMembersIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) @@ -1566,7 +1567,7 @@ func TestCheckUsersTeamMembersIntegrity(t *testing.T) { ParentId: &member.UserId, }, data.Records[0]) ss.Team().RemoveAllMembersByTeam(member.TeamId) - dbmap.Delete(team) + dbmap.Exec(`DELETE FROM Teams WHERE Id=?`, team.Id) }) }) } @@ -1574,7 +1575,7 @@ func TestCheckUsersTeamMembersIntegrity(t *testing.T) { func TestCheckUsersUserAccessTokensIntegrity(t *testing.T) { StoreTest(t, func(t *testing.T, ss store.Store) { store := ss.(*SqlStore) - dbmap := store.GetMaster() + dbmap := store.GetMasterX() t.Run("should generate a report with no records", func(t *testing.T) { result := checkUsersUserAccessTokensIntegrity(store) @@ -1587,7 +1588,7 @@ func TestCheckUsersUserAccessTokensIntegrity(t *testing.T) { user := createUser(ss) userId := user.Id uat := createUserAccessToken(ss, user.Id) - dbmap.Delete(user) + dbmap.Exec(`DELETE FROM Users WHERE Id=?`, user.Id) result := checkUsersUserAccessTokensIntegrity(store) require.NoError(t, result.Err) data := result.Data.(model.RelationalIntegrityCheckData) diff --git a/store/sqlstore/job_store.go b/store/sqlstore/job_store.go index 6c5b0e08a8..99152d15ca 100644 --- a/store/sqlstore/job_store.go +++ b/store/sqlstore/job_store.go @@ -26,17 +26,7 @@ type SqlJobStore struct { } func newSqlJobStore(sqlStore *SqlStore) store.JobStore { - s := &SqlJobStore{sqlStore} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.Job{}, "Jobs").SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("Type").SetMaxSize(32) - table.ColMap("Status").SetMaxSize(32) - table.ColMap("Data").SetDataType(sqlStore.jsonDataType()) - } - - return s + return &SqlJobStore{sqlStore} } func (jss SqlJobStore) Save(job *model.Job) (*model.Job, error) { diff --git a/store/sqlstore/license_store.go b/store/sqlstore/license_store.go index b40c8b4de4..d7e61bb98c 100644 --- a/store/sqlstore/license_store.go +++ b/store/sqlstore/license_store.go @@ -18,15 +18,7 @@ type SqlLicenseStore struct { } func newSqlLicenseStore(sqlStore *SqlStore) store.LicenseStore { - ls := &SqlLicenseStore{sqlStore} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.LicenseRecord{}, "Licenses").SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("Bytes").SetMaxSize(10000) - } - - return ls + return &SqlLicenseStore{sqlStore} } // Save validates and stores the license instance in the database. The Id diff --git a/store/sqlstore/link_metadata_store.go b/store/sqlstore/link_metadata_store.go index 86608b7c7a..a935e12a43 100644 --- a/store/sqlstore/link_metadata_store.go +++ b/store/sqlstore/link_metadata_store.go @@ -19,16 +19,7 @@ type SqlLinkMetadataStore struct { } func newSqlLinkMetadataStore(sqlStore *SqlStore) store.LinkMetadataStore { - s := &SqlLinkMetadataStore{sqlStore} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.LinkMetadata{}, "LinkMetadata").SetKeys(false, "Hash") - table.ColMap("URL").SetMaxSize(2048) - table.ColMap("Type").SetMaxSize(16) - table.ColMap("Data").SetDataType(sqlStore.jsonDataType()) - } - - return s + return &SqlLinkMetadataStore{sqlStore} } func (s SqlLinkMetadataStore) Save(metadata *model.LinkMetadata) (*model.LinkMetadata, error) { diff --git a/store/sqlstore/oauth_store.go b/store/sqlstore/oauth_store.go index b0435b137e..4bcad0b91a 100644 --- a/store/sqlstore/oauth_store.go +++ b/store/sqlstore/oauth_store.go @@ -18,38 +18,7 @@ type SqlOAuthStore struct { } func newSqlOAuthStore(sqlStore *SqlStore) store.OAuthStore { - as := &SqlOAuthStore{sqlStore} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.OAuthApp{}, "OAuthApps").SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("CreatorId").SetMaxSize(26) - table.ColMap("ClientSecret").SetMaxSize(128) - table.ColMap("Name").SetMaxSize(64) - table.ColMap("Description").SetMaxSize(512) - table.ColMap("CallbackUrls").SetMaxSize(1024) - table.ColMap("Homepage").SetMaxSize(256) - table.ColMap("IconURL").SetMaxSize(512) - - tableAuth := db.AddTableWithName(model.AuthData{}, "OAuthAuthData").SetKeys(false, "Code") - tableAuth.ColMap("UserId").SetMaxSize(26) - tableAuth.ColMap("ClientId").SetMaxSize(26) - tableAuth.ColMap("Code").SetMaxSize(128) - tableAuth.ColMap("RedirectUri").SetMaxSize(256) - tableAuth.ColMap("State").SetMaxSize(1024) - tableAuth.ColMap("Scope").SetMaxSize(128) - - tableAccess := db.AddTableWithName(model.AccessData{}, "OAuthAccessData").SetKeys(false, "Token") - tableAccess.ColMap("ClientId").SetMaxSize(26) - tableAccess.ColMap("UserId").SetMaxSize(26) - tableAccess.ColMap("Token").SetMaxSize(26) - tableAccess.ColMap("RefreshToken").SetMaxSize(26) - tableAccess.ColMap("RedirectUri").SetMaxSize(256) - tableAccess.ColMap("Scope").SetMaxSize(128) - tableAccess.SetUniqueTogether("ClientId", "UserId") - } - - return as + return &SqlOAuthStore{sqlStore} } func (as SqlOAuthStore) SaveApp(app *model.OAuthApp) (*model.OAuthApp, error) { diff --git a/store/sqlstore/plugin_store.go b/store/sqlstore/plugin_store.go index 624be3487d..d0cda29b48 100644 --- a/store/sqlstore/plugin_store.go +++ b/store/sqlstore/plugin_store.go @@ -24,16 +24,7 @@ type SqlPluginStore struct { } func newSqlPluginStore(sqlStore *SqlStore) store.PluginStore { - s := &SqlPluginStore{sqlStore} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.PluginKeyValue{}, "PluginKeyValueStore").SetKeys(false, "PluginId", "Key") - table.ColMap("PluginId").SetMaxSize(190) - table.ColMap("Key").SetMaxSize(150) - table.ColMap("Value").SetMaxSize(8192) - } - - return s + return &SqlPluginStore{sqlStore} } func (ps SqlPluginStore) SaveOrUpdate(kv *model.PluginKeyValue) (*model.PluginKeyValue, error) { diff --git a/store/sqlstore/post_store.go b/store/sqlstore/post_store.go index 55217a71ec..8609b683bf 100644 --- a/store/sqlstore/post_store.go +++ b/store/sqlstore/post_store.go @@ -125,29 +125,11 @@ func postSliceCoalesceQuery() string { } func newSqlPostStore(sqlStore *SqlStore, metrics einterfaces.MetricsInterface) store.PostStore { - s := &SqlPostStore{ + return &SqlPostStore{ SqlStore: sqlStore, metrics: metrics, maxPostSizeCached: model.PostMessageMaxRunesV1, } - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.Post{}, "Posts").SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("UserId").SetMaxSize(26) - table.ColMap("ChannelId").SetMaxSize(26) - table.ColMap("RootId").SetMaxSize(26) - table.ColMap("OriginalId").SetMaxSize(26) - table.ColMap("Message").SetMaxSize(model.PostMessageMaxBytesV2) - table.ColMap("Type").SetMaxSize(26) - table.ColMap("Hashtags").SetMaxSize(1000) - table.ColMap("Props").SetDataType(sqlStore.jsonDataType()) - table.ColMap("Filenames").SetMaxSize(model.PostFilenamesMaxRunes) - table.ColMap("FileIds").SetMaxSize(model.PostFileidsMaxRunes) - table.ColMap("RemoteId").SetMaxSize(26) - } - - return s } func (s *SqlPostStore) SaveMultiple(posts []*model.Post) ([]*model.Post, int, error) { diff --git a/store/sqlstore/preference_store.go b/store/sqlstore/preference_store.go index a9f5707794..68d0c4e5cd 100644 --- a/store/sqlstore/preference_store.go +++ b/store/sqlstore/preference_store.go @@ -18,15 +18,6 @@ type SqlPreferenceStore struct { func newSqlPreferenceStore(sqlStore *SqlStore) store.PreferenceStore { s := &SqlPreferenceStore{sqlStore} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.Preference{}, "Preferences").SetKeys(false, "UserId", "Category", "Name") - table.ColMap("UserId").SetMaxSize(26) - table.ColMap("Category").SetMaxSize(32) - table.ColMap("Name").SetMaxSize(32) - table.ColMap("Value").SetMaxSize(2000) - } - return s } diff --git a/store/sqlstore/product_notices_store.go b/store/sqlstore/product_notices_store.go index eb75ddb728..8e146ef214 100644 --- a/store/sqlstore/product_notices_store.go +++ b/store/sqlstore/product_notices_store.go @@ -18,15 +18,7 @@ type SqlProductNoticesStore struct { } func newSqlProductNoticesStore(sqlStore *SqlStore) store.ProductNoticesStore { - s := SqlProductNoticesStore{sqlStore} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.ProductNoticeViewState{}, "ProductNoticeViewState").SetKeys(false, "UserId", "NoticeId") - table.ColMap("UserId").SetMaxSize(26) - table.ColMap("NoticeId").SetMaxSize(26) - } - - return s + return &SqlProductNoticesStore{sqlStore} } func (s SqlProductNoticesStore) Clear(notices []string) error { diff --git a/store/sqlstore/reaction_store.go b/store/sqlstore/reaction_store.go index e238a02747..1c6746dd87 100644 --- a/store/sqlstore/reaction_store.go +++ b/store/sqlstore/reaction_store.go @@ -18,17 +18,7 @@ type SqlReactionStore struct { } func newSqlReactionStore(sqlStore *SqlStore) store.ReactionStore { - s := &SqlReactionStore{sqlStore} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.Reaction{}, "Reactions").SetKeys(false, "PostId", "UserId", "EmojiName") - table.ColMap("UserId").SetMaxSize(26) - table.ColMap("PostId").SetMaxSize(26) - table.ColMap("EmojiName").SetMaxSize(64) - table.ColMap("RemoteId").SetMaxSize(26) - } - - return s + return &SqlReactionStore{sqlStore} } func (s *SqlReactionStore) Save(reaction *model.Reaction) (*model.Reaction, error) { diff --git a/store/sqlstore/remote_cluster_store.go b/store/sqlstore/remote_cluster_store.go index 335f9eb87b..9fc518658e 100644 --- a/store/sqlstore/remote_cluster_store.go +++ b/store/sqlstore/remote_cluster_store.go @@ -19,21 +19,7 @@ type sqlRemoteClusterStore struct { } func newSqlRemoteClusterStore(sqlStore *SqlStore) store.RemoteClusterStore { - s := &sqlRemoteClusterStore{sqlStore} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.RemoteCluster{}, "RemoteClusters").SetKeys(false, "RemoteId", "Name") - table.ColMap("RemoteId").SetMaxSize(26) - table.ColMap("RemoteTeamId").SetMaxSize(26) - table.ColMap("Name").SetMaxSize(64) - table.ColMap("DisplayName").SetMaxSize(64) - table.ColMap("SiteURL").SetMaxSize(512) - table.ColMap("Token").SetMaxSize(26) - table.ColMap("RemoteToken").SetMaxSize(26) - table.ColMap("Topics").SetMaxSize(512) - table.ColMap("CreatorId").SetMaxSize(26) - } - return s + return &sqlRemoteClusterStore{sqlStore} } func (s sqlRemoteClusterStore) Save(remoteCluster *model.RemoteCluster) (*model.RemoteCluster, error) { diff --git a/store/sqlstore/retention_policy_store.go b/store/sqlstore/retention_policy_store.go index 554521989d..6b1891897a 100644 --- a/store/sqlstore/retention_policy_store.go +++ b/store/sqlstore/retention_policy_store.go @@ -24,29 +24,10 @@ type SqlRetentionPolicyStore struct { } func newSqlRetentionPolicyStore(sqlStore *SqlStore, metrics einterfaces.MetricsInterface) store.RetentionPolicyStore { - s := &SqlRetentionPolicyStore{ + return &SqlRetentionPolicyStore{ SqlStore: sqlStore, metrics: metrics, } - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.RetentionPolicy{}, "RetentionPolicies") - table.SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("DisplayName").SetMaxSize(64) - - tableC := db.AddTableWithName(model.RetentionPolicyChannel{}, "RetentionPoliciesChannels") - tableC.SetKeys(false, "ChannelId") - tableC.ColMap("PolicyId").SetMaxSize(26) - tableC.ColMap("ChannelId").SetMaxSize(26) - - tableT := db.AddTableWithName(model.RetentionPolicyTeam{}, "RetentionPoliciesTeams") - tableT.SetKeys(false, "TeamId") - tableT.ColMap("PolicyId").SetMaxSize(26) - tableT.ColMap("TeamId").SetMaxSize(26) - } - - return s } // executePossiblyEmptyQuery only executes the query if it is non-empty. This helps avoid diff --git a/store/sqlstore/role_store.go b/store/sqlstore/role_store.go index fda0ac483e..9d8c91c468 100644 --- a/store/sqlstore/role_store.go +++ b/store/sqlstore/role_store.go @@ -83,17 +83,7 @@ func (role Role) ToModel() *model.Role { } func newSqlRoleStore(sqlStore *SqlStore) store.RoleStore { - s := &SqlRoleStore{sqlStore} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(Role{}, "Roles").SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("Name").SetMaxSize(64).SetUnique(true) - table.ColMap("DisplayName").SetMaxSize(128) - table.ColMap("Description").SetMaxSize(1024) - table.ColMap("Permissions") - } - return s + return &SqlRoleStore{sqlStore} } func (s *SqlRoleStore) Save(role *model.Role) (*model.Role, error) { diff --git a/store/sqlstore/scheme_store.go b/store/sqlstore/scheme_store.go index 19b401b55a..856262d9b8 100644 --- a/store/sqlstore/scheme_store.go +++ b/store/sqlstore/scheme_store.go @@ -19,28 +19,7 @@ type SqlSchemeStore struct { } func newSqlSchemeStore(sqlStore *SqlStore) store.SchemeStore { - s := &SqlSchemeStore{sqlStore} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.Scheme{}, "Schemes").SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("Name").SetMaxSize(model.SchemeNameMaxLength).SetUnique(true) - table.ColMap("DisplayName").SetMaxSize(model.SchemeDisplayNameMaxLength) - table.ColMap("Description").SetMaxSize(model.SchemeDescriptionMaxLength) - table.ColMap("Scope").SetMaxSize(32) - table.ColMap("DefaultTeamAdminRole").SetMaxSize(64) - table.ColMap("DefaultTeamUserRole").SetMaxSize(64) - table.ColMap("DefaultTeamGuestRole").SetMaxSize(64) - table.ColMap("DefaultChannelAdminRole").SetMaxSize(64) - table.ColMap("DefaultChannelUserRole").SetMaxSize(64) - table.ColMap("DefaultChannelGuestRole").SetMaxSize(64) - table.ColMap("DefaultPlaybookAdminRole").SetMaxSize(64).SetDefaultConstraint(model.NewString("")) - table.ColMap("DefaultPlaybookMemberRole").SetMaxSize(64).SetDefaultConstraint(model.NewString("")) - table.ColMap("DefaultRunAdminRole").SetMaxSize(64).SetDefaultConstraint(model.NewString("")) - table.ColMap("DefaultRunMemberRole").SetMaxSize(64).SetDefaultConstraint(model.NewString("")) - } - - return s + return &SqlSchemeStore{sqlStore} } func (s *SqlSchemeStore) Save(scheme *model.Scheme) (*model.Scheme, error) { diff --git a/store/sqlstore/session_store.go b/store/sqlstore/session_store.go index 66099a2027..94636706d8 100644 --- a/store/sqlstore/session_store.go +++ b/store/sqlstore/session_store.go @@ -25,19 +25,7 @@ type SqlSessionStore struct { } func newSqlSessionStore(sqlStore *SqlStore) store.SessionStore { - us := &SqlSessionStore{sqlStore} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.Session{}, "Sessions").SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("Token").SetMaxSize(26) - table.ColMap("UserId").SetMaxSize(26) - table.ColMap("DeviceId").SetMaxSize(512) - table.ColMap("Roles").SetMaxSize(model.UserRolesMaxLength) - table.ColMap("Props").SetDataType(sqlStore.jsonDataType()) - } - - return us + return &SqlSessionStore{sqlStore} } func (me SqlSessionStore) Save(session *model.Session) (*model.Session, error) { diff --git a/store/sqlstore/shared_channel_store.go b/store/sqlstore/shared_channel_store.go index 35561e65cb..4799711546 100644 --- a/store/sqlstore/shared_channel_store.go +++ b/store/sqlstore/shared_channel_store.go @@ -23,45 +23,9 @@ type SqlSharedChannelStore struct { } func newSqlSharedChannelStore(sqlStore *SqlStore) store.SharedChannelStore { - s := &SqlSharedChannelStore{ + return &SqlSharedChannelStore{ SqlStore: sqlStore, } - - for _, db := range sqlStore.GetAllConns() { - tableSharedChannels := db.AddTableWithName(model.SharedChannel{}, "SharedChannels").SetKeys(false, "ChannelId") - tableSharedChannels.ColMap("ChannelId").SetMaxSize(26) - tableSharedChannels.ColMap("TeamId").SetMaxSize(26) - tableSharedChannels.ColMap("CreatorId").SetMaxSize(26) - tableSharedChannels.ColMap("ShareName").SetMaxSize(64) - tableSharedChannels.SetUniqueTogether("ShareName", "TeamId") - tableSharedChannels.ColMap("ShareDisplayName").SetMaxSize(64) - tableSharedChannels.ColMap("SharePurpose").SetMaxSize(250) - tableSharedChannels.ColMap("ShareHeader").SetMaxSize(1024) - tableSharedChannels.ColMap("RemoteId").SetMaxSize(26) - - tableSharedChannelRemotes := db.AddTableWithName(model.SharedChannelRemote{}, "SharedChannelRemotes").SetKeys(false, "Id", "ChannelId") - tableSharedChannelRemotes.ColMap("Id").SetMaxSize(26) - tableSharedChannelRemotes.ColMap("ChannelId").SetMaxSize(26) - tableSharedChannelRemotes.ColMap("CreatorId").SetMaxSize(26) - tableSharedChannelRemotes.ColMap("RemoteId").SetMaxSize(26) - tableSharedChannelRemotes.ColMap("LastPostId").SetMaxSize(26) - tableSharedChannelRemotes.SetUniqueTogether("ChannelId", "RemoteId") - - tableSharedChannelUsers := db.AddTableWithName(model.SharedChannelUser{}, "SharedChannelUsers").SetKeys(false, "Id") - tableSharedChannelUsers.ColMap("Id").SetMaxSize(26) - tableSharedChannelUsers.ColMap("UserId").SetMaxSize(26) - tableSharedChannelUsers.ColMap("RemoteId").SetMaxSize(26) - tableSharedChannelUsers.ColMap("ChannelId").SetMaxSize(26) - tableSharedChannelUsers.SetUniqueTogether("UserId", "ChannelId", "RemoteId") - - tableSharedChannelFiles := db.AddTableWithName(model.SharedChannelAttachment{}, "SharedChannelAttachments").SetKeys(false, "Id") - tableSharedChannelFiles.ColMap("Id").SetMaxSize(26) - tableSharedChannelFiles.ColMap("FileId").SetMaxSize(26) - tableSharedChannelFiles.ColMap("RemoteId").SetMaxSize(26) - tableSharedChannelFiles.SetUniqueTogether("FileId", "RemoteId") - } - - return s } // Save inserts a new shared channel record. diff --git a/store/sqlstore/status_store.go b/store/sqlstore/status_store.go index e68091542e..8f97e862a3 100644 --- a/store/sqlstore/status_store.go +++ b/store/sqlstore/status_store.go @@ -20,17 +20,7 @@ type SqlStatusStore struct { } func newSqlStatusStore(sqlStore *SqlStore) store.StatusStore { - s := &SqlStatusStore{sqlStore} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.Status{}, "Status").SetKeys(false, "UserId") - table.ColMap("UserId").SetMaxSize(26) - table.ColMap("Status").SetMaxSize(32) - table.ColMap("ActiveChannel").SetMaxSize(26) - table.ColMap("PrevStatus").SetMaxSize(32) - } - - return s + return &SqlStatusStore{sqlStore} } func (s SqlStatusStore) SaveOrUpdate(st *model.Status) error { diff --git a/store/sqlstore/store.go b/store/sqlstore/store.go index 121e2001cb..82cbcb5b3c 100644 --- a/store/sqlstore/store.go +++ b/store/sqlstore/store.go @@ -934,7 +934,25 @@ func (ss *SqlStore) SharedChannel() store.SharedChannelStore { } func (ss *SqlStore) DropAllTables() { - ss.master.TruncateTables() + if ss.DriverName() == model.DatabaseDriverPostgres { + ss.masterX.Exec(`DO + $func$ + BEGIN + EXECUTE + (SELECT 'TRUNCATE TABLE ' || string_agg(oid::regclass::text, ', ') || ' CASCADE' + FROM pg_class + WHERE relkind = 'r' -- only tables + AND relnamespace = 'public'::regnamespace + ); + END + $func$;`) + } else { + tables := []string{} + ss.masterX.Select(&tables, `show tables`) + for _, t := range tables { + ss.masterX.Exec(`TRUNCATE TABLE ` + t) + } + } } func (ss *SqlStore) getQueryBuilder() sq.StatementBuilderType { @@ -1160,13 +1178,6 @@ func versionString(v int, driver string) string { return "" } -func (ss *SqlStore) jsonDataType() string { - if ss.DriverName() == model.DatabaseDriverPostgres { - return "jsonb" - } - return "json" -} - func (ss *SqlStore) toReserveCase(str string) string { if ss.DriverName() == model.DatabaseDriverPostgres { return fmt.Sprintf("%q", str) diff --git a/store/sqlstore/store_test.go b/store/sqlstore/store_test.go index 856da8182e..88b52a7804 100644 --- a/store/sqlstore/store_test.go +++ b/store/sqlstore/store_test.go @@ -686,7 +686,7 @@ func TestReplicaLagQuery(t *testing.T) { store.initConnection() store.stores.post = newSqlPostStore(store, mockMetrics) - err := store.GetMaster().CreateTablesIfNotExists() + err := store.migrate(migrationsDirectionUp) require.NoError(t, err) defer store.Close() diff --git a/store/sqlstore/system_store.go b/store/sqlstore/system_store.go index 56edc5bcd9..c7b40afd6d 100644 --- a/store/sqlstore/system_store.go +++ b/store/sqlstore/system_store.go @@ -23,15 +23,7 @@ type SqlSystemStore struct { } func newSqlSystemStore(sqlStore *SqlStore) store.SystemStore { - s := &SqlSystemStore{sqlStore} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.System{}, "Systems").SetKeys(false, "Name") - table.ColMap("Name").SetMaxSize(64) - table.ColMap("Value").SetMaxSize(1024) - } - - return s + return &SqlSystemStore{sqlStore} } func (s SqlSystemStore) Save(system *model.System) error { diff --git a/store/sqlstore/team_store.go b/store/sqlstore/team_store.go index d200ba3c00..3a062040e1 100644 --- a/store/sqlstore/team_store.go +++ b/store/sqlstore/team_store.go @@ -209,26 +209,6 @@ func newSqlTeamStore(sqlStore *SqlStore) store.TeamStore { s.teamsQuery = s.getQueryBuilder(). Select("Teams.*"). From("Teams") - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.Team{}, "Teams").SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("DisplayName").SetMaxSize(64) - table.ColMap("Name").SetMaxSize(64).SetUnique(true) - table.ColMap("Description").SetMaxSize(255) - table.ColMap("Type").SetMaxSize(255) - table.ColMap("Email").SetMaxSize(128) - table.ColMap("CompanyName").SetMaxSize(64) - table.ColMap("AllowedDomains").SetMaxSize(1000) - table.ColMap("InviteId").SetMaxSize(32) - table.ColMap("SchemeId").SetMaxSize(26) - - tablem := db.AddTableWithName(teamMember{}, "TeamMembers").SetKeys(false, "TeamId", "UserId") - tablem.ColMap("TeamId").SetMaxSize(26) - tablem.ColMap("UserId").SetMaxSize(26) - tablem.ColMap("Roles").SetMaxSize(model.UserRolesMaxLength) - } - return s } diff --git a/store/sqlstore/terms_of_service_store.go b/store/sqlstore/terms_of_service_store.go index 17ab2b80e7..7c2845458b 100644 --- a/store/sqlstore/terms_of_service_store.go +++ b/store/sqlstore/terms_of_service_store.go @@ -18,16 +18,7 @@ type SqlTermsOfServiceStore struct { } func newSqlTermsOfServiceStore(sqlStore *SqlStore, metrics einterfaces.MetricsInterface) store.TermsOfServiceStore { - s := SqlTermsOfServiceStore{sqlStore, metrics} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.TermsOfService{}, "TermsOfService").SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("UserId").SetMaxSize(26) - table.ColMap("Text").SetMaxSize(model.PostMessageMaxBytesV2) - } - - return s + return SqlTermsOfServiceStore{sqlStore, metrics} } func (s SqlTermsOfServiceStore) Save(termsOfService *model.TermsOfService) (*model.TermsOfService, error) { diff --git a/store/sqlstore/thread_store.go b/store/sqlstore/thread_store.go index 72d9cbdbf0..f0e8aea333 100644 --- a/store/sqlstore/thread_store.go +++ b/store/sqlstore/thread_store.go @@ -26,21 +26,9 @@ func (s *SqlThreadStore) ClearCaches() { } func newSqlThreadStore(sqlStore *SqlStore) store.ThreadStore { - s := &SqlThreadStore{ + return &SqlThreadStore{ SqlStore: sqlStore, } - - for _, db := range sqlStore.GetAllConns() { - tableThreads := db.AddTableWithName(model.Thread{}, "Threads").SetKeys(false, "PostId") - tableThreads.ColMap("PostId").SetMaxSize(26) - tableThreads.ColMap("ChannelId").SetMaxSize(26) - tableThreads.ColMap("Participants").SetDataType(sqlStore.jsonDataType()) - tableThreadMemberships := db.AddTableWithName(model.ThreadMembership{}, "ThreadMemberships").SetKeys(false, "PostId", "UserId") - tableThreadMemberships.ColMap("PostId").SetMaxSize(26) - tableThreadMemberships.ColMap("UserId").SetMaxSize(26) - } - - return s } func threadSliceColumns() []string { diff --git a/store/sqlstore/tokens_store.go b/store/sqlstore/tokens_store.go index 21e8baad39..a2971eb324 100644 --- a/store/sqlstore/tokens_store.go +++ b/store/sqlstore/tokens_store.go @@ -20,16 +20,7 @@ type SqlTokenStore struct { } func newSqlTokenStore(sqlStore *SqlStore) store.TokenStore { - s := &SqlTokenStore{sqlStore} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.Token{}, "Tokens").SetKeys(false, "Token") - table.ColMap("Token").SetMaxSize(64) - table.ColMap("Type").SetMaxSize(64) - table.ColMap("Extra").SetMaxSize(2048) - } - - return s + return &SqlTokenStore{sqlStore} } func (s SqlTokenStore) Save(token *model.Token) error { diff --git a/store/sqlstore/upload_session_store.go b/store/sqlstore/upload_session_store.go index b994dae01d..6860f3fddb 100644 --- a/store/sqlstore/upload_session_store.go +++ b/store/sqlstore/upload_session_store.go @@ -18,21 +18,9 @@ type SqlUploadSessionStore struct { } func newSqlUploadSessionStore(sqlStore *SqlStore) store.UploadSessionStore { - s := &SqlUploadSessionStore{ + return &SqlUploadSessionStore{ SqlStore: sqlStore, } - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.UploadSession{}, "UploadSessions").SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("Type").SetMaxSize(32) - table.ColMap("UserId").SetMaxSize(26) - table.ColMap("ChannelId").SetMaxSize(26) - table.ColMap("Filename").SetMaxSize(256) - table.ColMap("Path").SetMaxSize(512) - table.ColMap("RemoteId").SetMaxSize(26) - table.ColMap("ReqFileId").SetMaxSize(26) - } - return s } func (us SqlUploadSessionStore) Save(session *model.UploadSession) (*model.UploadSession, error) { diff --git a/store/sqlstore/user_access_token_store.go b/store/sqlstore/user_access_token_store.go index 13b510c4d8..3b4f5b57e7 100644 --- a/store/sqlstore/user_access_token_store.go +++ b/store/sqlstore/user_access_token_store.go @@ -18,17 +18,7 @@ type SqlUserAccessTokenStore struct { } func newSqlUserAccessTokenStore(sqlStore *SqlStore) store.UserAccessTokenStore { - s := &SqlUserAccessTokenStore{sqlStore} - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.UserAccessToken{}, "UserAccessTokens").SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("Token").SetMaxSize(26).SetUnique(true) - table.ColMap("UserId").SetMaxSize(26) - table.ColMap("Description").SetMaxSize(512) - } - - return s + return &SqlUserAccessTokenStore{sqlStore} } func (s SqlUserAccessTokenStore) Save(token *model.UserAccessToken) (*model.UserAccessToken, error) { diff --git a/store/sqlstore/user_store.go b/store/sqlstore/user_store.go index b9f55167a0..5b459b2fb9 100644 --- a/store/sqlstore/user_store.go +++ b/store/sqlstore/user_store.go @@ -56,27 +56,6 @@ func newSqlUserStore(sqlStore *SqlStore, metrics einterfaces.MetricsInterface) s From("Users u"). LeftJoin("Bots b ON ( b.UserId = u.Id )") - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.User{}, "Users").SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("Username").SetMaxSize(64).SetUnique(true) - table.ColMap("Password").SetMaxSize(128) - table.ColMap("AuthData").SetMaxSize(128).SetUnique(true) - table.ColMap("AuthService").SetMaxSize(32) - table.ColMap("Email").SetMaxSize(128).SetUnique(true) - table.ColMap("Nickname").SetMaxSize(64) - table.ColMap("FirstName").SetMaxSize(64) - table.ColMap("LastName").SetMaxSize(64) - table.ColMap("Roles").SetMaxSize(model.UserRolesMaxLength) - table.ColMap("Props").SetDataType(sqlStore.jsonDataType()) - table.ColMap("NotifyProps").SetDataType(sqlStore.jsonDataType()) - table.ColMap("Locale").SetMaxSize(5) - table.ColMap("MfaSecret").SetMaxSize(128) - table.ColMap("RemoteId").SetMaxSize(26) - table.ColMap("Position").SetMaxSize(128) - table.ColMap("Timezone").SetDataType(sqlStore.jsonDataType()) - } - return us } diff --git a/store/sqlstore/webhook_store.go b/store/sqlstore/webhook_store.go index 484905a388..0a72d4058a 100644 --- a/store/sqlstore/webhook_store.go +++ b/store/sqlstore/webhook_store.go @@ -23,39 +23,10 @@ func (s SqlWebhookStore) ClearCaches() { } func newSqlWebhookStore(sqlStore *SqlStore, metrics einterfaces.MetricsInterface) store.WebhookStore { - s := &SqlWebhookStore{ + return &SqlWebhookStore{ SqlStore: sqlStore, metrics: metrics, } - - for _, db := range sqlStore.GetAllConns() { - table := db.AddTableWithName(model.IncomingWebhook{}, "IncomingWebhooks").SetKeys(false, "Id") - table.ColMap("Id").SetMaxSize(26) - table.ColMap("UserId").SetMaxSize(26) - table.ColMap("ChannelId").SetMaxSize(26) - table.ColMap("TeamId").SetMaxSize(26) - table.ColMap("DisplayName").SetMaxSize(64) - table.ColMap("Description").SetMaxSize(500) - table.ColMap("Username").SetMaxSize(255) - table.ColMap("IconURL").SetMaxSize(1024) - - tableo := db.AddTableWithName(model.OutgoingWebhook{}, "OutgoingWebhooks").SetKeys(false, "Id") - tableo.ColMap("Id").SetMaxSize(26) - tableo.ColMap("Token").SetMaxSize(26) - tableo.ColMap("CreatorId").SetMaxSize(26) - tableo.ColMap("ChannelId").SetMaxSize(26) - tableo.ColMap("TeamId").SetMaxSize(26) - tableo.ColMap("TriggerWords").SetMaxSize(1024) - tableo.ColMap("CallbackURLs").SetMaxSize(1024) - tableo.ColMap("DisplayName").SetMaxSize(64) - tableo.ColMap("Description").SetMaxSize(500) - tableo.ColMap("ContentType").SetMaxSize(128) - tableo.ColMap("TriggerWhen").SetMaxSize(1) - tableo.ColMap("Username").SetMaxSize(64) - tableo.ColMap("IconURL").SetMaxSize(1024) - } - - return s } func (s SqlWebhookStore) InvalidateWebhookCache(webhookId string) {