s/Get(Master|Replica)X/Get\1/g (#29520)
Drop the legacy `X` suffix from `GetMasterX` and `GetReplicaX`. The presence of the suffix suggests there's a `non-X` version: but in fact we migrated these away a long time ago, so remove the cognitive overhead. As an aside, this additionally helps avoid trip up LLMs that interpret this as "something to fix".
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
8b86e1276e
Коммит
5369f8b36b
@@ -129,10 +129,10 @@ func TestGetSidebarCategories(t *testing.T) {
|
||||
|
||||
// Temporarily renaming a table to force a DB error.
|
||||
sqlStore := mainHelper.GetSQLStore()
|
||||
_, err := sqlStore.GetMasterX().Exec("ALTER TABLE SidebarCategories RENAME TO SidebarCategoriesTest")
|
||||
_, err := sqlStore.GetMaster().Exec("ALTER TABLE SidebarCategories RENAME TO SidebarCategoriesTest")
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
_, err := sqlStore.GetMasterX().Exec("ALTER TABLE SidebarCategoriesTest RENAME TO SidebarCategories")
|
||||
_, err := sqlStore.GetMaster().Exec("ALTER TABLE SidebarCategoriesTest RENAME TO SidebarCategories")
|
||||
require.NoError(t, err)
|
||||
}()
|
||||
|
||||
|
||||
@@ -95,12 +95,12 @@ func TestEnsureInstallationDate(t *testing.T) {
|
||||
for _, tc := range tt {
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
sqlStore := th.GetSqlStore()
|
||||
sqlStore.GetMasterX().Exec("DELETE FROM Users")
|
||||
sqlStore.GetMaster().Exec("DELETE FROM Users")
|
||||
|
||||
for _, createAt := range tc.UsersCreationDates {
|
||||
user := th.CreateUser()
|
||||
user.CreateAt = createAt
|
||||
sqlStore.GetMasterX().Exec("UPDATE Users SET CreateAt = ? WHERE Id = ?", createAt, user.Id)
|
||||
sqlStore.GetMaster().Exec("UPDATE Users SET CreateAt = ? WHERE Id = ?", createAt, user.Id)
|
||||
}
|
||||
|
||||
if tc.PrevInstallationDate == nil {
|
||||
@@ -125,7 +125,7 @@ func TestEnsureInstallationDate(t *testing.T) {
|
||||
assert.True(t, *tc.ExpectedInstallationDate <= value && *tc.ExpectedInstallationDate+1000 >= value)
|
||||
}
|
||||
|
||||
sqlStore.GetMasterX().Exec("DELETE FROM Users")
|
||||
sqlStore.GetMaster().Exec("DELETE FROM Users")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -651,34 +651,34 @@ func (th *TestHelper) ConfigureInbucketMail() {
|
||||
|
||||
func (*TestHelper) ResetRoleMigration() {
|
||||
sqlStore := mainHelper.GetSQLStore()
|
||||
if _, err := sqlStore.GetMasterX().Exec("DELETE from Roles"); err != nil {
|
||||
if _, err := sqlStore.GetMaster().Exec("DELETE from Roles"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
mainHelper.GetClusterInterface().SendClearRoleCacheMessage()
|
||||
|
||||
if _, err := sqlStore.GetMasterX().Exec("DELETE from Systems where Name = ?", model.AdvancedPermissionsMigrationKey); err != nil {
|
||||
if _, err := sqlStore.GetMaster().Exec("DELETE from Systems where Name = ?", model.AdvancedPermissionsMigrationKey); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (*TestHelper) ResetEmojisMigration() {
|
||||
sqlStore := mainHelper.GetSQLStore()
|
||||
if _, err := sqlStore.GetMasterX().Exec("UPDATE Roles SET Permissions=REPLACE(Permissions, ' create_emojis', '') WHERE builtin=True"); err != nil {
|
||||
if _, err := sqlStore.GetMaster().Exec("UPDATE Roles SET Permissions=REPLACE(Permissions, ' create_emojis', '') WHERE builtin=True"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if _, err := sqlStore.GetMasterX().Exec("UPDATE Roles SET Permissions=REPLACE(Permissions, ' delete_emojis', '') WHERE builtin=True"); err != nil {
|
||||
if _, err := sqlStore.GetMaster().Exec("UPDATE Roles SET Permissions=REPLACE(Permissions, ' delete_emojis', '') WHERE builtin=True"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if _, err := sqlStore.GetMasterX().Exec("UPDATE Roles SET Permissions=REPLACE(Permissions, ' delete_others_emojis', '') WHERE builtin=True"); err != nil {
|
||||
if _, err := sqlStore.GetMaster().Exec("UPDATE Roles SET Permissions=REPLACE(Permissions, ' delete_others_emojis', '') WHERE builtin=True"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
mainHelper.GetClusterInterface().SendClearRoleCacheMessage()
|
||||
|
||||
if _, err := sqlStore.GetMasterX().Exec("DELETE from Systems where Name = ?", EmojisPermissionsMigrationKey); err != nil {
|
||||
if _, err := sqlStore.GetMaster().Exec("DELETE from Systems where Name = ?", EmojisPermissionsMigrationKey); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func TestReadReplicaDisabledBasedOnLicense(t *testing.T) {
|
||||
ConfigStore(configStore),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.Same(t, ps.sqlStore.GetMasterX(), ps.sqlStore.GetReplicaX())
|
||||
require.Same(t, ps.sqlStore.GetMaster(), ps.sqlStore.GetReplica())
|
||||
require.Len(t, ps.Config().SqlSettings.DataSourceReplicas, 1)
|
||||
})
|
||||
|
||||
@@ -56,7 +56,7 @@ func TestReadReplicaDisabledBasedOnLicense(t *testing.T) {
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.NotSame(t, ps.sqlStore.GetMasterX(), ps.sqlStore.GetReplicaX())
|
||||
require.NotSame(t, ps.sqlStore.GetMaster(), ps.sqlStore.GetReplica())
|
||||
require.Len(t, ps.Config().SqlSettings.DataSourceReplicas, 1)
|
||||
})
|
||||
|
||||
@@ -68,7 +68,7 @@ func TestReadReplicaDisabledBasedOnLicense(t *testing.T) {
|
||||
ConfigStore(configStore),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.Same(t, ps.sqlStore.GetMasterX(), ps.sqlStore.GetSearchReplicaX())
|
||||
require.Same(t, ps.sqlStore.GetMaster(), ps.sqlStore.GetSearchReplicaX())
|
||||
require.Len(t, ps.Config().SqlSettings.DataSourceSearchReplicas, 1)
|
||||
})
|
||||
|
||||
@@ -84,7 +84,7 @@ func TestReadReplicaDisabledBasedOnLicense(t *testing.T) {
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.NotSame(t, ps.sqlStore.GetMasterX(), ps.sqlStore.GetSearchReplicaX())
|
||||
require.NotSame(t, ps.sqlStore.GetMaster(), ps.sqlStore.GetSearchReplicaX())
|
||||
require.Len(t, ps.Config().SqlSettings.DataSourceSearchReplicas, 1)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
store.GetMasterX().Close()
|
||||
store.GetMaster().Close()
|
||||
|
||||
for _, isMaster := range []bool{true, false} {
|
||||
handle := sql.OpenDB(driver.NewConnector(p.Driver, isMaster))
|
||||
@@ -51,7 +51,7 @@ func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model
|
||||
storetest.TestChannelStore(p.t, rctx, store, wrapper)
|
||||
storetest.TestBotStore(p.t, rctx, store, wrapper)
|
||||
|
||||
store.GetMasterX().Close()
|
||||
store.GetMaster().Close()
|
||||
}
|
||||
|
||||
// Use the API to instantiate the driver
|
||||
|
||||
@@ -982,7 +982,7 @@ func TestCreatePost(t *testing.T) {
|
||||
sqlStore := th.GetSqlStore()
|
||||
sql := fmt.Sprintf("select count(*) from Posts where Id = '%[1]s' or OriginalId = '%[1]s';", previewPost.Id)
|
||||
var val int64
|
||||
err2 := sqlStore.GetMasterX().Get(&val, sql)
|
||||
err2 := sqlStore.GetMaster().Get(&val, sql)
|
||||
require.NoError(t, err2)
|
||||
|
||||
require.EqualValues(t, int64(1), val)
|
||||
|
||||
@@ -1116,7 +1116,7 @@ func TestPermanentDeleteUser(t *testing.T) {
|
||||
bots2 := []*model.Bot{}
|
||||
|
||||
sqlStore := mainHelper.GetSQLStore()
|
||||
err1 := sqlStore.GetMasterX().Select(&bots1, "SELECT * FROM Bots")
|
||||
err1 := sqlStore.GetMaster().Select(&bots1, "SELECT * FROM Bots")
|
||||
assert.NoError(t, err1)
|
||||
assert.Equal(t, 1, len(bots1))
|
||||
|
||||
@@ -1127,7 +1127,7 @@ func TestPermanentDeleteUser(t *testing.T) {
|
||||
err = th.App.PermanentDeleteUser(th.Context, retUser1)
|
||||
assert.Nil(t, err)
|
||||
|
||||
err1 = sqlStore.GetMasterX().Select(&bots2, "SELECT * FROM Bots")
|
||||
err1 = sqlStore.GetMaster().Select(&bots2, "SELECT * FROM Bots")
|
||||
assert.NoError(t, err1)
|
||||
assert.Equal(t, 0, len(bots2))
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ func (s SqlAuditStore) Save(audit *model.Audit) error {
|
||||
audit.Id = model.NewId()
|
||||
audit.CreateAt = model.GetMillis()
|
||||
|
||||
if _, err := s.GetMasterX().NamedExec(`INSERT INTO Audits
|
||||
if _, err := s.GetMaster().NamedExec(`INSERT INTO Audits
|
||||
(Id, CreateAt, UserId, Action, ExtraInfo, IpAddress, SessionId)
|
||||
VALUES
|
||||
(:Id, :CreateAt, :UserId, :Action, :ExtraInfo, :IpAddress, :SessionId)`, audit); err != nil {
|
||||
@@ -54,14 +54,14 @@ func (s SqlAuditStore) Get(userId string, offset int, limit int) (model.Audits,
|
||||
}
|
||||
|
||||
var audits model.Audits
|
||||
if err := s.GetReplicaX().Select(&audits, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&audits, queryString, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get Audit list for userId=%s", userId)
|
||||
}
|
||||
return audits, nil
|
||||
}
|
||||
|
||||
func (s SqlAuditStore) PermanentDeleteByUser(userId string) error {
|
||||
if _, err := s.GetMasterX().Exec("DELETE FROM Audits WHERE UserId = ?", userId); err != nil {
|
||||
if _, err := s.GetMaster().Exec("DELETE FROM Audits WHERE UserId = ?", userId); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete Audit with userId=%s", userId)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -94,7 +94,7 @@ func (us SqlBotStore) Get(botUserId string, includeDeleted bool) (*model.Bot, er
|
||||
`
|
||||
|
||||
var bot model.Bot
|
||||
if err := us.GetReplicaX().Get(&bot, query, botUserId); err == sql.ErrNoRows {
|
||||
if err := us.GetReplica().Get(&bot, query, botUserId); err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Bot", botUserId)
|
||||
} else if err != nil {
|
||||
return nil, errors.Wrapf(err, "selectone: user_id=%s", botUserId)
|
||||
@@ -155,7 +155,7 @@ func (us SqlBotStore) GetAll(options *model.BotGetOptions) ([]*model.Bot, error)
|
||||
args = append(args, options.PerPage, options.Page*options.PerPage)
|
||||
|
||||
bots := []*model.Bot{}
|
||||
if err := us.GetReplicaX().Select(&bots, sql, args...); err != nil {
|
||||
if err := us.GetReplica().Select(&bots, sql, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "error selecting all bots")
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ func (us SqlBotStore) Save(bot *model.Bot) (*model.Bot, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := us.GetMasterX().NamedExec(`INSERT INTO Bots
|
||||
if _, err := us.GetMaster().NamedExec(`INSERT INTO Bots
|
||||
(UserId, Description, OwnerId, LastIconUpdate, CreateAt, UpdateAt, DeleteAt)
|
||||
VALUES
|
||||
(:UserId, :Description, :OwnerId, :LastIconUpdate, :CreateAt, :UpdateAt, :DeleteAt)`, botFromModel(bot)); err != nil {
|
||||
@@ -204,7 +204,7 @@ func (us SqlBotStore) Update(bot *model.Bot) (*model.Bot, error) {
|
||||
oldBot.DeleteAt = bot.DeleteAt
|
||||
bot = oldBot
|
||||
|
||||
res, err := us.GetMasterX().NamedExec(`UPDATE Bots
|
||||
res, err := us.GetMaster().NamedExec(`UPDATE Bots
|
||||
SET Description=:Description, OwnerId=:OwnerId, LastIconUpdate=:LastIconUpdate,
|
||||
UpdateAt=:UpdateAt, DeleteAt=:DeleteAt
|
||||
WHERE UserId=:UserId`, botFromModel(bot))
|
||||
@@ -226,7 +226,7 @@ func (us SqlBotStore) Update(bot *model.Bot) (*model.Bot, error) {
|
||||
// If the corresponding user is to be deleted, it must be done via the user store.
|
||||
func (us SqlBotStore) PermanentDelete(botUserId string) error {
|
||||
query := "DELETE FROM Bots WHERE UserId = ?"
|
||||
if _, err := us.GetMasterX().Exec(query, botUserId); err != nil {
|
||||
if _, err := us.GetMaster().Exec(query, botUserId); err != nil {
|
||||
return store.NewErrInvalidInput("Bot", "UserId", botUserId).Wrap(err)
|
||||
}
|
||||
return nil
|
||||
@@ -241,7 +241,7 @@ func (us SqlBotStore) GetAllAfter(limit int, afterId string) ([]*model.Bot, erro
|
||||
}
|
||||
|
||||
bots := []*model.Bot{}
|
||||
if err := us.GetReplicaX().Select(&bots, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Select(&bots, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Bots")
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ func (us SqlBotStore) GetByUsername(username string) (*model.Bot, error) {
|
||||
}
|
||||
|
||||
bot := model.Bot{}
|
||||
if err := us.GetReplicaX().Get(&bot, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Get(&bot, queryString, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, errors.Wrap(store.NewErrNotFound("Bot", fmt.Sprintf("username=%s", username)), "failed to find Bot")
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ func (s *SqlChannelBookmarkStore) ErrorIfBookmarkFileInfoAlreadyAttached(fileId
|
||||
})
|
||||
|
||||
var attached int64
|
||||
err := s.GetReplicaX().GetBuilder(&attached, alreadyAttachedQuery)
|
||||
err := s.GetReplica().GetBuilder(&attached, alreadyAttachedQuery)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable_to_save_channel_bookmark")
|
||||
}
|
||||
@@ -105,7 +105,7 @@ func (s *SqlChannelBookmarkStore) Get(Id string, includeDeleted bool) (*model.Ch
|
||||
|
||||
bookmark := model.ChannelBookmarkAndFileInfo{}
|
||||
|
||||
if err := s.GetReplicaX().Get(&bookmark, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&bookmark, queryString, args...); err != nil {
|
||||
return nil, store.NewErrNotFound("ChannelBookmark", Id)
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ func (s *SqlChannelBookmarkStore) Save(bookmark *model.ChannelBookmark, increase
|
||||
return nil, err
|
||||
}
|
||||
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -216,7 +216,7 @@ func (s *SqlChannelBookmarkStore) Update(bookmark *model.ChannelBookmark) error
|
||||
return errors.Wrap(err, "channel_bookmark_update_tosql")
|
||||
}
|
||||
|
||||
res, err := s.GetMasterX().Exec(query, args...)
|
||||
res, err := s.GetMaster().Exec(query, args...)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to update channel bookmark with id=%s", bookmark.Id)
|
||||
}
|
||||
@@ -232,7 +232,7 @@ func (s *SqlChannelBookmarkStore) Update(bookmark *model.ChannelBookmark) error
|
||||
|
||||
func (s *SqlChannelBookmarkStore) UpdateSortOrder(bookmarkId, channelId string, newIndex int64) ([]*model.ChannelBookmarkWithFileInfo, error) {
|
||||
now := model.GetMillis()
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -292,7 +292,7 @@ func (s *SqlChannelBookmarkStore) UpdateSortOrder(bookmarkId, channelId string,
|
||||
|
||||
func (s *SqlChannelBookmarkStore) Delete(bookmarkId string, deleteFile bool) error {
|
||||
now := model.GetMillis()
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -368,7 +368,7 @@ func (s *SqlChannelBookmarkStore) GetBookmarksForChannelSince(channelId string,
|
||||
bookmarkRows := []model.ChannelBookmarkAndFileInfo{}
|
||||
bookmarks := []*model.ChannelBookmarkWithFileInfo{}
|
||||
|
||||
if err := s.GetReplicaX().Select(&bookmarkRows, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&bookmarkRows, queryString, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find bookmarks")
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ func (s SqlChannelMemberHistoryStore) LogJoinEvent(userId string, channelId stri
|
||||
JoinTime: joinTime,
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().NamedExec(`INSERT INTO ChannelMemberHistory
|
||||
if _, err := s.GetMaster().NamedExec(`INSERT INTO ChannelMemberHistory
|
||||
(UserId, ChannelId, JoinTime)
|
||||
VALUES
|
||||
(:UserId, :ChannelId, :JoinTime)`, channelMemberHistory); err != nil {
|
||||
@@ -53,7 +53,7 @@ func (s SqlChannelMemberHistoryStore) LogLeaveEvent(userId string, channelId str
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "channel_member_history_to_sql")
|
||||
}
|
||||
sqlResult, err := s.GetMasterX().Exec(query, params...)
|
||||
sqlResult, err := s.GetMaster().Exec(query, params...)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "LogLeaveEvent userId=%s channelId=%s leaveTime=%d", userId, channelId, leaveTime)
|
||||
}
|
||||
@@ -99,7 +99,7 @@ func (s SqlChannelMemberHistoryStore) hasDataAtOrBefore(time int64) (bool, error
|
||||
return false, errors.Wrap(err, "channel_member_history_to_sql")
|
||||
}
|
||||
var result NullableCountResult
|
||||
if err := s.GetReplicaX().Get(&result, query); err != nil {
|
||||
if err := s.GetReplica().Get(&result, query); err != nil {
|
||||
return false, err
|
||||
} else if result.Min.Valid {
|
||||
return result.Min.Int64 <= time, nil
|
||||
@@ -127,7 +127,7 @@ func (s SqlChannelMemberHistoryStore) getFromChannelMemberHistoryTable(startTime
|
||||
return nil, errors.Wrap(err, "channel_member_history_to_sql")
|
||||
}
|
||||
histories := []*model.ChannelMemberHistoryResult{}
|
||||
if err := s.GetReplicaX().Select(&histories, query, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&histories, query, args...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ func (s SqlChannelMemberHistoryStore) getFromChannelMembersTable(startTime int64
|
||||
}
|
||||
|
||||
histories := []*model.ChannelMemberHistoryResult{}
|
||||
if err := s.GetReplicaX().Select(&histories, query, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&histories, query, args...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// we have to fill in the join/leave times, because that data doesn't exist in the channel members table
|
||||
@@ -190,7 +190,7 @@ func (s SqlChannelMemberHistoryStore) DeleteOrphanedRows(limit int) (deleted int
|
||||
LIMIT ?
|
||||
) AS A
|
||||
)`
|
||||
result, err := s.GetMasterX().Exec(query, limit)
|
||||
result, err := s.GetMaster().Exec(query, limit)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -235,7 +235,7 @@ func (s SqlChannelMemberHistoryStore) PermanentDeleteBatch(endTime int64, limit
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "channel_member_history_to_sql")
|
||||
}
|
||||
sqlResult, err := s.GetMasterX().Exec(query, args...)
|
||||
sqlResult, err := s.GetMaster().Exec(query, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "PermanentDeleteBatch endTime=%d limit=%d", endTime, limit)
|
||||
}
|
||||
@@ -260,7 +260,7 @@ func (s SqlChannelMemberHistoryStore) GetChannelsLeftSince(userID string, since
|
||||
return nil, errors.Wrap(err, "channel_member_history_to_sql")
|
||||
}
|
||||
channelIds := []string{}
|
||||
err = s.GetReplicaX().Select(&channelIds, query, params...)
|
||||
err = s.GetReplica().Select(&channelIds, query, params...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetChannelsLeftSince userId=%s since=%d", userID, since)
|
||||
}
|
||||
|
||||
@@ -559,7 +559,7 @@ func (s SqlChannelStore) Save(rctx request.CTX, channel *model.Channel, maxChann
|
||||
}
|
||||
|
||||
var newChannel *model.Channel
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -623,7 +623,7 @@ func (s SqlChannelStore) SaveDirectChannel(rctx request.CTX, directChannel *mode
|
||||
return nil, store.NewErrInvalidInput("Channel", "Type", directChannel.Type)
|
||||
}
|
||||
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -702,7 +702,7 @@ func (s SqlChannelStore) saveChannelT(transaction *sqlxTxWrapper, channel *model
|
||||
|
||||
if rowAffected == 0 {
|
||||
dupChannel := model.Channel{}
|
||||
if serr := s.GetMasterX().Get(&dupChannel, "SELECT * FROM Channels WHERE TeamId = ? AND Name = ?", channel.TeamId, channel.Name); serr != nil {
|
||||
if serr := s.GetMaster().Get(&dupChannel, "SELECT * FROM Channels WHERE TeamId = ? AND Name = ?", channel.TeamId, channel.Name); serr != nil {
|
||||
return nil, errors.Wrapf(serr, "error while retrieving existing channel %s", channel.Name) // do not return this as a *store.ErrConflict as it would be treated as a recoverable error
|
||||
}
|
||||
return &dupChannel, store.NewErrConflict("Channel", err, "id="+channel.Id)
|
||||
@@ -713,7 +713,7 @@ func (s SqlChannelStore) saveChannelT(transaction *sqlxTxWrapper, channel *model
|
||||
|
||||
// Update writes the updated channel to the database.
|
||||
func (s SqlChannelStore) Update(rctx request.CTX, channel *model.Channel) (_ *model.Channel, err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -786,7 +786,7 @@ func (s SqlChannelStore) updateChannelT(transaction *sqlxTxWrapper, channel *mod
|
||||
|
||||
func (s SqlChannelStore) GetChannelUnread(channelId, userId string) (*model.ChannelUnread, error) {
|
||||
var unreadChannel model.ChannelUnread
|
||||
err := s.GetReplicaX().Get(&unreadChannel,
|
||||
err := s.GetReplica().Get(&unreadChannel,
|
||||
`SELECT
|
||||
Channels.TeamId TeamId, Channels.Id ChannelId, (Channels.TotalMsgCount - ChannelMembers.MsgCount) MsgCount, (Channels.TotalMsgCountRoot - ChannelMembers.MsgCountRoot) MsgCountRoot, ChannelMembers.MentionCount MentionCount, ChannelMembers.MentionCountRoot MentionCountRoot, COALESCE(ChannelMembers.UrgentMentionCount, 0) UrgentMentionCount, ChannelMembers.NotifyProps NotifyProps
|
||||
FROM
|
||||
@@ -819,7 +819,7 @@ func (s SqlChannelStore) GetPinnedPosts(channelId string) (*model.PostList, erro
|
||||
pl := model.NewPostList()
|
||||
|
||||
posts := []*model.Post{}
|
||||
if err := s.GetReplicaX().Select(&posts, "SELECT *, (SELECT count(Posts.Id) FROM Posts WHERE Posts.RootId = (CASE WHEN p.RootId = '' THEN p.Id ELSE p.RootId END) AND Posts.DeleteAt = 0) as ReplyCount FROM Posts p WHERE IsPinned = true AND ChannelId = ? AND DeleteAt = 0 ORDER BY CreateAt ASC", channelId); err != nil {
|
||||
if err := s.GetReplica().Select(&posts, "SELECT *, (SELECT count(Posts.Id) FROM Posts WHERE Posts.RootId = (CASE WHEN p.RootId = '' THEN p.Id ELSE p.RootId END) AND Posts.DeleteAt = 0) as ReplyCount FROM Posts p WHERE IsPinned = true AND ChannelId = ? AND DeleteAt = 0 ORDER BY CreateAt ASC", channelId); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Posts")
|
||||
}
|
||||
for _, post := range posts {
|
||||
@@ -832,7 +832,7 @@ func (s SqlChannelStore) GetPinnedPosts(channelId string) (*model.PostList, erro
|
||||
//nolint:unparam
|
||||
func (s SqlChannelStore) Get(id string, allowFromCache bool) (*model.Channel, error) {
|
||||
ch := model.Channel{}
|
||||
err := s.GetReplicaX().Get(&ch, `SELECT * FROM Channels WHERE Id=?`, id)
|
||||
err := s.GetReplica().Get(&ch, `SELECT * FROM Channels WHERE Id=?`, id)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Channel", id)
|
||||
@@ -855,7 +855,7 @@ func (s SqlChannelStore) GetMany(ids []string, allowFromCache bool) (model.Chann
|
||||
}
|
||||
|
||||
channels := model.ChannelList{}
|
||||
err = s.GetReplicaX().Select(&channels, sql, args...)
|
||||
err = s.GetReplica().Select(&channels, sql, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get channels with ids %v", ids)
|
||||
}
|
||||
@@ -881,7 +881,7 @@ func (s SqlChannelStore) Restore(channelId string, time int64) error {
|
||||
func (s SqlChannelStore) SetDeleteAt(channelId string, deleteAt, updateAt int64) (err error) {
|
||||
defer s.InvalidateChannel(channelId)
|
||||
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "SetDeleteAt: begin_transaction")
|
||||
}
|
||||
@@ -925,7 +925,7 @@ func (s SqlChannelStore) setDeleteAtT(transaction *sqlxTxWrapper, channelId stri
|
||||
|
||||
// PermanentDeleteByTeam removes all channels for the given team from the database.
|
||||
func (s SqlChannelStore) PermanentDeleteByTeam(teamId string) (err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "PermanentDeleteByTeam: begin_transaction")
|
||||
}
|
||||
@@ -962,7 +962,7 @@ func (s SqlChannelStore) permanentDeleteByTeamtT(transaction *sqlxTxWrapper, tea
|
||||
|
||||
// PermanentDelete removes the given channel from the database.
|
||||
func (s SqlChannelStore) PermanentDelete(rctx request.CTX, channelId string) (err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "PermanentDelete: begin_transaction")
|
||||
}
|
||||
@@ -998,7 +998,7 @@ func (s SqlChannelStore) permanentDeleteT(transaction *sqlxTxWrapper, channelId
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) PermanentDeleteMembersByChannel(rctx request.CTX, channelId string) error {
|
||||
_, err := s.GetMasterX().Exec("DELETE FROM ChannelMembers WHERE ChannelId = ?", channelId)
|
||||
_, err := s.GetMaster().Exec("DELETE FROM ChannelMembers WHERE ChannelId = ?", channelId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete Channel with channelId=%s", channelId)
|
||||
}
|
||||
@@ -1049,7 +1049,7 @@ func (s SqlChannelStore) GetChannels(teamId string, userId string, opts *model.C
|
||||
return nil, errors.Wrapf(err, "getchannels_tosql")
|
||||
}
|
||||
|
||||
err = s.GetReplicaX().Select(&channels, sql, args...)
|
||||
err = s.GetReplica().Select(&channels, sql, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get channels with TeamId=%s and UserId=%s", teamId, userId)
|
||||
}
|
||||
@@ -1101,7 +1101,7 @@ func (s SqlChannelStore) GetChannelsByUser(userId string, includeDeleted bool, l
|
||||
}
|
||||
|
||||
channels := model.ChannelList{}
|
||||
err = s.GetReplicaX().Select(&channels, sql, args...)
|
||||
err = s.GetReplica().Select(&channels, sql, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get channels with UserId=%s", userId)
|
||||
}
|
||||
@@ -1115,7 +1115,7 @@ func (s SqlChannelStore) GetChannelsByUser(userId string, includeDeleted bool, l
|
||||
|
||||
func (s SqlChannelStore) GetAllChannelMemberIdsByChannelId(channelID string) ([]string, error) {
|
||||
userIDs := []string{}
|
||||
err := s.GetReplicaX().Select(&userIDs, `SELECT UserId
|
||||
err := s.GetReplica().Select(&userIDs, `SELECT UserId
|
||||
FROM ChannelMembers
|
||||
WHERE ChannelId=?`, channelID)
|
||||
if err != nil {
|
||||
@@ -1139,7 +1139,7 @@ func (s SqlChannelStore) GetAllChannels(offset, limit int, opts store.ChannelSea
|
||||
}
|
||||
|
||||
data := model.ChannelListWithTeamData{}
|
||||
err = s.GetReplicaX().Select(&data, queryString, args...)
|
||||
err = s.GetReplica().Select(&data, queryString, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get all channels")
|
||||
}
|
||||
@@ -1156,7 +1156,7 @@ func (s SqlChannelStore) GetAllChannelsCount(opts store.ChannelSearchOpts) (int6
|
||||
}
|
||||
|
||||
var count int64
|
||||
err = s.GetReplicaX().Get(&count, queryString, args...)
|
||||
err = s.GetReplica().Get(&count, queryString, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count all channels")
|
||||
}
|
||||
@@ -1217,7 +1217,7 @@ func (s SqlChannelStore) getAllChannelsQuery(opts store.ChannelSearchOpts, forCo
|
||||
|
||||
func (s SqlChannelStore) GetMoreChannels(teamId string, userId string, offset int, limit int) (model.ChannelList, error) {
|
||||
channels := model.ChannelList{}
|
||||
err := s.GetReplicaX().Select(&channels, `
|
||||
err := s.GetReplica().Select(&channels, `
|
||||
SELECT
|
||||
Channels.*
|
||||
FROM
|
||||
@@ -1268,7 +1268,7 @@ func (s SqlChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, li
|
||||
return nil, errors.Wrap(err, "channels_tosql")
|
||||
}
|
||||
|
||||
err = s.GetReplicaX().Select(&channels, query, args...)
|
||||
err = s.GetReplica().Select(&channels, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find channel with teamId=%s", teamId)
|
||||
}
|
||||
@@ -1277,7 +1277,7 @@ func (s SqlChannelStore) GetPrivateChannelsForTeam(teamId string, offset int, li
|
||||
|
||||
func (s SqlChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) (model.ChannelList, error) {
|
||||
channels := model.ChannelList{}
|
||||
err := s.GetReplicaX().Select(&channels, `
|
||||
err := s.GetReplica().Select(&channels, `
|
||||
SELECT
|
||||
Channels.*
|
||||
FROM
|
||||
@@ -1331,7 +1331,7 @@ func (s SqlChannelStore) GetPublicChannelsByIdsForTeam(teamId string, channelIds
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetPublicChannelsByIdsForTeam to_sql")
|
||||
}
|
||||
err = s.GetReplicaX().Select(&data, queryString, args...)
|
||||
err = s.GetReplica().Select(&data, queryString, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Channels")
|
||||
}
|
||||
@@ -1350,7 +1350,7 @@ func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) (*model.
|
||||
TotalMsgCountRoot int64
|
||||
UpdateAt int64
|
||||
}{}
|
||||
err := s.GetReplicaX().Select(&data, `SELECT Id, TotalMsgCount, TotalMsgCountRoot, UpdateAt
|
||||
err := s.GetReplica().Select(&data, `SELECT Id, TotalMsgCount, TotalMsgCountRoot, UpdateAt
|
||||
FROM Channels
|
||||
WHERE Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = ?)
|
||||
AND (TeamId = ? OR TeamId = '')
|
||||
@@ -1378,7 +1378,7 @@ func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) (*model.
|
||||
|
||||
func (s SqlChannelStore) GetTeamChannels(teamId string) (model.ChannelList, error) {
|
||||
data := model.ChannelList{}
|
||||
err := s.GetReplicaX().Select(&data, "SELECT * FROM Channels WHERE TeamId = ? And Type != ? ORDER BY DisplayName", teamId, model.ChannelTypeDirect)
|
||||
err := s.GetReplica().Select(&data, "SELECT * FROM Channels WHERE TeamId = ? And Type != ? ORDER BY DisplayName", teamId, model.ChannelTypeDirect)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Channels with teamId=%s", teamId)
|
||||
}
|
||||
@@ -1423,7 +1423,7 @@ func (s SqlChannelStore) getByNames(teamId string, names []string, allowFromCach
|
||||
return nil, errors.Wrap(err, "GetByNames_tosql")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Select(&channels, query, args...); err != nil && err != sql.ErrNoRows {
|
||||
if err := s.GetReplica().Select(&channels, query, args...); err != nil && err != sql.ErrNoRows {
|
||||
msg := fmt.Sprintf("failed to get channels with names=%v", names)
|
||||
if teamId != "" {
|
||||
msg += fmt.Sprintf(" teamId=%s", teamId)
|
||||
@@ -1463,7 +1463,7 @@ func (s SqlChannelStore) getByName(teamId string, name string, includeDeleted bo
|
||||
}
|
||||
|
||||
channel := model.Channel{}
|
||||
if err := s.GetReplicaX().Get(&channel, queryStr, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&channel, queryStr, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Channel", fmt.Sprintf("TeamId=%s&Name=%s", teamId, name))
|
||||
}
|
||||
@@ -1476,7 +1476,7 @@ func (s SqlChannelStore) getByName(teamId string, name string, includeDeleted bo
|
||||
func (s SqlChannelStore) GetDeletedByName(teamId string, name string) (*model.Channel, error) {
|
||||
channel := model.Channel{}
|
||||
|
||||
if err := s.GetReplicaX().Get(&channel, `SELECT *
|
||||
if err := s.GetReplica().Get(&channel, `SELECT *
|
||||
FROM Channels
|
||||
WHERE (TeamId = ? OR TeamId = '')
|
||||
AND Name = ?
|
||||
@@ -1520,7 +1520,7 @@ func (s SqlChannelStore) GetDeleted(teamId string, offset int, limit int, userId
|
||||
return nil, errors.Wrapf(err, "GetDeleted_ToSql")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Select(&channels, query, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&channels, query, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Channel", fmt.Sprintf("TeamId=%s,UserId=%s", teamId, userId))
|
||||
}
|
||||
@@ -1639,7 +1639,7 @@ func (s SqlChannelStore) saveMultipleMembers(members []*model.ChannelMember) ([]
|
||||
User sql.NullString
|
||||
Admin sql.NullString
|
||||
}{}
|
||||
err = s.GetMasterX().Select(&defaultChannelsRoles, channelRolesSql, channelRolesArgs...)
|
||||
err = s.GetMaster().Select(&defaultChannelsRoles, channelRolesSql, channelRolesArgs...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "default_channel_roles_select")
|
||||
}
|
||||
@@ -1678,7 +1678,7 @@ func (s SqlChannelStore) saveMultipleMembers(members []*model.ChannelMember) ([]
|
||||
User sql.NullString
|
||||
Admin sql.NullString
|
||||
}{}
|
||||
err = s.GetMasterX().Select(&defaultTeamsRoles, teamRolesSql, teamRolesArgs...)
|
||||
err = s.GetMaster().Select(&defaultTeamsRoles, teamRolesSql, teamRolesArgs...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "default_team_roles_select")
|
||||
}
|
||||
@@ -1697,7 +1697,7 @@ func (s SqlChannelStore) saveMultipleMembers(members []*model.ChannelMember) ([]
|
||||
return nil, errors.Wrap(err, "channel_members_tosql")
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().Exec(sql, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(sql, args...); err != nil {
|
||||
if IsUniqueConstraintError(err, []string{"ChannelId", "channelmembers_pkey", "PRIMARY"}) {
|
||||
return nil, store.NewErrConflict("ChannelMembers", err, "")
|
||||
}
|
||||
@@ -1748,7 +1748,7 @@ func (s SqlChannelStore) UpdateMultipleMembers(members []*model.ChannelMember) (
|
||||
|
||||
var transaction *sqlxTxWrapper
|
||||
|
||||
if transaction, err = s.GetMasterX().Beginx(); err != nil {
|
||||
if transaction, err = s.GetMaster().Beginx(); err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
defer finalizeTransactionX(transaction, &err)
|
||||
@@ -1807,7 +1807,7 @@ func (s SqlChannelStore) UpdateMember(rctx request.CTX, member *model.ChannelMem
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) UpdateMemberNotifyProps(channelID, userID string, props map[string]string) (_ *model.ChannelMember, err error) {
|
||||
tx, err := s.GetMasterX().Beginx()
|
||||
tx, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -1928,7 +1928,7 @@ func (s SqlChannelStore) PatchMultipleMembersNotifyProps(members []*model.Channe
|
||||
|
||||
builder = builder.Where(whereClause)
|
||||
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -1978,7 +1978,7 @@ func (s SqlChannelStore) GetMembers(channelID string, offset, limit int) (model.
|
||||
}
|
||||
|
||||
dbMembers := channelMemberWithSchemeRolesList{}
|
||||
err = s.GetReplicaX().Select(&dbMembers, sql, args...)
|
||||
err = s.GetReplica().Select(&dbMembers, sql, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get ChannelMembers with channelId=%s", channelID)
|
||||
}
|
||||
@@ -1988,7 +1988,7 @@ func (s SqlChannelStore) GetMembers(channelID string, offset, limit int) (model.
|
||||
|
||||
func (s SqlChannelStore) GetChannelMembersTimezones(channelId string) ([]model.StringMap, error) {
|
||||
dbMembersTimezone := []model.StringMap{}
|
||||
err := s.GetReplicaX().Select(&dbMembersTimezone, `
|
||||
err := s.GetReplica().Select(&dbMembersTimezone, `
|
||||
SELECT
|
||||
Users.Timezone
|
||||
FROM
|
||||
@@ -2039,7 +2039,7 @@ func (s SqlChannelStore) GetChannelsWithUnreadsAndWithMentions(ctx context.Conte
|
||||
LastViewedAt int64
|
||||
}
|
||||
|
||||
err = s.GetReplicaX().Select(&channels, queryString, args...)
|
||||
err = s.GetReplica().Select(&channels, queryString, args...)
|
||||
if err != nil {
|
||||
return nil, nil, nil, errors.Wrap(err, "failed to find channels with unreads and with mentions data")
|
||||
}
|
||||
@@ -2164,7 +2164,7 @@ func (s SqlChannelStore) GetMemberForPost(postId string, userId string, includeA
|
||||
if !includeArchivedChannels {
|
||||
query += " AND Channels.DeleteAt = 0"
|
||||
}
|
||||
if err := s.GetReplicaX().Get(&dbMember, query, userId, postId); err != nil {
|
||||
if err := s.GetReplica().Get(&dbMember, query, userId, postId); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get ChannelMember with postId=%s and userId=%s", postId, userId)
|
||||
}
|
||||
return dbMember.ToModel(), nil
|
||||
@@ -2240,7 +2240,7 @@ func (s SqlChannelStore) GetChannelsMemberCount(channelIDs []string) (_ map[stri
|
||||
return nil, errors.Wrap(err, "channels_member_count_tosql")
|
||||
}
|
||||
|
||||
rows, err := s.GetReplicaX().DB.Query(queryString, args...)
|
||||
rows, err := s.GetReplica().DB.Query(queryString, args...)
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to fetch member counts")
|
||||
@@ -2279,7 +2279,7 @@ type allChannelMemberNotifyProps struct {
|
||||
|
||||
func (s SqlChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) (map[string]model.StringMap, error) {
|
||||
data := []allChannelMemberNotifyProps{}
|
||||
err := s.GetReplicaX().Select(&data, `
|
||||
err := s.GetReplica().Select(&data, `
|
||||
SELECT UserId, NotifyProps
|
||||
FROM ChannelMembers
|
||||
WHERE ChannelId = ?`, channelId)
|
||||
@@ -2306,7 +2306,7 @@ func (s SqlChannelStore) GetMemberCountFromCache(channelId string) int64 {
|
||||
|
||||
func (s SqlChannelStore) GetFileCount(channelId string) (int64, error) {
|
||||
var count int64
|
||||
err := s.GetReplicaX().Get(&count, `
|
||||
err := s.GetReplica().Get(&count, `
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
@@ -2325,7 +2325,7 @@ func (s SqlChannelStore) GetFileCount(channelId string) (int64, error) {
|
||||
//nolint:unparam
|
||||
func (s SqlChannelStore) GetMemberCount(channelId string, allowFromCache bool) (int64, error) {
|
||||
var count int64
|
||||
err := s.GetReplicaX().Get(&count, `
|
||||
err := s.GetReplica().Get(&count, `
|
||||
SELECT
|
||||
count(*)
|
||||
FROM
|
||||
@@ -2402,7 +2402,7 @@ func (s SqlChannelStore) InvalidatePinnedPostCount(channelId string) {
|
||||
//nolint:unparam
|
||||
func (s SqlChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool) (int64, error) {
|
||||
var count int64
|
||||
err := s.GetReplicaX().Get(&count, `
|
||||
err := s.GetReplica().Get(&count, `
|
||||
SELECT count(*)
|
||||
FROM Posts
|
||||
WHERE
|
||||
@@ -2428,7 +2428,7 @@ func (s SqlChannelStore) GetGuestCount(channelId string, allowFromCache bool) (i
|
||||
indexHint = `USE INDEX(idx_channelmembers_channel_id_scheme_guest_user_id)`
|
||||
}
|
||||
var count int64
|
||||
err := s.GetReplicaX().Get(&count, `
|
||||
err := s.GetReplica().Get(&count, `
|
||||
SELECT
|
||||
count(*)
|
||||
FROM
|
||||
@@ -2454,7 +2454,7 @@ func (s SqlChannelStore) RemoveMembers(rctx request.CTX, channelId string, userI
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "channel_tosql")
|
||||
}
|
||||
_, err = s.GetMasterX().Exec(query, args...)
|
||||
_, err = s.GetMaster().Exec(query, args...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to delete ChannelMembers")
|
||||
}
|
||||
@@ -2469,7 +2469,7 @@ func (s SqlChannelStore) RemoveMembers(rctx request.CTX, channelId string, userI
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "channel_tosql")
|
||||
}
|
||||
_, err = s.GetMasterX().Exec(query, args...)
|
||||
_, err = s.GetMaster().Exec(query, args...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to delete SidebarChannels")
|
||||
}
|
||||
@@ -2498,7 +2498,7 @@ func (s SqlChannelStore) RemoveAllDeactivatedMembers(rctx request.CTX, channelId
|
||||
ChannelMembers.ChannelId = ?
|
||||
`
|
||||
|
||||
_, err := s.GetMasterX().Exec(query, channelId)
|
||||
_, err := s.GetMaster().Exec(query, channelId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete ChannelMembers with channelId=%s", channelId)
|
||||
}
|
||||
@@ -2506,7 +2506,7 @@ func (s SqlChannelStore) RemoveAllDeactivatedMembers(rctx request.CTX, channelId
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) PermanentDeleteMembersByUser(rctx request.CTX, userId string) error {
|
||||
if _, err := s.GetMasterX().Exec("DELETE FROM ChannelMembers WHERE UserId = ?", userId); err != nil {
|
||||
if _, err := s.GetMaster().Exec("DELETE FROM ChannelMembers WHERE UserId = ?", userId); err != nil {
|
||||
return errors.Wrapf(err, "failed to permanent delete ChannelMembers with userId=%s", userId)
|
||||
}
|
||||
return nil
|
||||
@@ -2561,7 +2561,7 @@ func (s SqlChannelStore) UpdateLastViewedAt(channelIds []string, userId string)
|
||||
}
|
||||
}
|
||||
|
||||
err = s.GetMasterX().Select(&lastPostAtTimes, sql, args...)
|
||||
err = s.GetMaster().Select(&lastPostAtTimes, sql, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find ChannelMembers data with userId=%s and channelId in %v", userId, channelIds)
|
||||
}
|
||||
@@ -2614,7 +2614,7 @@ func (s SqlChannelStore) UpdateLastViewedAt(channelIds []string, userId string)
|
||||
return nil, errors.Wrap(err, "UpdateLastViewedAt_Update_Tosql")
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().Exec(sql, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(sql, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to update ChannelMembers with userId=%s and channelId in %v", userId, channelIds)
|
||||
}
|
||||
|
||||
@@ -2638,7 +2638,7 @@ func (s SqlChannelStore) CountUrgentPostsAfter(channelId string, timestamp int64
|
||||
}
|
||||
|
||||
var urgent int64
|
||||
err := s.GetReplicaX().GetBuilder(&urgent, query)
|
||||
err := s.GetReplica().GetBuilder(&urgent, query)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count urgent Posts")
|
||||
}
|
||||
@@ -2680,7 +2680,7 @@ func (s SqlChannelStore) CountPostsAfter(channelId string, timestamp int64, excl
|
||||
}
|
||||
|
||||
var unread int64
|
||||
err = s.GetReplicaX().Get(&unread, sql, args...)
|
||||
err = s.GetReplica().Get(&unread, sql, args...)
|
||||
if err != nil {
|
||||
return 0, 0, errors.Wrap(err, "failed to count Posts")
|
||||
}
|
||||
@@ -2690,7 +2690,7 @@ func (s SqlChannelStore) CountPostsAfter(channelId string, timestamp int64, excl
|
||||
}
|
||||
|
||||
var unreadRoot int64
|
||||
err = s.GetReplicaX().Get(&unreadRoot, sql2, args2...)
|
||||
err = s.GetReplica().Get(&unreadRoot, sql2, args2...)
|
||||
if err != nil {
|
||||
return 0, 0, errors.Wrap(err, "failed to count root Posts")
|
||||
}
|
||||
@@ -2742,7 +2742,7 @@ func (s SqlChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID s
|
||||
UserId = :userid
|
||||
AND ChannelId = :channelid
|
||||
`
|
||||
_, err = s.GetMasterX().NamedExec(setUnreadQuery, params)
|
||||
_, err = s.GetMaster().NamedExec(setUnreadQuery, params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to update ChannelMembers")
|
||||
}
|
||||
@@ -2768,7 +2768,7 @@ func (s SqlChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID s
|
||||
AND c.DeleteAt = 0
|
||||
`
|
||||
result := &model.ChannelUnreadAt{}
|
||||
if err = s.GetMasterX().Get(result, chanUnreadQuery, userID, unreadPost.ChannelId); err != nil {
|
||||
if err = s.GetMaster().Get(result, chanUnreadQuery, userID, unreadPost.ChannelId); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get ChannelMember with channelId=%s", unreadPost.ChannelId)
|
||||
}
|
||||
|
||||
@@ -2804,7 +2804,7 @@ func (s SqlChannelStore) IncrementMentionCount(channelId string, userIDs []strin
|
||||
return errors.Wrap(err, "IncrementMentionCount_Tosql")
|
||||
}
|
||||
|
||||
_, err = s.GetMasterX().Exec(sql, args...)
|
||||
_, err = s.GetMaster().Exec(sql, args...)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to Update ChannelMembers with channelId=%s and userId=%v", channelId, userIDs)
|
||||
}
|
||||
@@ -2813,7 +2813,7 @@ func (s SqlChannelStore) IncrementMentionCount(channelId string, userIDs []strin
|
||||
|
||||
func (s SqlChannelStore) GetAll(teamId string) ([]*model.Channel, error) {
|
||||
data := []*model.Channel{}
|
||||
err := s.GetReplicaX().Select(&data, "SELECT * FROM Channels WHERE TeamId = ? AND Type != ? ORDER BY Name", teamId, model.ChannelTypeDirect)
|
||||
err := s.GetReplica().Select(&data, "SELECT * FROM Channels WHERE TeamId = ? AND Type != ? ORDER BY Name", teamId, model.ChannelTypeDirect)
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Channels with teamId=%s", teamId)
|
||||
@@ -2839,7 +2839,7 @@ func (s SqlChannelStore) GetChannelsByIds(channelIds []string, includeDeleted bo
|
||||
}
|
||||
|
||||
channels := []*model.Channel{}
|
||||
err = s.GetReplicaX().Select(&channels, sql, args...)
|
||||
err = s.GetReplica().Select(&channels, sql, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Channels")
|
||||
}
|
||||
@@ -2867,7 +2867,7 @@ func (s SqlChannelStore) GetChannelsWithTeamDataByIds(channelIDs []string, inclu
|
||||
}
|
||||
|
||||
channels := []*model.ChannelWithTeamData{}
|
||||
err = s.GetReplicaX().Select(&channels, sql, args...)
|
||||
err = s.GetReplica().Select(&channels, sql, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Channels")
|
||||
}
|
||||
@@ -2876,7 +2876,7 @@ func (s SqlChannelStore) GetChannelsWithTeamDataByIds(channelIDs []string, inclu
|
||||
|
||||
func (s SqlChannelStore) GetForPost(postId string) (*model.Channel, error) {
|
||||
channel := model.Channel{}
|
||||
if err := s.GetReplicaX().Get(
|
||||
if err := s.GetReplica().Get(
|
||||
&channel,
|
||||
`SELECT
|
||||
Channels.*
|
||||
@@ -2910,7 +2910,7 @@ func (s SqlChannelStore) AnalyticsTypeCount(teamId string, channelType model.Cha
|
||||
}
|
||||
|
||||
var value int64
|
||||
err = s.GetReplicaX().Get(&value, sql, args...)
|
||||
err = s.GetReplica().Get(&value, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count Channels")
|
||||
}
|
||||
@@ -2936,7 +2936,7 @@ func (s SqlChannelStore) AnalyticsDeletedTypeCount(teamId string, channelType mo
|
||||
}
|
||||
|
||||
var v int64
|
||||
err = s.GetReplicaX().Get(&v, sql, args...)
|
||||
err = s.GetReplica().Get(&v, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "failed to count Channels with teamId=%s and channelType=%s", teamId, channelType)
|
||||
}
|
||||
@@ -2959,7 +2959,7 @@ func (s SqlChannelStore) GetMembersForUser(teamID string, userID string) (model.
|
||||
}
|
||||
|
||||
dbMembers := channelMemberWithSchemeRolesList{}
|
||||
err = s.GetReplicaX().Select(&dbMembers, sql, args...)
|
||||
err = s.GetReplica().Select(&dbMembers, sql, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find ChannelMembers data with teamId=%s and userId=%s", teamID, userID)
|
||||
}
|
||||
@@ -2970,7 +2970,7 @@ func (s SqlChannelStore) GetMembersForUser(teamID string, userID string) (model.
|
||||
func (s SqlChannelStore) GetMembersForUserWithPagination(userId string, page, perPage int) (model.ChannelMembersWithTeamData, error) {
|
||||
dbMembers := channelMemberWithTeamWithSchemeRolesList{}
|
||||
offset := page * perPage
|
||||
err := s.GetReplicaX().Select(&dbMembers, channelMembersWithSchemeSelectQuery+"WHERE ChannelMembers.UserId = ? ORDER BY ChannelId ASC Limit ? Offset ?", userId, perPage, offset)
|
||||
err := s.GetReplica().Select(&dbMembers, channelMembersWithSchemeSelectQuery+"WHERE ChannelMembers.UserId = ? ORDER BY ChannelId ASC Limit ? Offset ?", userId, perPage, offset)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find ChannelMembers data with and userId=%s", userId)
|
||||
}
|
||||
@@ -2980,7 +2980,7 @@ func (s SqlChannelStore) GetMembersForUserWithPagination(userId string, page, pe
|
||||
|
||||
func (s SqlChannelStore) GetTeamMembersForChannel(channelID string) ([]string, error) {
|
||||
teamMemberIDs := []string{}
|
||||
if err := s.GetReplicaX().Select(&teamMemberIDs, `SELECT tm.UserId
|
||||
if err := s.GetReplica().Select(&teamMemberIDs, `SELECT tm.UserId
|
||||
FROM Channels c, Teams t, TeamMembers tm
|
||||
WHERE
|
||||
c.TeamId=t.Id
|
||||
@@ -3043,7 +3043,7 @@ func (s SqlChannelStore) Autocomplete(rctx request.CTX, userID, term string, inc
|
||||
}
|
||||
|
||||
channels := model.ChannelListWithTeamData{}
|
||||
err = s.GetReplicaX().Select(&channels, sql, args...)
|
||||
err = s.GetReplica().Select(&channels, sql, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "could not find channel with term=%s", trimInput(term))
|
||||
}
|
||||
@@ -3156,7 +3156,7 @@ func (s SqlChannelStore) AutocompleteInTeamForSearch(teamID string, userID strin
|
||||
}
|
||||
|
||||
// query the database
|
||||
err = s.GetReplicaX().Select(&channels, sql, args...)
|
||||
err = s.GetReplica().Select(&channels, sql, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Channels with term='%s'", trimInput(term))
|
||||
}
|
||||
@@ -3213,7 +3213,7 @@ func (s SqlChannelStore) autocompleteInTeamForSearchDirectMessages(userID string
|
||||
|
||||
// query the channel list from the database using SQLX
|
||||
channels := model.ChannelList{}
|
||||
if err := s.GetReplicaX().Select(&channels, sql, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&channels, sql, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Channels with term='%s'", trimInput(term))
|
||||
}
|
||||
|
||||
@@ -3446,7 +3446,7 @@ func (s SqlChannelStore) SearchAllChannels(term string, opts store.ChannelSearch
|
||||
return nil, 0, errors.Wrap(err, "channel_tosql")
|
||||
}
|
||||
channels := model.ChannelListWithTeamData{}
|
||||
if err2 := s.GetReplicaX().Select(&channels, queryString, args...); err2 != nil {
|
||||
if err2 := s.GetReplica().Select(&channels, queryString, args...); err2 != nil {
|
||||
return nil, 0, errors.Wrapf(err2, "failed to find Channels with term='%s'", trimInput(term))
|
||||
}
|
||||
|
||||
@@ -3459,7 +3459,7 @@ func (s SqlChannelStore) SearchAllChannels(term string, opts store.ChannelSearch
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrap(err, "channel_tosql")
|
||||
}
|
||||
if err2 := s.GetReplicaX().Get(&totalCount, queryString, args...); err2 != nil {
|
||||
if err2 := s.GetReplica().Get(&totalCount, queryString, args...); err2 != nil {
|
||||
return nil, 0, errors.Wrapf(err2, "failed to find Channels with term='%s'", trimInput(term))
|
||||
}
|
||||
} else {
|
||||
@@ -3634,7 +3634,7 @@ func (s SqlChannelStore) performSearch(searchQuery sq.SelectBuilder, term string
|
||||
}
|
||||
|
||||
channels := model.ChannelList{}
|
||||
err = s.GetReplicaX().Select(&channels, sql, args...)
|
||||
err = s.GetReplica().Select(&channels, sql, args...)
|
||||
if err != nil {
|
||||
return channels, errors.Wrapf(err, "failed to find Channels with term='%s'", trimInput(term))
|
||||
}
|
||||
@@ -3727,7 +3727,7 @@ func (s SqlChannelStore) SearchGroupChannels(userId, term string) (model.Channel
|
||||
}
|
||||
|
||||
groupChannels := model.ChannelList{}
|
||||
if err := s.GetReplicaX().Select(&groupChannels, sql, params...); err != nil {
|
||||
if err := s.GetReplica().Select(&groupChannels, sql, params...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Channels with term='%s' and userId=%s", trimInput(term), userId)
|
||||
}
|
||||
return groupChannels, nil
|
||||
@@ -3747,7 +3747,7 @@ func (s SqlChannelStore) GetMembersByIds(channelID string, userIDs []string) (mo
|
||||
}
|
||||
|
||||
dbMembers := channelMemberWithSchemeRolesList{}
|
||||
if err := s.GetReplicaX().Select(&dbMembers, sql, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&dbMembers, sql, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find ChannelMembers with channelId=%s and userId in %v", channelID, userIDs)
|
||||
}
|
||||
|
||||
@@ -3768,7 +3768,7 @@ func (s SqlChannelStore) GetMembersByChannelIds(channelIDs []string, userID stri
|
||||
}
|
||||
|
||||
dbMembers := channelMemberWithSchemeRolesList{}
|
||||
if err := s.GetReplicaX().Select(&dbMembers, sql, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&dbMembers, sql, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find ChannelMembers with userId=%s and channelId in %v", userID, channelIDs)
|
||||
}
|
||||
|
||||
@@ -3796,7 +3796,7 @@ func (s SqlChannelStore) GetMembersInfoByChannelIds(channelIDs []string) (map[st
|
||||
ChannelId string
|
||||
}{}
|
||||
|
||||
if err := s.GetReplicaX().Select(&res, sql, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&res, sql, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find channels display name")
|
||||
}
|
||||
|
||||
@@ -3814,7 +3814,7 @@ func (s SqlChannelStore) GetMembersInfoByChannelIds(channelIDs []string) (map[st
|
||||
|
||||
func (s SqlChannelStore) GetChannelsByScheme(schemeId string, offset int, limit int) (model.ChannelList, error) {
|
||||
channels := model.ChannelList{}
|
||||
err := s.GetReplicaX().Select(&channels, "SELECT * FROM Channels WHERE SchemeId = ? ORDER BY DisplayName LIMIT ? OFFSET ?", schemeId, limit, offset)
|
||||
err := s.GetReplica().Select(&channels, "SELECT * FROM Channels WHERE SchemeId = ? ORDER BY DisplayName LIMIT ? OFFSET ?", schemeId, limit, offset)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Channels with schemeId=%s", schemeId)
|
||||
}
|
||||
@@ -3828,7 +3828,7 @@ func (s SqlChannelStore) GetChannelsByScheme(schemeId string, offset int, limit
|
||||
func (s SqlChannelStore) MigrateChannelMembers(fromChannelId string, fromUserId string) (_ map[string]string, err error) {
|
||||
var transaction *sqlxTxWrapper
|
||||
|
||||
if transaction, err = s.GetMasterX().Beginx(); err != nil {
|
||||
if transaction, err = s.GetMaster().Beginx(); err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
defer finalizeTransactionX(transaction, &err)
|
||||
@@ -3922,7 +3922,7 @@ func (s SqlChannelStore) MigrateChannelMembers(fromChannelId string, fromUserId
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) ResetAllChannelSchemes() (err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -3956,7 +3956,7 @@ func (s SqlChannelStore) ClearAllCustomRoleAssignments() (err error) {
|
||||
for {
|
||||
var transaction *sqlxTxWrapper
|
||||
|
||||
if transaction, err = s.GetMasterX().Beginx(); err != nil {
|
||||
if transaction, err = s.GetMaster().Beginx(); err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
|
||||
@@ -4030,7 +4030,7 @@ func (s SqlChannelStore) ClearAllCustomRoleAssignments() (err error) {
|
||||
|
||||
func (s SqlChannelStore) GetAllChannelsForExportAfter(limit int, afterId string) ([]*model.ChannelForExport, error) {
|
||||
channels := []*model.ChannelForExport{}
|
||||
if err := s.GetReplicaX().Select(&channels, `
|
||||
if err := s.GetReplica().Select(&channels, `
|
||||
SELECT
|
||||
Channels.*,
|
||||
Teams.Name as TeamName,
|
||||
@@ -4082,7 +4082,7 @@ func (s SqlChannelStore) GetChannelMembersForExport(userId string, teamId string
|
||||
if !includeArchivedChannel {
|
||||
q += " AND Channels.DeleteAt = 0"
|
||||
}
|
||||
err := s.GetReplicaX().Select(&members, q, userId, teamId)
|
||||
err := s.GetReplica().Select(&members, q, userId, teamId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Channels for export")
|
||||
}
|
||||
@@ -4113,7 +4113,7 @@ func (s SqlChannelStore) GetAllDirectChannelsForExportAfter(limit int, afterId s
|
||||
return nil, errors.Wrap(err, "channel_tosql")
|
||||
}
|
||||
|
||||
if err2 := s.GetReplicaX().Select(&directChannelsForExport, queryString, args...); err2 != nil {
|
||||
if err2 := s.GetReplica().Select(&directChannelsForExport, queryString, args...); err2 != nil {
|
||||
return nil, errors.Wrap(err2, "failed to find direct Channels for export")
|
||||
}
|
||||
|
||||
@@ -4133,7 +4133,7 @@ func (s SqlChannelStore) GetAllDirectChannelsForExportAfter(limit int, afterId s
|
||||
}
|
||||
|
||||
channelMembers := []*model.ChannelMemberForExport{}
|
||||
if err2 := s.GetReplicaX().Select(&channelMembers, queryString, args...); err2 != nil {
|
||||
if err2 := s.GetReplica().Select(&channelMembers, queryString, args...); err2 != nil {
|
||||
return nil, errors.Wrap(err2, "failed to find ChannelMembers")
|
||||
}
|
||||
|
||||
@@ -4188,7 +4188,7 @@ func (s SqlChannelStore) UserBelongsToChannels(userId string, channelIds []strin
|
||||
return false, errors.Wrap(err, "channel_tosql")
|
||||
}
|
||||
var c int64
|
||||
err = s.GetReplicaX().Get(&c, queryString, args...)
|
||||
err = s.GetReplica().Get(&c, queryString, args...)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "failed to count ChannelMembers")
|
||||
}
|
||||
@@ -4201,7 +4201,7 @@ func (s SqlChannelStore) UserBelongsToChannels(userId string, channelIds []strin
|
||||
//
|
||||
// TODO: parameterize adminIDs
|
||||
func (s SqlChannelStore) UpdateMembersRole(channelID string, adminIDs []string) (_ []*model.ChannelMember, err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -4279,7 +4279,7 @@ func (s SqlChannelStore) GroupSyncedChannelCount() (int64, error) {
|
||||
}
|
||||
|
||||
var count int64
|
||||
err = s.GetReplicaX().Get(&count, sql, args...)
|
||||
err = s.GetReplica().Get(&count, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count Channels")
|
||||
}
|
||||
@@ -4298,7 +4298,7 @@ func (s SqlChannelStore) SetShared(channelId string, shared bool) error {
|
||||
return errors.Wrap(err, "channel_set_shared_tosql")
|
||||
}
|
||||
|
||||
result, err := s.GetMasterX().Exec(squery, args...)
|
||||
result, err := s.GetMaster().Exec(squery, args...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to update `Shared` for Channels")
|
||||
}
|
||||
@@ -4327,7 +4327,7 @@ func (s SqlChannelStore) GetTeamForChannel(channelID string) (*model.Team, error
|
||||
}
|
||||
|
||||
team := model.Team{}
|
||||
err = s.GetReplicaX().Get(&team, query, args...)
|
||||
err = s.GetReplica().Get(&team, query, args...)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Team", fmt.Sprintf("channel_id=%s", channelID))
|
||||
@@ -4347,7 +4347,7 @@ func (s SqlChannelStore) IsReadOnlyChannel(channelID string) (bool, error) {
|
||||
// there might be in effect a custom scheme for the user that doesn't allow to create posts, but that wouldn't
|
||||
// be a readonly channel but a readonly user
|
||||
var schemaId string
|
||||
err = s.GetReplicaX().Get(&schemaId, squery, args...)
|
||||
err = s.GetReplica().Get(&schemaId, squery, args...)
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
@@ -4365,7 +4365,7 @@ func (s SqlChannelStore) IsChannelReadOnlyScheme(schemeID string) (bool, error)
|
||||
return false, err
|
||||
}
|
||||
var permissions string
|
||||
err = s.GetReplicaX().Get(&permissions, squery, args...)
|
||||
err = s.GetReplica().Get(&permissions, squery, args...)
|
||||
if err != nil {
|
||||
mlog.Err(err)
|
||||
return false, err
|
||||
|
||||
@@ -21,7 +21,7 @@ type dbSelecter interface {
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) CreateInitialSidebarCategories(c request.CTX, userId string, opts *store.SidebarCategorySearchOpts) (_ *model.OrderedSidebarCategories, err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "CreateInitialSidebarCategories: begin_transaction")
|
||||
}
|
||||
@@ -250,7 +250,7 @@ func (s SqlChannelStore) migrateFavoritesToSidebarT(transaction *sqlxTxWrapper,
|
||||
// MigrateFavoritesToSidebarChannels populates the SidebarChannels table by analyzing existing user preferences for favorites
|
||||
// **IMPORTANT** This function should only be called from the migration task and shouldn't be used by itself
|
||||
func (s SqlChannelStore) MigrateFavoritesToSidebarChannels(lastUserId string, runningOrder int64) (_ map[string]any, err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -297,7 +297,7 @@ type sidebarCategoryForJoin struct {
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) CreateSidebarCategory(userId, teamId string, newCategory *model.SidebarCategoryWithChannels) (_ *model.SidebarCategoryWithChannels, err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -419,7 +419,7 @@ func (s SqlChannelStore) CreateSidebarCategory(userId, teamId string, newCategor
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) completePopulatingCategoryChannels(category *model.SidebarCategoryWithChannels) (_ *model.SidebarCategoryWithChannels, err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -504,7 +504,7 @@ func (s SqlChannelStore) GetSidebarCategory(categoryId string) (*model.SidebarCa
|
||||
}
|
||||
|
||||
categories := []*sidebarCategoryForJoin{}
|
||||
if err = s.GetReplicaX().Select(&categories, sql, args...); err != nil {
|
||||
if err = s.GetReplica().Select(&categories, sql, args...); err != nil {
|
||||
return nil, store.NewErrNotFound("SidebarCategories", categoryId).Wrap(err)
|
||||
}
|
||||
|
||||
@@ -600,11 +600,11 @@ func (s SqlChannelStore) GetSidebarCategoriesForTeamForUser(userId, teamId strin
|
||||
TeamID: teamId,
|
||||
ExcludeTeam: false,
|
||||
}
|
||||
return s.getSidebarCategoriesT(s.GetReplicaX(), userId, opts)
|
||||
return s.getSidebarCategoriesT(s.GetReplica(), userId, opts)
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetSidebarCategories(userID string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
|
||||
return s.getSidebarCategoriesT(s.GetReplicaX(), userID, opts)
|
||||
return s.getSidebarCategoriesT(s.GetReplica(), userID, opts)
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetSidebarCategoryOrder(userId, teamId string) ([]string, error) {
|
||||
@@ -623,7 +623,7 @@ func (s SqlChannelStore) GetSidebarCategoryOrder(userId, teamId string) ([]strin
|
||||
return nil, errors.Wrap(err, "sidebar_category_tosql")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Select(&ids, sql, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&ids, sql, args...); err != nil {
|
||||
return nil, store.NewErrNotFound("SidebarCategories", fmt.Sprintf("userId=%s,teamId=%s", userId, teamId)).Wrap(err)
|
||||
}
|
||||
|
||||
@@ -650,7 +650,7 @@ func (s SqlChannelStore) updateSidebarCategoryOrderT(transaction *sqlxTxWrapper,
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) UpdateSidebarCategoryOrder(userId, teamId string, categoryOrder []string) (err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -693,7 +693,7 @@ func (s SqlChannelStore) UpdateSidebarCategoryOrder(userId, teamId string, categ
|
||||
|
||||
//nolint:unparam
|
||||
func (s SqlChannelStore) UpdateSidebarCategories(userId, teamId string, categories []*model.SidebarCategoryWithChannels) (updated []*model.SidebarCategoryWithChannels, original []*model.SidebarCategoryWithChannels, err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -865,7 +865,7 @@ func (s SqlChannelStore) UpdateSidebarCategories(userId, teamId string, categori
|
||||
// UpdateSidebarChannelsByPreferences is called when the Preference table is being updated to keep SidebarCategories in sync
|
||||
// At the moment, it's only handling Favorites and NOT DMs/GMs (those will be handled client side)
|
||||
func (s SqlChannelStore) UpdateSidebarChannelsByPreferences(preferences model.Preferences) (err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "UpdateSidebarChannelsByPreferences: begin_transaction")
|
||||
}
|
||||
@@ -1013,7 +1013,7 @@ func (s SqlChannelStore) addChannelToFavoritesCategoryT(transaction *sqlxTxWrapp
|
||||
// DeleteSidebarChannelsByPreferences is called when the Preference table is being updated to keep SidebarCategories in sync
|
||||
// At the moment, it's only handling Favorites and NOT DMs/GMs (those will be handled client side)
|
||||
func (s SqlChannelStore) DeleteSidebarChannelsByPreferences(preferences model.Preferences) (err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "DeleteSidebarChannelsByPreferences: begin_transaction")
|
||||
}
|
||||
@@ -1041,7 +1041,7 @@ func (s SqlChannelStore) DeleteSidebarChannelsByPreferences(preferences model.Pr
|
||||
//nolint:unparam
|
||||
func (s SqlChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) error {
|
||||
// if channel is being moved, remove it from the categories, since it's possible that there's no matching category in the new team
|
||||
if _, err := s.GetMasterX().Exec("DELETE FROM SidebarChannels WHERE ChannelId=?", channel.Id); err != nil {
|
||||
if _, err := s.GetMaster().Exec("DELETE FROM SidebarChannels WHERE ChannelId=?", channel.Id); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete SidebarChannels with channelId=%s", channel.Id)
|
||||
}
|
||||
return nil
|
||||
@@ -1068,10 +1068,10 @@ func (s SqlChannelStore) ClearSidebarOnTeamLeave(userId, teamId string) error {
|
||||
AND SidebarCategories.TeamId = ?
|
||||
AND SidebarChannels.UserId = ?)`
|
||||
}
|
||||
if _, err := s.GetMasterX().Exec(deleteQuery, teamId, userId); err != nil {
|
||||
if _, err := s.GetMaster().Exec(deleteQuery, teamId, userId); err != nil {
|
||||
return errors.Wrap(err, "failed to delete from SidebarChannels")
|
||||
}
|
||||
if _, err := s.GetMasterX().Exec("DELETE FROM SidebarCategories WHERE SidebarCategories.TeamId = ? AND SidebarCategories.UserId = ?", teamId, userId); err != nil {
|
||||
if _, err := s.GetMaster().Exec("DELETE FROM SidebarCategories WHERE SidebarCategories.TeamId = ? AND SidebarCategories.UserId = ?", teamId, userId); err != nil {
|
||||
return errors.Wrap(err, "failed to delete from SidebarCategories")
|
||||
}
|
||||
return nil
|
||||
@@ -1080,7 +1080,7 @@ func (s SqlChannelStore) ClearSidebarOnTeamLeave(userId, teamId string) error {
|
||||
// DeleteSidebarCategory removes a custom category and moves any channels into it into the Channels and Direct Messages
|
||||
// categories respectively. Assumes that the provided user ID and team ID match the given category ID.
|
||||
func (s SqlChannelStore) DeleteSidebarCategory(categoryId string) (err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -1141,6 +1141,6 @@ func (s SqlChannelStore) DeleteAllSidebarChannelForChannel(channelID string) err
|
||||
return errors.Wrap(err, "delete_all_sidebar_channel_for_channel_to_sql")
|
||||
}
|
||||
|
||||
_, err = s.GetMasterX().Exec(query, args...)
|
||||
_, err = s.GetMaster().Exec(query, args...)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func (s sqlClusterDiscoveryStore) Save(ClusterDiscovery *model.ClusterDiscovery)
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().NamedExec(`
|
||||
if _, err := s.GetMaster().NamedExec(`
|
||||
INSERT INTO
|
||||
ClusterDiscovery
|
||||
(Id, Type, ClusterName, Hostname, GossipPort, Port, CreateAt, LastPingAt)
|
||||
@@ -49,7 +49,7 @@ func (s sqlClusterDiscoveryStore) Delete(ClusterDiscovery *model.ClusterDiscover
|
||||
return false, errors.Wrap(err, "cluster_discovery_tosql")
|
||||
}
|
||||
|
||||
res, err := s.GetMasterX().Exec(queryString, args...)
|
||||
res, err := s.GetMaster().Exec(queryString, args...)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "failed to delete ClusterDiscovery")
|
||||
}
|
||||
@@ -76,7 +76,7 @@ func (s sqlClusterDiscoveryStore) Exists(ClusterDiscovery *model.ClusterDiscover
|
||||
}
|
||||
|
||||
var count int
|
||||
if err := s.GetMasterX().Get(&count, queryString, args...); err != nil {
|
||||
if err := s.GetMaster().Get(&count, queryString, args...); err != nil {
|
||||
return false, errors.Wrap(err, "failed to count ClusterDiscovery")
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ func (s sqlClusterDiscoveryStore) GetAll(ClusterDiscoveryType, clusterName strin
|
||||
}
|
||||
|
||||
list := []*model.ClusterDiscovery{}
|
||||
if err := s.GetMasterX().Select(&list, queryString, args...); err != nil {
|
||||
if err := s.GetMaster().Select(&list, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find ClusterDiscovery")
|
||||
}
|
||||
return list, nil
|
||||
@@ -116,7 +116,7 @@ func (s sqlClusterDiscoveryStore) SetLastPingAt(ClusterDiscovery *model.ClusterD
|
||||
return errors.Wrap(err, "cluster_discovery_tosql")
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(queryString, args...); err != nil {
|
||||
return errors.Wrap(err, "failed to update ClusterDiscovery")
|
||||
}
|
||||
return nil
|
||||
@@ -132,7 +132,7 @@ func (s sqlClusterDiscoveryStore) Cleanup() error {
|
||||
return errors.Wrap(err, "cluster_discovery_tosql")
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(queryString, args...); err != nil {
|
||||
return errors.Wrap(err, "failed to delete ClusterDiscoveries")
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -42,7 +42,7 @@ func (s SqlCommandStore) Save(command *model.Command) (*model.Command, error) {
|
||||
// Trigger is a keyword
|
||||
trigger := s.toReserveCase("trigger")
|
||||
|
||||
if _, err := s.GetMasterX().NamedExec(`INSERT INTO Commands (Id, Token, CreateAt,
|
||||
if _, err := s.GetMaster().NamedExec(`INSERT INTO Commands (Id, Token, CreateAt,
|
||||
UpdateAt, DeleteAt, CreatorId, TeamId, `+trigger+`, Method, Username,
|
||||
IconURL, AutoComplete, AutoCompleteDesc, AutoCompleteHint, DisplayName, Description,
|
||||
URL, PluginId)
|
||||
@@ -63,7 +63,7 @@ func (s SqlCommandStore) Get(id string) (*model.Command, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "commands_tosql")
|
||||
}
|
||||
if err = s.GetReplicaX().Get(&command, query, args...); err == sql.ErrNoRows {
|
||||
if err = s.GetReplica().Get(&command, query, args...); err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Command", id)
|
||||
} else if err != nil {
|
||||
return nil, errors.Wrapf(err, "selectone: command_id=%s", id)
|
||||
@@ -80,7 +80,7 @@ func (s SqlCommandStore) GetByTeam(teamId string) ([]*model.Command, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "commands_tosql")
|
||||
}
|
||||
if err := s.GetReplicaX().Select(&commands, sql, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&commands, sql, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "select: team_id=%s", teamId)
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ func (s SqlCommandStore) GetByTrigger(teamId string, trigger string) (*model.Com
|
||||
return nil, errors.Wrapf(err, "commands_tosql")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Get(&command, query, args...); err == sql.ErrNoRows {
|
||||
if err := s.GetReplica().Get(&command, query, args...); err == sql.ErrNoRows {
|
||||
errorId := "teamId=" + teamId + ", trigger=" + trigger
|
||||
return nil, store.NewErrNotFound("Command", errorId)
|
||||
} else if err != nil {
|
||||
@@ -121,7 +121,7 @@ func (s SqlCommandStore) Delete(commandId string, time int64) error {
|
||||
return errors.Wrapf(err, "commands_tosql")
|
||||
}
|
||||
|
||||
_, err = s.GetMasterX().Exec(sql, args...)
|
||||
_, err = s.GetMaster().Exec(sql, args...)
|
||||
if err != nil {
|
||||
errors.Wrapf(err, "delete: command_id=%s", commandId)
|
||||
}
|
||||
@@ -136,7 +136,7 @@ func (s SqlCommandStore) PermanentDeleteByTeam(teamId string) error {
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "commands_tosql")
|
||||
}
|
||||
_, err = s.GetMasterX().Exec(sql, args...)
|
||||
_, err = s.GetMaster().Exec(sql, args...)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "delete: team_id=%s", teamId)
|
||||
}
|
||||
@@ -150,7 +150,7 @@ func (s SqlCommandStore) PermanentDeleteByUser(userId string) error {
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "commands_tosql")
|
||||
}
|
||||
_, err = s.GetMasterX().Exec(sql, args...)
|
||||
_, err = s.GetMaster().Exec(sql, args...)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "delete: user_id=%s", userId)
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func (s SqlCommandStore) Update(cmd *model.Command) (*model.Command, error) {
|
||||
return nil, errors.Wrap(err, "commands_tosql")
|
||||
}
|
||||
|
||||
res, err := s.GetMasterX().Exec(queryString, args...)
|
||||
res, err := s.GetMaster().Exec(queryString, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to update commands")
|
||||
}
|
||||
@@ -222,7 +222,7 @@ func (s SqlCommandStore) AnalyticsCommandCount(teamId string) (int64, error) {
|
||||
}
|
||||
|
||||
var c int64
|
||||
err = s.GetReplicaX().Get(&c, sql, args...)
|
||||
err = s.GetReplica().Get(&c, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "unable to count the commands: team_id=%s", teamId)
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func (s SqlCommandWebhookStore) Save(webhook *model.CommandWebhook) (*model.Comm
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().NamedExec(`INSERT INTO CommandWebhooks
|
||||
if _, err := s.GetMaster().NamedExec(`INSERT INTO CommandWebhooks
|
||||
(Id,CreateAt,CommandId,UserId,ChannelId,RootId,UseCount)
|
||||
Values
|
||||
(:Id, :CreateAt, :CommandId, :UserId, :ChannelId, :RootId, :UseCount)`, webhook); err != nil {
|
||||
@@ -58,7 +58,7 @@ func (s SqlCommandWebhookStore) Get(id string) (*model.CommandWebhook, error) {
|
||||
return nil, errors.Wrap(err, "get_tosql")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Get(&webhook, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&webhook, queryString, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("CommandWebhook", id)
|
||||
}
|
||||
@@ -80,7 +80,7 @@ func (s SqlCommandWebhookStore) TryUse(id string, limit int) error {
|
||||
return errors.Wrap(err, "tryuse_tosql")
|
||||
}
|
||||
|
||||
if sqlResult, err := s.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
if sqlResult, err := s.GetMaster().Exec(queryString, args...); err != nil {
|
||||
return errors.Wrapf(err, "tryuse: id=%s limit=%d", id, limit)
|
||||
} else if rows, err := sqlResult.RowsAffected(); rows == 0 {
|
||||
return store.NewErrInvalidInput("CommandWebhook", "id", id).Wrap(err)
|
||||
@@ -102,7 +102,7 @@ func (s SqlCommandWebhookStore) Cleanup() {
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(queryString, args...); err != nil {
|
||||
mlog.Error("Unable to cleanup command webhook store.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func (s SqlComplianceStore) Save(compliance *model.Compliance) (*model.Complianc
|
||||
query := `INSERT INTO Compliances (Id, CreateAt, UserId, Status, Count, ` + desc + `, Type, StartAt, EndAt, Keywords, Emails)
|
||||
VALUES
|
||||
(:Id, :CreateAt, :UserId, :Status, :Count, :Desc, :Type, :StartAt, :EndAt, :Keywords, :Emails)`
|
||||
if _, err := s.GetMasterX().NamedExec(query, compliance); err != nil {
|
||||
if _, err := s.GetMaster().NamedExec(query, compliance); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to save Compliance")
|
||||
}
|
||||
return compliance, nil
|
||||
@@ -68,7 +68,7 @@ func (s SqlComplianceStore) Update(compliance *model.Compliance) (*model.Complia
|
||||
return nil, errors.Wrap(err, "compliances_tosql")
|
||||
}
|
||||
|
||||
res, err := s.GetMasterX().Exec(queryString, args...)
|
||||
res, err := s.GetMaster().Exec(queryString, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to update Compliance")
|
||||
}
|
||||
@@ -85,7 +85,7 @@ func (s SqlComplianceStore) Update(compliance *model.Compliance) (*model.Complia
|
||||
func (s SqlComplianceStore) GetAll(offset, limit int) (model.Compliances, error) {
|
||||
query := "SELECT * FROM Compliances ORDER BY CreateAt DESC LIMIT ? OFFSET ?"
|
||||
compliances := model.Compliances{}
|
||||
if err := s.GetReplicaX().Select(&compliances, query, limit, offset); err != nil {
|
||||
if err := s.GetReplica().Select(&compliances, query, limit, offset); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find all Compliances")
|
||||
}
|
||||
return compliances, nil
|
||||
@@ -93,7 +93,7 @@ func (s SqlComplianceStore) GetAll(offset, limit int) (model.Compliances, error)
|
||||
|
||||
func (s SqlComplianceStore) Get(id string) (*model.Compliance, error) {
|
||||
var compliance model.Compliance
|
||||
if err := s.GetReplicaX().Get(&compliance, `SELECT * FROM Compliances WHERE Id = ?`, id); err != nil {
|
||||
if err := s.GetReplica().Get(&compliance, `SELECT * FROM Compliances WHERE Id = ?`, id); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Compliances", id)
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func (s SqlComplianceStore) ComplianceExport(job *model.Compliance, cursor model
|
||||
` + keywordQuery + `
|
||||
ORDER BY Posts.CreateAt, Posts.Id
|
||||
LIMIT ?`
|
||||
if err := s.GetReplicaX().Select(&channelPosts, channelsQuery, argsChannelsQuery...); err != nil {
|
||||
if err := s.GetReplica().Select(&channelPosts, channelsQuery, argsChannelsQuery...); err != nil {
|
||||
return nil, cursor, errors.Wrap(err, "unable to export compliance")
|
||||
}
|
||||
if len(channelPosts) < limit {
|
||||
@@ -257,7 +257,7 @@ func (s SqlComplianceStore) ComplianceExport(job *model.Compliance, cursor model
|
||||
ORDER BY Posts.CreateAt, Posts.Id
|
||||
LIMIT ?`
|
||||
|
||||
if err := s.GetReplicaX().Select(&directMessagePosts, directMessagesQuery, argsDirectMessagesQuery...); err != nil {
|
||||
if err := s.GetReplica().Select(&directMessagePosts, directMessagesQuery, argsDirectMessagesQuery...); err != nil {
|
||||
return nil, cursor, errors.Wrap(err, "unable to export compliance")
|
||||
}
|
||||
if len(directMessagePosts) < limit {
|
||||
@@ -330,7 +330,7 @@ func (s SqlComplianceStore) MessageExport(c request.CTX, cursor model.MessageExp
|
||||
}
|
||||
|
||||
cposts := []*model.MessageExport{}
|
||||
if err := s.GetReplicaX().SelectCtx(c.Context(), &cposts, query, args...); err != nil {
|
||||
if err := s.GetReplica().SelectCtx(c.Context(), &cposts, query, args...); err != nil {
|
||||
return nil, cursor, errors.Wrap(err, "unable to export messages")
|
||||
}
|
||||
if len(cposts) > 0 {
|
||||
|
||||
@@ -48,7 +48,7 @@ func HasMaster(ctx context.Context) bool {
|
||||
// DBXFromContext is a helper utility that returns the sqlx DB handle from a given context.
|
||||
func (ss *SqlStore) DBXFromContext(ctx context.Context) *sqlxDBWrapper {
|
||||
if HasMaster(ctx) {
|
||||
return ss.GetMasterX()
|
||||
return ss.GetMaster()
|
||||
}
|
||||
return ss.GetReplicaX()
|
||||
return ss.GetReplica()
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func (s *SqlDesktopTokensStore) GetUserId(token string, minCreateAt int64) (*str
|
||||
})
|
||||
|
||||
dt := struct{ UserId string }{}
|
||||
err := s.GetReplicaX().GetBuilder(&dt, query)
|
||||
err := s.GetReplica().GetBuilder(&dt, query)
|
||||
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
@@ -58,7 +58,7 @@ func (s *SqlDesktopTokensStore) Insert(token string, createAt int64, userId stri
|
||||
return errors.Wrap(err, "insert_desktoptokens_tosql")
|
||||
}
|
||||
|
||||
if _, err = s.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err = s.GetMaster().Exec(query, args...); err != nil {
|
||||
return errors.Wrap(err, "failed to insert token row")
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ func (s *SqlDesktopTokensStore) Delete(token string) error {
|
||||
return errors.Wrap(err, "delete_desktoptokens_tosql")
|
||||
}
|
||||
|
||||
if _, err = s.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err = s.GetMaster().Exec(query, args...); err != nil {
|
||||
return errors.Wrap(err, "failed to delete token row")
|
||||
}
|
||||
return nil
|
||||
@@ -97,7 +97,7 @@ func (s *SqlDesktopTokensStore) DeleteByUserId(userId string) error {
|
||||
return errors.Wrap(err, "delete_by_userid_desktoptokens_tosql")
|
||||
}
|
||||
|
||||
if _, err = s.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err = s.GetMaster().Exec(query, args...); err != nil {
|
||||
return errors.Wrap(err, "failed to delete token row")
|
||||
}
|
||||
return nil
|
||||
@@ -116,7 +116,7 @@ func (s *SqlDesktopTokensStore) DeleteOlderThan(minCreateAt int64) error {
|
||||
return errors.Wrap(err, "delete_old_desktoptokens_tosql")
|
||||
}
|
||||
|
||||
if _, err = s.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err = s.GetMaster().Exec(query, args...); err != nil {
|
||||
return errors.Wrap(err, "failed to delete token row")
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -76,7 +76,7 @@ func (s *SqlDraftStore) Get(userId, channelId, rootId string, includeDeleted boo
|
||||
}
|
||||
|
||||
dt := model.Draft{}
|
||||
err := s.GetReplicaX().GetBuilder(&dt, query)
|
||||
err := s.GetReplica().GetBuilder(&dt, query)
|
||||
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
@@ -109,7 +109,7 @@ func (s *SqlDraftStore) Upsert(draft *model.Draft) (*model.Draft, error) {
|
||||
return nil, errors.Wrap(err, "save_draft_tosql")
|
||||
}
|
||||
|
||||
if _, err = s.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err = s.GetMaster().Exec(query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to upsert Draft")
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ func (s *SqlDraftStore) GetDraftsForUser(userID, teamID string) ([]*model.Draft,
|
||||
})
|
||||
}
|
||||
|
||||
err := s.GetReplicaX().SelectBuilder(&drafts, query)
|
||||
err := s.GetReplica().SelectBuilder(&drafts, query)
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get user drafts")
|
||||
@@ -172,7 +172,7 @@ func (s *SqlDraftStore) Delete(userID, channelID, rootID string) error {
|
||||
return errors.Wrapf(err, "failed to convert to sql")
|
||||
}
|
||||
|
||||
_, err = s.GetMasterX().Exec(sql, args...)
|
||||
_, err = s.GetMaster().Exec(sql, args...)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to delete Draft")
|
||||
@@ -195,7 +195,7 @@ func (s *SqlDraftStore) DeleteDraftsAssociatedWithPost(channelID, rootID string)
|
||||
return errors.Wrapf(err, "failed to convert to sql")
|
||||
}
|
||||
|
||||
_, err = s.GetMasterX().Exec(sql, args...)
|
||||
_, err = s.GetMaster().Exec(sql, args...)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to delete Draft")
|
||||
@@ -218,7 +218,7 @@ func (s *SqlDraftStore) determineMaxDraftSize() int {
|
||||
if s.DriverName() == model.DatabaseDriverPostgres {
|
||||
// The Draft.Message column in Postgres has historically been VARCHAR(4000), but
|
||||
// may be manually enlarged to support longer drafts.
|
||||
if err := s.GetReplicaX().Get(&maxDraftSizeBytes, `
|
||||
if err := s.GetReplica().Get(&maxDraftSizeBytes, `
|
||||
SELECT
|
||||
COALESCE(character_maximum_length, 0)
|
||||
FROM
|
||||
@@ -232,7 +232,7 @@ func (s *SqlDraftStore) determineMaxDraftSize() int {
|
||||
} else if s.DriverName() == model.DatabaseDriverMysql {
|
||||
// The Draft.Message column in MySQL has historically been TEXT, with a maximum
|
||||
// limit of 65535.
|
||||
if err := s.GetReplicaX().Get(&maxDraftSizeBytes, `
|
||||
if err := s.GetReplica().Get(&maxDraftSizeBytes, `
|
||||
SELECT
|
||||
COALESCE(CHARACTER_MAXIMUM_LENGTH, 0)
|
||||
FROM
|
||||
@@ -276,7 +276,7 @@ func (s *SqlDraftStore) GetLastCreateAtAndUserIdValuesForEmptyDraftsMigration(cr
|
||||
OrderBy("CreateAt", "UserId ASC").
|
||||
Limit(100)
|
||||
|
||||
err := s.GetReplicaX().SelectBuilder(&drafts, query)
|
||||
err := s.GetReplica().SelectBuilder(&drafts, query)
|
||||
if err != nil {
|
||||
return 0, "", errors.Wrap(err, "failed to get the list of drafts")
|
||||
}
|
||||
@@ -337,7 +337,7 @@ func (s *SqlDraftStore) DeleteEmptyDraftsByCreateAtAndUserId(createAt int64, use
|
||||
).Where(sq.Eq{"Message": ""})
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().ExecBuilder(builder); err != nil {
|
||||
if _, err := s.GetMaster().ExecBuilder(builder); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete empty drafts")
|
||||
}
|
||||
|
||||
@@ -393,7 +393,7 @@ func (s *SqlDraftStore) DeleteOrphanDraftsByCreateAtAndUserId(createAt int64, us
|
||||
Suffix("AND (d.RootId IN (SELECT Id FROM Posts WHERE DeleteAt <> 0) OR NOT EXISTS (SELECT 1 FROM Posts WHERE Posts.Id = d.RootId))")
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().ExecBuilder(builder); err != nil {
|
||||
if _, err := s.GetMaster().ExecBuilder(builder); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete orphan drafts")
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ func (es SqlEmojiStore) Save(emoji *model.Emoji) (*model.Emoji, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := es.GetMasterX().NamedExec(`INSERT INTO Emoji
|
||||
if _, err := es.GetMaster().NamedExec(`INSERT INTO Emoji
|
||||
(Id, CreateAt, UpdateAt, DeleteAt, CreatorId, Name)
|
||||
VALUES
|
||||
(:Id, :CreateAt, :UpdateAt, :DeleteAt, :CreatorId, :Name)`, emoji); err != nil {
|
||||
@@ -82,14 +82,14 @@ func (es SqlEmojiStore) GetList(offset, limit int, sort string) ([]*model.Emoji,
|
||||
|
||||
query += " LIMIT ? OFFSET ?"
|
||||
|
||||
if err := es.GetReplicaX().Select(&emojis, query, limit, offset); err != nil {
|
||||
if err := es.GetReplica().Select(&emojis, query, limit, offset); err != nil {
|
||||
return nil, errors.Wrap(err, "could not get list of emojis")
|
||||
}
|
||||
return emojis, nil
|
||||
}
|
||||
|
||||
func (es SqlEmojiStore) Delete(emoji *model.Emoji, time int64) error {
|
||||
if sqlResult, err := es.GetMasterX().Exec(
|
||||
if sqlResult, err := es.GetMaster().Exec(
|
||||
`UPDATE
|
||||
Emoji
|
||||
SET
|
||||
@@ -118,7 +118,7 @@ func (es SqlEmojiStore) Search(name string, prefixOnly bool, limit int) ([]*mode
|
||||
|
||||
term += name + "%"
|
||||
|
||||
if err := es.GetReplicaX().Select(&emojis,
|
||||
if err := es.GetReplica().Select(&emojis,
|
||||
`SELECT
|
||||
*
|
||||
FROM
|
||||
|
||||
@@ -126,7 +126,7 @@ func (fs SqlFileInfoStore) Save(rctx request.CTX, info *model.FileInfo) (*model.
|
||||
:Name, :Extension, :Size, :MimeType, :Width, :Height, :HasPreviewImage, :MiniPreview, :Content, :RemoteId)
|
||||
`
|
||||
|
||||
if _, err := fs.GetMasterX().NamedExec(query, info); err != nil {
|
||||
if _, err := fs.GetMaster().NamedExec(query, info); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to save FileInfo")
|
||||
}
|
||||
return info, nil
|
||||
@@ -146,7 +146,7 @@ func (fs SqlFileInfoStore) GetByIds(ids []string) ([]*model.FileInfo, error) {
|
||||
}
|
||||
|
||||
items := []fileInfoWithChannelID{}
|
||||
if err := fs.GetReplicaX().Select(&items, queryString, args...); err != nil {
|
||||
if err := fs.GetReplica().Select(&items, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find FileInfos")
|
||||
}
|
||||
if len(items) == 0 {
|
||||
@@ -194,7 +194,7 @@ func (fs SqlFileInfoStore) Upsert(rctx request.CTX, info *model.FileInfo) (*mode
|
||||
return nil, errors.Wrap(err, "file_info_tosql")
|
||||
}
|
||||
|
||||
sqlResult, err := fs.GetMasterX().Exec(queryString, args...)
|
||||
sqlResult, err := fs.GetMaster().Exec(queryString, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to update FileInfo")
|
||||
}
|
||||
@@ -222,9 +222,9 @@ func (fs SqlFileInfoStore) get(id string, fromMaster bool) (*model.FileInfo, err
|
||||
return nil, errors.Wrap(err, "file_info_tosql")
|
||||
}
|
||||
|
||||
db := fs.GetReplicaX()
|
||||
db := fs.GetReplica()
|
||||
if fromMaster {
|
||||
db = fs.GetMasterX()
|
||||
db = fs.GetMaster()
|
||||
}
|
||||
|
||||
if err := db.Get(info, queryString, args...); err != nil {
|
||||
@@ -304,7 +304,7 @@ func (fs SqlFileInfoStore) GetWithOptions(page, perPage int, opt *model.GetFileI
|
||||
return nil, errors.Wrap(err, "file_info_tosql")
|
||||
}
|
||||
infos := []*model.FileInfo{}
|
||||
if err := fs.GetReplicaX().Select(&infos, queryString, args...); err != nil {
|
||||
if err := fs.GetReplica().Select(&infos, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find FileInfos")
|
||||
}
|
||||
return infos, nil
|
||||
@@ -325,7 +325,7 @@ func (fs SqlFileInfoStore) GetByPath(path string) (*model.FileInfo, error) {
|
||||
return nil, errors.Wrap(err, "file_info_tosql")
|
||||
}
|
||||
|
||||
if err := fs.GetReplicaX().Get(info, queryString, args...); err != nil {
|
||||
if err := fs.GetReplica().Get(info, queryString, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("FileInfo", fmt.Sprintf("path=%s", path))
|
||||
}
|
||||
@@ -341,10 +341,10 @@ func (fs SqlFileInfoStore) InvalidateFileInfosForPostCache(postId string, delete
|
||||
func (fs SqlFileInfoStore) GetForPost(postId string, readFromMaster, includeDeleted, allowFromCache bool) ([]*model.FileInfo, error) {
|
||||
infos := []*model.FileInfo{}
|
||||
|
||||
dbmap := fs.GetReplicaX()
|
||||
dbmap := fs.GetReplica()
|
||||
|
||||
if readFromMaster {
|
||||
dbmap = fs.GetMasterX()
|
||||
dbmap = fs.GetMaster()
|
||||
}
|
||||
|
||||
query := fs.getQueryBuilder().
|
||||
@@ -383,7 +383,7 @@ func (fs SqlFileInfoStore) GetForUser(userId string) ([]*model.FileInfo, error)
|
||||
return nil, errors.Wrap(err, "file_info_tosql")
|
||||
}
|
||||
|
||||
if err := fs.GetReplicaX().Select(&infos, queryString, args...); err != nil {
|
||||
if err := fs.GetReplica().Select(&infos, queryString, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find FileInfos with creatorId=%s", userId)
|
||||
}
|
||||
return infos, nil
|
||||
@@ -407,7 +407,7 @@ func (fs SqlFileInfoStore) AttachToPost(rctx request.CTX, fileId, postId, channe
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "file_info_tosql")
|
||||
}
|
||||
sqlResult, err := fs.GetMasterX().Exec(queryString, args...)
|
||||
sqlResult, err := fs.GetMaster().Exec(queryString, args...)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to update FileInfo with id=%s and postId=%s", fileId, postId)
|
||||
}
|
||||
@@ -434,7 +434,7 @@ func (fs SqlFileInfoStore) SetContent(rctx request.CTX, fileId, content string)
|
||||
return errors.Wrap(err, "file_info_tosql")
|
||||
}
|
||||
|
||||
_, err = fs.GetMasterX().Exec(queryString, args...)
|
||||
_, err = fs.GetMaster().Exec(queryString, args...)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to update FileInfo content with id=%s", fileId)
|
||||
}
|
||||
@@ -443,7 +443,7 @@ func (fs SqlFileInfoStore) SetContent(rctx request.CTX, fileId, content string)
|
||||
}
|
||||
|
||||
func (fs SqlFileInfoStore) DeleteForPost(rctx request.CTX, postId string) (string, error) {
|
||||
if _, err := fs.GetMasterX().Exec(
|
||||
if _, err := fs.GetMaster().Exec(
|
||||
`UPDATE
|
||||
FileInfo
|
||||
SET
|
||||
@@ -456,14 +456,14 @@ func (fs SqlFileInfoStore) DeleteForPost(rctx request.CTX, postId string) (strin
|
||||
}
|
||||
|
||||
func (fs SqlFileInfoStore) PermanentDeleteForPost(rctx request.CTX, postID string) error {
|
||||
if _, err := fs.GetMasterX().Exec(`DELETE FROM FileInfo WHERE PostId = ?`, postID); err != nil {
|
||||
if _, err := fs.GetMaster().Exec(`DELETE FROM FileInfo WHERE PostId = ?`, postID); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete FileInfo with PostId=%s", postID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fs SqlFileInfoStore) PermanentDelete(rctx request.CTX, fileId string) error {
|
||||
if _, err := fs.GetMasterX().Exec(`DELETE FROM FileInfo WHERE Id = ?`, fileId); err != nil {
|
||||
if _, err := fs.GetMaster().Exec(`DELETE FROM FileInfo WHERE Id = ?`, fileId); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete FileInfo with id=%s", fileId)
|
||||
}
|
||||
return nil
|
||||
@@ -477,7 +477,7 @@ func (fs SqlFileInfoStore) PermanentDeleteBatch(rctx request.CTX, endTime int64,
|
||||
query = "DELETE from FileInfo WHERE CreateAt < ? AND CreatorId != ? LIMIT ?"
|
||||
}
|
||||
|
||||
sqlResult, err := fs.GetMasterX().Exec(query, endTime, model.BookmarkFileOwner, limit)
|
||||
sqlResult, err := fs.GetMaster().Exec(query, endTime, model.BookmarkFileOwner, limit)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to delete FileInfos in batch")
|
||||
}
|
||||
@@ -493,7 +493,7 @@ func (fs SqlFileInfoStore) PermanentDeleteBatch(rctx request.CTX, endTime int64,
|
||||
func (fs SqlFileInfoStore) PermanentDeleteByUser(rctx request.CTX, userId string) (int64, error) {
|
||||
query := "DELETE from FileInfo WHERE CreatorId = ?"
|
||||
|
||||
sqlResult, err := fs.GetMasterX().Exec(query, userId)
|
||||
sqlResult, err := fs.GetMaster().Exec(query, userId)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "failed to delete FileInfo with creatorId=%s", userId)
|
||||
}
|
||||
@@ -699,7 +699,7 @@ func (fs SqlFileInfoStore) CountAll() (int64, error) {
|
||||
}
|
||||
|
||||
var count int64
|
||||
err = fs.GetReplicaX().Get(&count, queryString, args...)
|
||||
err = fs.GetReplica().Get(&count, queryString, args...)
|
||||
if err != nil {
|
||||
return int64(0), errors.Wrap(err, "failed to count Files")
|
||||
}
|
||||
@@ -744,7 +744,7 @@ func (fs SqlFileInfoStore) GetStorageUsage(allowFromCache, includeDeleted bool)
|
||||
}
|
||||
|
||||
var size int64
|
||||
err := fs.GetReplicaX().GetBuilder(&size, query)
|
||||
err := fs.GetReplica().GetBuilder(&size, query)
|
||||
if err != nil {
|
||||
return int64(0), errors.Wrap(err, "failed to get storage usage")
|
||||
}
|
||||
@@ -786,7 +786,7 @@ func (fs *SqlFileInfoStore) GetUptoNSizeFileTime(n int64) (int64, error) {
|
||||
}
|
||||
|
||||
var createAt int64
|
||||
if err := fs.GetReplicaX().Get(&createAt, query, queryArgs...); err != nil {
|
||||
if err := fs.GetReplica().Get(&createAt, query, queryArgs...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return 0, store.NewErrNotFound("File", "none")
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ func (s *SqlGroupStore) Create(group *model.Group) (*model.Group, error) {
|
||||
group.CreateAt = model.GetMillis()
|
||||
group.UpdateAt = group.CreateAt
|
||||
|
||||
if _, err := s.GetMasterX().NamedExec(`INSERT INTO UserGroups
|
||||
if _, err := s.GetMaster().NamedExec(`INSERT INTO UserGroups
|
||||
(Id, Name, DisplayName, Description, Source, RemoteId, CreateAt, UpdateAt, DeleteAt, AllowReference)
|
||||
VALUES
|
||||
(:Id, :Name, :DisplayName, :Description, :Source, :RemoteId, :CreateAt, :UpdateAt, :DeleteAt, :AllowReference)`, group); err != nil {
|
||||
@@ -114,7 +114,7 @@ func (s *SqlGroupStore) CreateWithUserIds(g *model.GroupWithUserIds) (_ *model.G
|
||||
return nil, err
|
||||
}
|
||||
|
||||
txn, err := s.GetMasterX().Beginx()
|
||||
txn, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -181,7 +181,7 @@ func (s *SqlGroupStore) checkUsersExist(userIDs []string) error {
|
||||
return err
|
||||
}
|
||||
var rows []string
|
||||
err = s.GetReplicaX().Select(&rows, usersSelectQuery, usersSelectArgs...)
|
||||
err = s.GetReplica().Select(&rows, usersSelectQuery, usersSelectArgs...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -220,7 +220,7 @@ func (s *SqlGroupStore) Get(groupId string) (*model.Group, error) {
|
||||
From("UserGroups").
|
||||
Where(sq.Eq{"Id": groupId})
|
||||
|
||||
if err := s.GetReplicaX().GetBuilder(&group, builder); err != nil {
|
||||
if err := s.GetReplica().GetBuilder(&group, builder); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Group", groupId)
|
||||
}
|
||||
@@ -241,7 +241,7 @@ func (s *SqlGroupStore) GetByName(name string, opts model.GroupSearchOpts) (*mod
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "get_by_name_tosql")
|
||||
}
|
||||
if err := s.GetReplicaX().Get(&group, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&group, queryString, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Group", fmt.Sprintf("name=%s", name))
|
||||
}
|
||||
@@ -258,7 +258,7 @@ func (s *SqlGroupStore) GetByIDs(groupIDs []string) ([]*model.Group, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "get_by_ids_tosql")
|
||||
}
|
||||
if err := s.GetReplicaX().Select(&groups, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&groups, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Groups by ids")
|
||||
}
|
||||
return groups, nil
|
||||
@@ -274,7 +274,7 @@ func (s *SqlGroupStore) GetByRemoteID(remoteID string, groupSource model.GroupSo
|
||||
"Source": groupSource,
|
||||
})
|
||||
|
||||
if err := s.GetReplicaX().GetBuilder(&group, builder); err != nil {
|
||||
if err := s.GetReplica().GetBuilder(&group, builder); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Group", fmt.Sprintf("remoteId=%s", remoteID))
|
||||
}
|
||||
@@ -294,7 +294,7 @@ func (s *SqlGroupStore) GetAllBySource(groupSource model.GroupSource) ([]*model.
|
||||
"Source": groupSource,
|
||||
})
|
||||
|
||||
if err := s.GetReplicaX().SelectBuilder(&groups, builder); err != nil {
|
||||
if err := s.GetReplica().SelectBuilder(&groups, builder); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Groups by groupSource=%v", groupSource)
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ func (s *SqlGroupStore) GetByUser(userId string) ([]*model.Group, error) {
|
||||
"UserId": userId,
|
||||
})
|
||||
|
||||
if err := s.GetReplicaX().SelectBuilder(&groups, builder); err != nil {
|
||||
if err := s.GetReplica().SelectBuilder(&groups, builder); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Groups with userId=%s", userId)
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ func (s *SqlGroupStore) Update(group *model.Group) (*model.Group, error) {
|
||||
From("UserGroups").
|
||||
Where(sq.Eq{"Id": group.Id})
|
||||
|
||||
if err := s.GetReplicaX().GetBuilder(&retrievedGroup, builder); err != nil {
|
||||
if err := s.GetReplica().GetBuilder(&retrievedGroup, builder); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Group", group.Id)
|
||||
}
|
||||
@@ -347,7 +347,7 @@ func (s *SqlGroupStore) Update(group *model.Group) (*model.Group, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res, err := s.GetMasterX().NamedExec(`UPDATE UserGroups
|
||||
res, err := s.GetMaster().NamedExec(`UPDATE UserGroups
|
||||
SET Name=:Name, DisplayName=:DisplayName, Description=:Description, Source=:Source,
|
||||
RemoteId=:RemoteId, CreateAt=:CreateAt, UpdateAt=:UpdateAt, DeleteAt=:DeleteAt, AllowReference=:AllowReference
|
||||
WHERE Id=:Id`, group)
|
||||
@@ -375,7 +375,7 @@ func (s *SqlGroupStore) Delete(groupID string) (*model.Group, error) {
|
||||
"DeleteAt": 0,
|
||||
})
|
||||
|
||||
if err := s.GetReplicaX().GetBuilder(&group, builder); err != nil {
|
||||
if err := s.GetReplica().GetBuilder(&group, builder); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Group", groupID)
|
||||
}
|
||||
@@ -385,7 +385,7 @@ func (s *SqlGroupStore) Delete(groupID string) (*model.Group, error) {
|
||||
time := model.GetMillis()
|
||||
group.DeleteAt = time
|
||||
group.UpdateAt = time
|
||||
if _, err := s.GetMasterX().Exec(`UPDATE UserGroups
|
||||
if _, err := s.GetMaster().Exec(`UPDATE UserGroups
|
||||
SET DeleteAt=?, UpdateAt=?
|
||||
WHERE Id=? AND DeleteAt=0`, group.DeleteAt, group.UpdateAt, groupID); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to update Group with id=%s", groupID)
|
||||
@@ -404,7 +404,7 @@ func (s *SqlGroupStore) Restore(groupID string) (*model.Group, error) {
|
||||
sq.NotEq{"DeleteAt": 0},
|
||||
})
|
||||
|
||||
if err := s.GetReplicaX().GetBuilder(&group, builder); err != nil {
|
||||
if err := s.GetReplica().GetBuilder(&group, builder); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Group", groupID)
|
||||
}
|
||||
@@ -413,7 +413,7 @@ func (s *SqlGroupStore) Restore(groupID string) (*model.Group, error) {
|
||||
|
||||
group.UpdateAt = model.GetMillis()
|
||||
group.DeleteAt = 0
|
||||
if _, err := s.GetMasterX().Exec(`UPDATE UserGroups
|
||||
if _, err := s.GetMaster().Exec(`UPDATE UserGroups
|
||||
SET DeleteAt=0, UpdateAt=?
|
||||
WHERE Id=? AND DeleteAt!=0`, group.UpdateAt, groupID); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to update Group with id=%s", groupID)
|
||||
@@ -430,7 +430,7 @@ func (s *SqlGroupStore) GetMember(groupID, userID string) (*model.GroupMember, e
|
||||
Where(sq.Eq{"GroupId": groupID}).
|
||||
Where(sq.Eq{"DeleteAt": 0})
|
||||
var groupMember model.GroupMember
|
||||
if err := s.GetReplicaX().GetBuilder(&groupMember, builder); err != nil {
|
||||
if err := s.GetReplica().GetBuilder(&groupMember, builder); err != nil {
|
||||
return nil, errors.Wrap(err, "GetMember")
|
||||
}
|
||||
return &groupMember, nil
|
||||
@@ -449,7 +449,7 @@ func (s *SqlGroupStore) GetMemberUsers(groupID string) ([]*model.User, error) {
|
||||
"GroupId": groupID,
|
||||
})
|
||||
|
||||
if err := s.GetReplicaX().SelectBuilder(&groupMembers, builder); err != nil {
|
||||
if err := s.GetReplica().SelectBuilder(&groupMembers, builder); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find member Users for Group with id=%s", groupID)
|
||||
}
|
||||
|
||||
@@ -511,7 +511,7 @@ func (s *SqlGroupStore) GetMemberUsersSortedPage(groupID string, page int, perPa
|
||||
return nil, errors.Wrap(err, "")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Select(&groupMembers, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&groupMembers, queryString, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find member Users for Group with id=%s", groupID)
|
||||
}
|
||||
|
||||
@@ -526,7 +526,7 @@ func (s *SqlGroupStore) GetNonMemberUsersPage(groupID string, page int, perPage
|
||||
From("UserGroups").
|
||||
Where(sq.Eq{"Id": groupID})
|
||||
|
||||
if err := s.GetReplicaX().GetBuilder(&model.Group{}, builder); err != nil {
|
||||
if err := s.GetReplica().GetBuilder(&model.Group{}, builder); err != nil {
|
||||
return nil, errors.Wrap(err, "GetNonMemberUsersPage")
|
||||
}
|
||||
|
||||
@@ -542,7 +542,7 @@ func (s *SqlGroupStore) GetNonMemberUsersPage(groupID string, page int, perPage
|
||||
|
||||
builder = applyViewRestrictionsFilter(builder, viewRestrictions, true)
|
||||
|
||||
if err := s.GetReplicaX().SelectBuilder(&groupMembers, builder); err != nil {
|
||||
if err := s.GetReplica().SelectBuilder(&groupMembers, builder); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find member Users for Group with id=%s", groupID)
|
||||
}
|
||||
|
||||
@@ -570,7 +570,7 @@ func (s *SqlGroupStore) GetMemberCountWithRestrictions(groupID string, viewRestr
|
||||
}
|
||||
|
||||
var count int64
|
||||
err = s.GetReplicaX().Get(&count, queryString, args...)
|
||||
err = s.GetReplica().Get(&count, queryString, args...)
|
||||
if err != nil {
|
||||
return int64(0), errors.Wrapf(err, "failed to count member Users for Group with id=%s", groupID)
|
||||
}
|
||||
@@ -600,7 +600,7 @@ func (s *SqlGroupStore) GetMemberUsersInTeam(groupID string, teamID string) ([]*
|
||||
AND Users.DeleteAt = 0
|
||||
`
|
||||
|
||||
if err := s.GetReplicaX().Select(&groupMembers, query, groupID, teamID); err != nil {
|
||||
if err := s.GetReplica().Select(&groupMembers, query, groupID, teamID); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to member Users for groupId=%s and teamId=%s", groupID, teamID)
|
||||
}
|
||||
|
||||
@@ -635,7 +635,7 @@ func (s *SqlGroupStore) GetMemberUsersNotInChannel(groupID string, channelID str
|
||||
AND Users.DeleteAt = 0
|
||||
`
|
||||
|
||||
if err := s.GetReplicaX().Select(&groupMembers, query, groupID, channelID, channelID); err != nil {
|
||||
if err := s.GetReplica().Select(&groupMembers, query, groupID, channelID, channelID); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to member Users for groupId=%s and channelId!=%s", groupID, channelID)
|
||||
}
|
||||
|
||||
@@ -647,7 +647,7 @@ func (s *SqlGroupStore) UpsertMember(groupID string, userID string) (*model.Grou
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err = s.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err = s.GetMaster().Exec(query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to save GroupMember")
|
||||
}
|
||||
return members[0], nil
|
||||
@@ -658,7 +658,7 @@ func (s *SqlGroupStore) DeleteMember(groupID string, userID string) (*model.Grou
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err = s.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err = s.GetMaster().Exec(query, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to update GroupMember with groupId=%s and userId=%s", groupID, userID)
|
||||
}
|
||||
|
||||
@@ -669,7 +669,7 @@ func (s *SqlGroupStore) PermanentDeleteMembersByUser(userId string) error {
|
||||
builder := s.getQueryBuilder().
|
||||
Delete("GroupMembers").
|
||||
Where(sq.Eq{"UserId": userId})
|
||||
if _, err := s.GetMasterX().ExecBuilder(builder); err != nil {
|
||||
if _, err := s.GetMaster().ExecBuilder(builder); err != nil {
|
||||
return errors.Wrapf(err, "failed to permanent delete GroupMember with userId=%s", userId)
|
||||
}
|
||||
return nil
|
||||
@@ -693,7 +693,7 @@ func (s *SqlGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, insertErr = s.GetMasterX().NamedExec(`INSERT INTO GroupTeams
|
||||
_, insertErr = s.GetMaster().NamedExec(`INSERT INTO GroupTeams
|
||||
(GroupId, AutoAdd, SchemeAdmin, CreateAt, DeleteAt, UpdateAt, TeamId)
|
||||
VALUES
|
||||
(:GroupId, :AutoAdd, :SchemeAdmin, :CreateAt, :DeleteAt, :UpdateAt, :TeamId)`, groupSyncableToGroupTeam(groupSyncable))
|
||||
@@ -703,7 +703,7 @@ func (s *SqlGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, insertErr = s.GetMasterX().NamedExec(`INSERT INTO GroupChannels
|
||||
_, insertErr = s.GetMaster().NamedExec(`INSERT INTO GroupChannels
|
||||
(GroupId, AutoAdd, SchemeAdmin, CreateAt, DeleteAt, UpdateAt, ChannelId)
|
||||
VALUES
|
||||
(:GroupId, :AutoAdd, :SchemeAdmin, :CreateAt, :DeleteAt, :UpdateAt, :ChannelId)`, groupSyncableToGroupChannel(groupSyncable))
|
||||
@@ -738,11 +738,11 @@ func (s *SqlGroupStore) getGroupSyncable(groupID string, syncableID string, sync
|
||||
switch syncableType {
|
||||
case model.GroupSyncableTypeTeam:
|
||||
var team groupTeam
|
||||
err = s.GetReplicaX().Get(&team, `SELECT * FROM GroupTeams WHERE GroupId=? AND TeamId=?`, groupID, syncableID)
|
||||
err = s.GetReplica().Get(&team, `SELECT * FROM GroupTeams WHERE GroupId=? AND TeamId=?`, groupID, syncableID)
|
||||
result = &team
|
||||
case model.GroupSyncableTypeChannel:
|
||||
var ch groupChannel
|
||||
err = s.GetReplicaX().Get(&ch, `SELECT * FROM GroupChannels WHERE GroupId=? AND ChannelId=?`, groupID, syncableID)
|
||||
err = s.GetReplica().Get(&ch, `SELECT * FROM GroupChannels WHERE GroupId=? AND ChannelId=?`, groupID, syncableID)
|
||||
result = &ch
|
||||
}
|
||||
|
||||
@@ -798,7 +798,7 @@ func (s *SqlGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableTy
|
||||
GroupId = ? AND GroupTeams.DeleteAt = 0`
|
||||
|
||||
results := []*groupTeamJoin{}
|
||||
err := s.GetReplicaX().Select(&results, sqlQuery, groupID)
|
||||
err := s.GetReplica().Select(&results, sqlQuery, groupID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find GroupTeams with groupId=%s", groupID)
|
||||
}
|
||||
@@ -834,7 +834,7 @@ func (s *SqlGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableTy
|
||||
GroupId = ? AND GroupChannels.DeleteAt = 0`
|
||||
|
||||
results := []*groupChannelJoin{}
|
||||
err := s.GetReplicaX().Select(&results, sqlQuery, groupID)
|
||||
err := s.GetReplica().Select(&results, sqlQuery, groupID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find GroupChannels with groupId=%s", groupID)
|
||||
}
|
||||
@@ -885,7 +885,7 @@ func (s *SqlGroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable)
|
||||
|
||||
switch groupSyncable.Type {
|
||||
case model.GroupSyncableTypeTeam:
|
||||
_, err = s.GetMasterX().NamedExec(`UPDATE GroupTeams
|
||||
_, err = s.GetMaster().NamedExec(`UPDATE GroupTeams
|
||||
SET AutoAdd=:AutoAdd, SchemeAdmin=:SchemeAdmin, CreateAt=:CreateAt,
|
||||
DeleteAt=:DeleteAt, UpdateAt=:UpdateAt
|
||||
WHERE GroupId=:GroupId AND TeamId=:TeamId`, groupSyncableToGroupTeam(groupSyncable))
|
||||
@@ -897,7 +897,7 @@ func (s *SqlGroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable)
|
||||
return nil, channelErr
|
||||
}
|
||||
|
||||
_, err = s.GetMasterX().NamedExec(`UPDATE GroupChannels
|
||||
_, err = s.GetMaster().NamedExec(`UPDATE GroupChannels
|
||||
SET AutoAdd=:AutoAdd, SchemeAdmin=:SchemeAdmin, CreateAt=:CreateAt,
|
||||
DeleteAt=:DeleteAt, UpdateAt=:UpdateAt
|
||||
WHERE GroupId=:GroupId AND ChannelId=:ChannelId`, groupSyncableToGroupChannel(groupSyncable))
|
||||
@@ -933,12 +933,12 @@ func (s *SqlGroupStore) DeleteGroupSyncable(groupID string, syncableID string, s
|
||||
|
||||
switch groupSyncable.Type {
|
||||
case model.GroupSyncableTypeTeam:
|
||||
_, err = s.GetMasterX().NamedExec(`UPDATE GroupTeams
|
||||
_, err = s.GetMaster().NamedExec(`UPDATE GroupTeams
|
||||
SET AutoAdd=:AutoAdd, SchemeAdmin=:SchemeAdmin, CreateAt=:CreateAt,
|
||||
DeleteAt=:DeleteAt, UpdateAt=:UpdateAt
|
||||
WHERE GroupId=:GroupId AND TeamId=:TeamId`, groupSyncableToGroupTeam(groupSyncable))
|
||||
case model.GroupSyncableTypeChannel:
|
||||
_, err = s.GetMasterX().NamedExec(`UPDATE GroupChannels
|
||||
_, err = s.GetMaster().NamedExec(`UPDATE GroupChannels
|
||||
SET AutoAdd=:AutoAdd, SchemeAdmin=:SchemeAdmin, CreateAt=:CreateAt,
|
||||
DeleteAt=:DeleteAt, UpdateAt=:UpdateAt
|
||||
WHERE GroupId=:GroupId AND ChannelId=:ChannelId`, groupSyncableToGroupChannel(groupSyncable))
|
||||
@@ -982,7 +982,7 @@ func (s *SqlGroupStore) TeamMembersToAdd(since int64, teamID *string, includeRem
|
||||
|
||||
teamMembers := []*model.UserTeamIDPair{}
|
||||
|
||||
if err := s.GetMasterX().SelectBuilder(&teamMembers, builder); err != nil {
|
||||
if err := s.GetMaster().SelectBuilder(&teamMembers, builder); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find UserTeamIDPairs")
|
||||
}
|
||||
|
||||
@@ -1021,7 +1021,7 @@ func (s *SqlGroupStore) ChannelMembersToAdd(since int64, channelID *string, incl
|
||||
|
||||
channelMembers := []*model.UserChannelIDPair{}
|
||||
|
||||
if err := s.GetMasterX().SelectBuilder(&channelMembers, builder); err != nil {
|
||||
if err := s.GetMaster().SelectBuilder(&channelMembers, builder); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find UserChannelIDPairs")
|
||||
}
|
||||
|
||||
@@ -1086,7 +1086,7 @@ func (s *SqlGroupStore) TeamMembersToRemove(teamID *string) ([]*model.TeamMember
|
||||
|
||||
teamMembers := []*model.TeamMember{}
|
||||
|
||||
if err := s.GetReplicaX().SelectBuilder(&teamMembers, builder); err != nil {
|
||||
if err := s.GetReplica().SelectBuilder(&teamMembers, builder); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find TeamMembers")
|
||||
}
|
||||
|
||||
@@ -1097,7 +1097,7 @@ func (s *SqlGroupStore) CountGroupsByChannel(channelId string, opts model.GroupS
|
||||
builder := s.groupsBySyncableBaseQuery(model.GroupSyncableTypeChannel, selectCountGroups, channelId, opts)
|
||||
|
||||
var count int64
|
||||
if err := s.GetReplicaX().GetBuilder(&count, builder); err != nil {
|
||||
if err := s.GetReplica().GetBuilder(&count, builder); err != nil {
|
||||
return int64(0), errors.Wrapf(err, "failed to count Groups by channel with channelId=%s", channelId)
|
||||
}
|
||||
|
||||
@@ -1209,7 +1209,7 @@ func (s *SqlGroupStore) GetGroupsByChannel(channelId string, opts model.GroupSea
|
||||
}
|
||||
|
||||
groups := groupsWithSchemeAdmin{}
|
||||
if err := s.GetReplicaX().SelectBuilder(&groups, builder); err != nil {
|
||||
if err := s.GetReplica().SelectBuilder(&groups, builder); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Groups with channelId=%s", channelId)
|
||||
}
|
||||
|
||||
@@ -1266,7 +1266,7 @@ func (s *SqlGroupStore) ChannelMembersToRemove(channelID *string) ([]*model.Chan
|
||||
|
||||
channelMembers := []*model.ChannelMember{}
|
||||
|
||||
if err := s.GetReplicaX().SelectBuilder(&channelMembers, builder); err != nil {
|
||||
if err := s.GetReplica().SelectBuilder(&channelMembers, builder); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find ChannelMembers")
|
||||
}
|
||||
|
||||
@@ -1390,7 +1390,7 @@ func (s *SqlGroupStore) CountGroupsByTeam(teamId string, opts model.GroupSearchO
|
||||
builder := s.groupsBySyncableBaseQuery(model.GroupSyncableTypeTeam, selectCountGroups, teamId, opts)
|
||||
|
||||
var count int64
|
||||
if err := s.GetReplicaX().GetBuilder(&count, builder); err != nil {
|
||||
if err := s.GetReplica().GetBuilder(&count, builder); err != nil {
|
||||
return int64(0), errors.Wrapf(err, "failed to count Groups with teamId=%s", teamId)
|
||||
}
|
||||
|
||||
@@ -1406,7 +1406,7 @@ func (s *SqlGroupStore) GetGroupsByTeam(teamId string, opts model.GroupSearchOpt
|
||||
}
|
||||
|
||||
groups := groupsWithSchemeAdmin{}
|
||||
if err := s.GetReplicaX().SelectBuilder(&groups, builder); err != nil {
|
||||
if err := s.GetReplica().SelectBuilder(&groups, builder); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Groups with teamId=%s", teamId)
|
||||
}
|
||||
|
||||
@@ -1423,7 +1423,7 @@ func (s *SqlGroupStore) GetGroupsAssociatedToChannelsByTeam(teamId string, opts
|
||||
|
||||
tgroups := groupsAssociatedToChannelWithSchemeAdmin{}
|
||||
|
||||
if err := s.GetReplicaX().SelectBuilder(&tgroups, builder); err != nil {
|
||||
if err := s.GetReplica().SelectBuilder(&tgroups, builder); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Groups with teamId=%s", teamId)
|
||||
}
|
||||
|
||||
@@ -1627,7 +1627,7 @@ func (s *SqlGroupStore) GetGroups(page, perPage int, opts model.GroupSearchOpts,
|
||||
return nil, errors.Wrap(err, "get_groups_tosql")
|
||||
}
|
||||
|
||||
if err = s.GetReplicaX().Select(&groupsVar, queryString, args...); err != nil {
|
||||
if err = s.GetReplica().Select(&groupsVar, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Groups")
|
||||
}
|
||||
|
||||
@@ -1684,7 +1684,7 @@ func (s *SqlGroupStore) TeamMembersMinusGroupMembers(teamID string, groupIDs []s
|
||||
builder = builder.OrderBy("Users.Username ASC").Limit(uint64(perPage)).Offset(uint64(page * perPage))
|
||||
|
||||
users := []*model.UserWithGroups{}
|
||||
if err := s.GetReplicaX().SelectBuilder(&users, builder); err != nil {
|
||||
if err := s.GetReplica().SelectBuilder(&users, builder); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find UserWithGroups")
|
||||
}
|
||||
|
||||
@@ -1700,7 +1700,7 @@ func (s *SqlGroupStore) CountTeamMembersMinusGroupMembers(teamID string, groupID
|
||||
}
|
||||
|
||||
var count int64
|
||||
if err := s.GetReplicaX().Get(&count, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&count, queryString, args...); err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count TeamMembers minus GroupMembers")
|
||||
}
|
||||
|
||||
@@ -1756,7 +1756,7 @@ func (s *SqlGroupStore) ChannelMembersMinusGroupMembers(channelID string, groupI
|
||||
builder = builder.OrderBy("Users.Username ASC").Limit(uint64(perPage)).Offset(uint64(page * perPage))
|
||||
|
||||
users := []*model.UserWithGroups{}
|
||||
if err := s.GetReplicaX().SelectBuilder(&users, builder); err != nil {
|
||||
if err := s.GetReplica().SelectBuilder(&users, builder); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find UserWithGroups")
|
||||
}
|
||||
|
||||
@@ -1772,7 +1772,7 @@ func (s *SqlGroupStore) CountChannelMembersMinusGroupMembers(channelID string, g
|
||||
}
|
||||
|
||||
var count int64
|
||||
if err := s.GetReplicaX().Get(&count, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&count, queryString, args...); err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count ChannelMembers")
|
||||
}
|
||||
|
||||
@@ -1796,7 +1796,7 @@ func (s *SqlGroupStore) AdminRoleGroupsForSyncableMember(userID, syncableID stri
|
||||
AND Group%[1]ss.DeleteAt = 0
|
||||
AND Group%[1]ss.SchemeAdmin = TRUE`, syncableType)
|
||||
|
||||
err := s.GetReplicaX().Select(&groupIds, query, userID, syncableID)
|
||||
err := s.GetReplica().Select(&groupIds, query, userID, syncableID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Group ids")
|
||||
}
|
||||
@@ -1810,7 +1810,7 @@ func (s *SqlGroupStore) PermittedSyncableAdmins(syncableID string, syncableType
|
||||
Join(fmt.Sprintf("GroupMembers ON GroupMembers.GroupId = Group%ss.GroupId AND Group%[1]ss.SchemeAdmin = TRUE AND GroupMembers.DeleteAt = 0", syncableType.String())).Where(fmt.Sprintf("Group%[1]ss.%[1]sId = ?", syncableType.String()), syncableID)
|
||||
|
||||
var userIDs []string
|
||||
if err := s.GetMasterX().SelectBuilder(&userIDs, builder); err != nil {
|
||||
if err := s.GetMaster().SelectBuilder(&userIDs, builder); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find User ids")
|
||||
}
|
||||
|
||||
@@ -1849,7 +1849,7 @@ func (s *SqlGroupStore) DistinctGroupMemberCountForSource(source model.GroupSour
|
||||
Where(sq.Eq{"UserGroups.Source": source, "GroupMembers.DeleteAt": 0})
|
||||
|
||||
var count int64
|
||||
if err := s.GetReplicaX().GetBuilder(&count, builder); err != nil {
|
||||
if err := s.GetReplica().GetBuilder(&count, builder); err != nil {
|
||||
return 0, errors.Wrapf(err, "failed to select distinct groupmember count for source %q", source)
|
||||
}
|
||||
|
||||
@@ -1877,7 +1877,7 @@ func (s *SqlGroupStore) countTableWithSelectAndWhere(selectStr, tableName string
|
||||
}
|
||||
|
||||
var count int64
|
||||
err = s.GetReplicaX().Get(&count, sql, args...)
|
||||
err = s.GetReplica().Get(&count, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "failed to count from table %s", tableName)
|
||||
}
|
||||
@@ -1891,7 +1891,7 @@ func (s *SqlGroupStore) UpsertMembers(groupID string, userIDs []string) ([]*mode
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err = s.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err = s.GetMaster().Exec(query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to save GroupMember")
|
||||
}
|
||||
|
||||
@@ -1901,7 +1901,7 @@ func (s *SqlGroupStore) UpsertMembers(groupID string, userIDs []string) ([]*mode
|
||||
func (s *SqlGroupStore) buildUpsertMembersQuery(groupID string, userIDs []string) (members []*model.GroupMember, query string, args []any, err error) {
|
||||
var retrievedGroup model.Group
|
||||
// Check Group exists
|
||||
if err = s.GetReplicaX().Get(&retrievedGroup, "SELECT * FROM UserGroups WHERE Id = ?", groupID); err != nil {
|
||||
if err = s.GetReplica().Get(&retrievedGroup, "SELECT * FROM UserGroups WHERE Id = ?", groupID); err != nil {
|
||||
err = errors.Wrapf(err, "failed to get UserGroup with groupId=%s", groupID)
|
||||
return
|
||||
}
|
||||
@@ -1944,7 +1944,7 @@ func (s *SqlGroupStore) DeleteMembers(groupID string, userIDs []string) ([]*mode
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err = s.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err = s.GetMaster().Exec(query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to delete GroupMembers")
|
||||
}
|
||||
return members, err
|
||||
@@ -1964,7 +1964,7 @@ func (s *SqlGroupStore) buildDeleteMembersQuery(groupID string, userIDs []string
|
||||
return
|
||||
}
|
||||
|
||||
err = s.GetReplicaX().Select(&members, membersSelectQuery, membersSelectArgs...)
|
||||
err = s.GetReplica().Select(&members, membersSelectQuery, membersSelectArgs...)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func getOrphanedRecords(ss *SqlStore, cfg relationalCheckConfig) ([]model.Orphan
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = ss.GetMasterX().Select(&records, query, args...)
|
||||
err = ss.GetMaster().Select(&records, query, args...)
|
||||
return records, err
|
||||
}
|
||||
|
||||
|
||||
@@ -415,7 +415,7 @@ func TestCheckParentChildIntegrity(t *testing.T) {
|
||||
func TestCheckChannelsCommandWebhooksIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkChannelsCommandWebhooksIntegrity(store)
|
||||
@@ -442,7 +442,7 @@ func TestCheckChannelsCommandWebhooksIntegrity(t *testing.T) {
|
||||
func TestCheckChannelsChannelMemberHistoryIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkChannelsChannelMemberHistoryIntegrity(store)
|
||||
@@ -473,7 +473,7 @@ func TestCheckChannelsChannelMemberHistoryIntegrity(t *testing.T) {
|
||||
func TestCheckChannelsChannelMembersIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkChannelsChannelMembersIntegrity(store)
|
||||
@@ -501,7 +501,7 @@ func TestCheckChannelsChannelMembersIntegrity(t *testing.T) {
|
||||
func TestCheckChannelsIncomingWebhooksIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkChannelsIncomingWebhooksIntegrity(store)
|
||||
@@ -529,7 +529,7 @@ func TestCheckChannelsIncomingWebhooksIntegrity(t *testing.T) {
|
||||
func TestCheckChannelsOutgoingWebhooksIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkChannelsOutgoingWebhooksIntegrity(store)
|
||||
@@ -559,7 +559,7 @@ func TestCheckChannelsOutgoingWebhooksIntegrity(t *testing.T) {
|
||||
func TestCheckChannelsPostsIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkChannelsPostsIntegrity(store)
|
||||
@@ -586,7 +586,7 @@ func TestCheckChannelsPostsIntegrity(t *testing.T) {
|
||||
func TestCheckCommandsCommandWebhooksIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkCommandsCommandWebhooksIntegrity(store)
|
||||
@@ -614,7 +614,7 @@ func TestCheckCommandsCommandWebhooksIntegrity(t *testing.T) {
|
||||
func TestCheckPostsFileInfoIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkPostsFileInfoIntegrity(store)
|
||||
@@ -642,7 +642,7 @@ func TestCheckPostsFileInfoIntegrity(t *testing.T) {
|
||||
func TestCheckPostsPostsRootIdIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkPostsPostsRootIdIntegrity(store)
|
||||
@@ -675,7 +675,7 @@ func TestCheckPostsPostsRootIdIntegrity(t *testing.T) {
|
||||
func TestCheckPostsReactionsIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkPostsReactionsIntegrity(store)
|
||||
@@ -702,7 +702,7 @@ func TestCheckPostsReactionsIntegrity(t *testing.T) {
|
||||
func TestCheckSchemesChannelsIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkSchemesChannelsIntegrity(store)
|
||||
@@ -733,7 +733,7 @@ func TestCheckSchemesChannelsIntegrity(t *testing.T) {
|
||||
func TestCheckSchemesTeamsIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkSchemesTeamsIntegrity(store)
|
||||
@@ -764,7 +764,7 @@ func TestCheckSchemesTeamsIntegrity(t *testing.T) {
|
||||
func TestCheckSessionsAuditsIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkSessionsAuditsIntegrity(store)
|
||||
@@ -795,7 +795,7 @@ func TestCheckSessionsAuditsIntegrity(t *testing.T) {
|
||||
func TestCheckTeamsChannelsIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkTeamsChannelsIntegrity(store)
|
||||
@@ -871,7 +871,7 @@ func TestCheckTeamsChannelsIntegrity(t *testing.T) {
|
||||
func TestCheckTeamsCommandsIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkTeamsCommandsIntegrity(store)
|
||||
@@ -899,7 +899,7 @@ func TestCheckTeamsCommandsIntegrity(t *testing.T) {
|
||||
func TestCheckTeamsIncomingWebhooksIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkTeamsIncomingWebhooksIntegrity(store)
|
||||
@@ -927,7 +927,7 @@ func TestCheckTeamsIncomingWebhooksIntegrity(t *testing.T) {
|
||||
func TestCheckTeamsOutgoingWebhooksIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkTeamsOutgoingWebhooksIntegrity(store)
|
||||
@@ -955,7 +955,7 @@ func TestCheckTeamsOutgoingWebhooksIntegrity(t *testing.T) {
|
||||
func TestCheckTeamsTeamMembersIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkTeamsTeamMembersIntegrity(store)
|
||||
@@ -983,7 +983,7 @@ func TestCheckTeamsTeamMembersIntegrity(t *testing.T) {
|
||||
func TestCheckUsersAuditsIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersAuditsIntegrity(store)
|
||||
@@ -1013,7 +1013,7 @@ func TestCheckUsersAuditsIntegrity(t *testing.T) {
|
||||
func TestCheckUsersCommandWebhooksIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersCommandWebhooksIntegrity(store)
|
||||
@@ -1041,7 +1041,7 @@ func TestCheckUsersCommandWebhooksIntegrity(t *testing.T) {
|
||||
func TestCheckUsersChannelsIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersChannelsIntegrity(store)
|
||||
@@ -1068,7 +1068,7 @@ func TestCheckUsersChannelsIntegrity(t *testing.T) {
|
||||
func TestCheckUsersChannelMemberHistoryIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersChannelMemberHistoryIntegrity(store)
|
||||
@@ -1098,7 +1098,7 @@ func TestCheckUsersChannelMemberHistoryIntegrity(t *testing.T) {
|
||||
func TestCheckUsersChannelMembersIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersChannelMembersIntegrity(store)
|
||||
@@ -1128,7 +1128,7 @@ func TestCheckUsersChannelMembersIntegrity(t *testing.T) {
|
||||
func TestCheckUsersCommandsIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersCommandsIntegrity(store)
|
||||
@@ -1156,7 +1156,7 @@ func TestCheckUsersCommandsIntegrity(t *testing.T) {
|
||||
func TestCheckUsersCompliancesIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersCompliancesIntegrity(store)
|
||||
@@ -1186,7 +1186,7 @@ func TestCheckUsersCompliancesIntegrity(t *testing.T) {
|
||||
func TestCheckUsersEmojiIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersEmojiIntegrity(store)
|
||||
@@ -1216,7 +1216,7 @@ func TestCheckUsersEmojiIntegrity(t *testing.T) {
|
||||
func TestCheckUsersFileInfoIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersFileInfoIntegrity(store)
|
||||
@@ -1246,7 +1246,7 @@ func TestCheckUsersFileInfoIntegrity(t *testing.T) {
|
||||
func TestCheckUsersIncomingWebhooksIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersIncomingWebhooksIntegrity(store)
|
||||
@@ -1274,7 +1274,7 @@ func TestCheckUsersIncomingWebhooksIntegrity(t *testing.T) {
|
||||
func TestCheckUsersOAuthAccessDataIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersOAuthAccessDataIntegrity(store)
|
||||
@@ -1304,7 +1304,7 @@ func TestCheckUsersOAuthAccessDataIntegrity(t *testing.T) {
|
||||
func TestCheckUsersOAuthAppsIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersOAuthAppsIntegrity(store)
|
||||
@@ -1334,7 +1334,7 @@ func TestCheckUsersOAuthAppsIntegrity(t *testing.T) {
|
||||
func TestCheckUsersOAuthAuthDataIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersOAuthAuthDataIntegrity(store)
|
||||
@@ -1364,7 +1364,7 @@ func TestCheckUsersOAuthAuthDataIntegrity(t *testing.T) {
|
||||
func TestCheckUsersOutgoingWebhooksIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersOutgoingWebhooksIntegrity(store)
|
||||
@@ -1392,7 +1392,7 @@ func TestCheckUsersOutgoingWebhooksIntegrity(t *testing.T) {
|
||||
func TestCheckUsersPostsIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersPostsIntegrity(store)
|
||||
@@ -1419,7 +1419,7 @@ func TestCheckUsersPostsIntegrity(t *testing.T) {
|
||||
func TestCheckUsersPreferencesIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersPreferencesIntegrity(store)
|
||||
@@ -1465,7 +1465,7 @@ func TestCheckUsersPreferencesIntegrity(t *testing.T) {
|
||||
func TestCheckUsersReactionsIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersReactionsIntegrity(store)
|
||||
@@ -1494,7 +1494,7 @@ func TestCheckUsersReactionsIntegrity(t *testing.T) {
|
||||
func TestCheckUsersSessionsIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersSessionsIntegrity(store)
|
||||
@@ -1522,7 +1522,7 @@ func TestCheckUsersSessionsIntegrity(t *testing.T) {
|
||||
func TestCheckUsersStatusIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersStatusIntegrity(store)
|
||||
@@ -1551,7 +1551,7 @@ func TestCheckUsersStatusIntegrity(t *testing.T) {
|
||||
func TestCheckUsersTeamMembersIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersTeamMembersIntegrity(store)
|
||||
@@ -1581,7 +1581,7 @@ func TestCheckUsersTeamMembersIntegrity(t *testing.T) {
|
||||
func TestCheckUsersUserAccessTokensIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkUsersUserAccessTokensIntegrity(store)
|
||||
@@ -1611,7 +1611,7 @@ func TestCheckUsersUserAccessTokensIntegrity(t *testing.T) {
|
||||
func TestCheckThreadsTeamsIntegrity(t *testing.T) {
|
||||
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
store := ss.(*SqlStore)
|
||||
dbmap := store.GetMasterX()
|
||||
dbmap := store.GetMaster()
|
||||
|
||||
t.Run("should generate a report with no records", func(t *testing.T) {
|
||||
result := checkThreadsTeamsIntegrity(store)
|
||||
|
||||
@@ -50,7 +50,7 @@ func (jss SqlJobStore) Save(job *model.Job) (*model.Job, error) {
|
||||
return nil, errors.Wrap(err, "failed to generate sqlquery")
|
||||
}
|
||||
|
||||
if _, err = jss.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
if _, err = jss.GetMaster().Exec(queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to save Job")
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ func (jss SqlJobStore) SaveOnce(job *model.Job) (*model.Job, error) {
|
||||
jsonData = AppendBinaryFlag(jsonData)
|
||||
}
|
||||
|
||||
tx, err := jss.GetMasterX().BeginXWithIsolation(&sql.TxOptions{
|
||||
tx, err := jss.GetMaster().BeginXWithIsolation(&sql.TxOptions{
|
||||
Isolation: sql.LevelSerializable,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -138,7 +138,7 @@ func (jss SqlJobStore) UpdateOptimistically(job *model.Job, currentStatus string
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "job_tosql")
|
||||
}
|
||||
sqlResult, err := jss.GetMasterX().Exec(query, args...)
|
||||
sqlResult, err := jss.GetMaster().Exec(query, args...)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "failed to update Job")
|
||||
}
|
||||
@@ -163,7 +163,7 @@ func (jss SqlJobStore) UpdateStatus(id string, status string) (*model.Job, error
|
||||
LastActivityAt: model.GetMillis(),
|
||||
}
|
||||
|
||||
if _, err := jss.GetMasterX().NamedExec(`UPDATE Jobs
|
||||
if _, err := jss.GetMaster().NamedExec(`UPDATE Jobs
|
||||
SET Status=:Status, LastActivityAt=:LastActivityAt
|
||||
WHERE Id=:Id`, job); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to update Job with id=%s", id)
|
||||
@@ -187,7 +187,7 @@ func (jss SqlJobStore) UpdateStatusOptimistically(id string, currentStatus strin
|
||||
return false, errors.Wrap(err, "job_tosql")
|
||||
}
|
||||
|
||||
sqlResult, err := jss.GetMasterX().Exec(query, args...)
|
||||
sqlResult, err := jss.GetMaster().Exec(query, args...)
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "failed to update Job with id=%s", id)
|
||||
}
|
||||
@@ -212,7 +212,7 @@ func (jss SqlJobStore) Get(c request.CTX, id string) (*model.Job, error) {
|
||||
}
|
||||
|
||||
var status model.Job
|
||||
if err = jss.GetReplicaX().Get(&status, query, args...); err != nil {
|
||||
if err = jss.GetReplica().Get(&status, query, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Job", id)
|
||||
}
|
||||
@@ -235,7 +235,7 @@ func (jss SqlJobStore) GetAllByTypesPage(c request.CTX, jobTypes []string, offse
|
||||
}
|
||||
|
||||
var jobs []*model.Job
|
||||
if err = jss.GetReplicaX().Select(&jobs, query, args...); err != nil {
|
||||
if err = jss.GetReplica().Select(&jobs, query, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Jobs with types")
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ func (jss SqlJobStore) GetAllByType(c request.CTX, jobType string) ([]*model.Job
|
||||
}
|
||||
|
||||
statuses := []*model.Job{}
|
||||
if err = jss.GetReplicaX().Select(&statuses, query, args...); err != nil {
|
||||
if err = jss.GetReplica().Select(&statuses, query, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Jobs with type=%s", jobType)
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ func (jss SqlJobStore) GetAllByTypeAndStatus(c request.CTX, jobType string, stat
|
||||
}
|
||||
|
||||
jobs := []*model.Job{}
|
||||
if err = jss.GetReplicaX().Select(&jobs, query, args...); err != nil {
|
||||
if err = jss.GetReplica().Select(&jobs, query, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Jobs with type=%s", jobType)
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ func (jss SqlJobStore) GetAllByTypePage(c request.CTX, jobType string, offset in
|
||||
}
|
||||
|
||||
statuses := []*model.Job{}
|
||||
if err = jss.GetReplicaX().Select(&statuses, query, args...); err != nil {
|
||||
if err = jss.GetReplica().Select(&statuses, query, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Jobs with type=%s", jobType)
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ func (jss SqlJobStore) GetAllByStatus(c request.CTX, status string) ([]*model.Jo
|
||||
return nil, errors.Wrap(err, "job_tosql")
|
||||
}
|
||||
|
||||
if err = jss.GetReplicaX().Select(&statuses, query, args...); err != nil {
|
||||
if err = jss.GetReplica().Select(&statuses, query, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Jobs with status=%s", status)
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ func (jss SqlJobStore) GetAllByTypeAndStatusPage(c request.CTX, jobType []string
|
||||
}
|
||||
|
||||
jobs := []*model.Job{}
|
||||
if err = jss.GetReplicaX().Select(&jobs, query, args...); err != nil {
|
||||
if err = jss.GetReplica().Select(&jobs, query, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Jobs with type=%s and status=%s", strings.Join(jobType, ","), status)
|
||||
}
|
||||
|
||||
@@ -352,7 +352,7 @@ func (jss SqlJobStore) GetNewestJobByStatusesAndType(status []string, jobType st
|
||||
}
|
||||
|
||||
var job model.Job
|
||||
if err = jss.GetReplicaX().Get(&job, query, args...); err != nil {
|
||||
if err = jss.GetReplica().Get(&job, query, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Job", fmt.Sprintf("<status, type>=<%s, %s>", strings.Join(status, ","), jobType))
|
||||
}
|
||||
@@ -371,7 +371,7 @@ func (jss SqlJobStore) GetCountByStatusAndType(status string, jobType string) (i
|
||||
}
|
||||
|
||||
var count int64
|
||||
err = jss.GetReplicaX().Get(&count, query, args...)
|
||||
err = jss.GetReplica().Get(&count, query, args...)
|
||||
if err != nil {
|
||||
return int64(0), errors.Wrapf(err, "failed to count Jobs with status=%s and type=%s", status, jobType)
|
||||
}
|
||||
@@ -386,7 +386,7 @@ func (jss SqlJobStore) Delete(id string) (string, error) {
|
||||
return "", errors.Wrap(err, "job_tosql")
|
||||
}
|
||||
|
||||
if _, err = jss.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err = jss.GetMaster().Exec(query, args...); err != nil {
|
||||
return "", errors.Wrapf(err, "failed to delete Job with id=%s", id)
|
||||
}
|
||||
return id, nil
|
||||
@@ -403,7 +403,7 @@ func (jss SqlJobStore) Cleanup(expiryTime int64, batchSize int) error {
|
||||
var rowsAffected int64 = 1
|
||||
|
||||
for rowsAffected > 0 {
|
||||
sqlResult, err := jss.GetMasterX().Exec(query,
|
||||
sqlResult, err := jss.GetMaster().Exec(query,
|
||||
expiryTime, model.JobStatusInProgress, model.JobStatusPending, batchSize)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable to delete jobs")
|
||||
|
||||
@@ -47,7 +47,7 @@ func (ls SqlLicenseStore) Save(license *model.LicenseRecord) error {
|
||||
return errors.Wrap(err, "license_tosql")
|
||||
}
|
||||
|
||||
if _, err := ls.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
if _, err := ls.GetMaster().Exec(queryString, args...); err != nil {
|
||||
return errors.Wrapf(err, "failed to insert License with licenseId=%s", license.Id)
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ func (ls SqlLicenseStore) GetAll() ([]*model.LicenseRecord, error) {
|
||||
}
|
||||
|
||||
licenses := []*model.LicenseRecord{}
|
||||
if err := ls.GetReplicaX().Select(&licenses, queryString); err != nil {
|
||||
if err := ls.GetReplica().Select(&licenses, queryString); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to fetch licenses")
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ func (s SqlLinkMetadataStore) Save(metadata *model.LinkMetadata) (*model.LinkMet
|
||||
return nil, errors.Wrap(err, "metadata_tosql")
|
||||
}
|
||||
|
||||
_, err = s.GetMasterX().Exec(q, args...)
|
||||
_, err = s.GetMaster().Exec(q, args...)
|
||||
if err != nil && !IsUniqueConstraintError(err, []string{"PRIMARY", "linkmetadata_pkey"}) {
|
||||
return nil, errors.Wrap(err, "could not save link metadata")
|
||||
}
|
||||
@@ -70,7 +70,7 @@ func (s SqlLinkMetadataStore) Get(url string, timestamp int64) (*model.LinkMetad
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not create query with querybuilder")
|
||||
}
|
||||
err = s.GetReplicaX().Get(&metadata, query, args...)
|
||||
err = s.GetReplica().Get(&metadata, query, args...)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("LinkMetadata", "url="+url)
|
||||
|
||||
@@ -141,7 +141,7 @@ func (ss *SqlStore) initMorph(dryRun bool) (*morph.Morph, error) {
|
||||
}
|
||||
defer db.Close()
|
||||
case model.DatabaseDriverPostgres:
|
||||
driver, err = ps.WithInstance(ss.GetMasterX().DB.DB)
|
||||
driver, err = ps.WithInstance(ss.GetMaster().DB.DB)
|
||||
default:
|
||||
err = fmt.Errorf("unsupported database type %s for migration", ss.DriverName())
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func newSqlNotifyAdminStore(sqlStore *SqlStore) store.NotifyAdminStore {
|
||||
|
||||
func (s SqlNotifyAdminStore) insert(data *model.NotifyAdminData) (sql.Result, error) {
|
||||
query := `INSERT INTO NotifyAdmin (UserId, CreateAt, RequiredPlan, RequiredFeature, Trial) VALUES (:UserId, :CreateAt, :RequiredPlan, :RequiredFeature, :Trial)`
|
||||
return s.GetMasterX().NamedExec(query, data)
|
||||
return s.GetMaster().NamedExec(query, data)
|
||||
}
|
||||
|
||||
func (s SqlNotifyAdminStore) Save(data *model.NotifyAdminData) (*model.NotifyAdminData, error) {
|
||||
@@ -54,7 +54,7 @@ func (s SqlNotifyAdminStore) GetDataByUserIdAndFeature(userId string, feature mo
|
||||
return nil, errors.Wrap(err, "could not build sql query to get all notification data by user id and required feature")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Select(&data, query, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&data, query, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("NotifyAdmin", fmt.Sprintf("user id: %s and required feature: %s", userId, feature))
|
||||
}
|
||||
@@ -75,21 +75,21 @@ func (s SqlNotifyAdminStore) Get(trial bool) ([]*model.NotifyAdminData, error) {
|
||||
return nil, errors.Wrap(err, "could not build sql query to get all notifcation data")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Select(&data, query, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&data, query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "notifcation data")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (s SqlNotifyAdminStore) DeleteBefore(trial bool, now int64) error {
|
||||
if _, err := s.GetMasterX().Exec("DELETE FROM NotifyAdmin WHERE Trial = ? AND CreateAt < ? AND SentAt IS NULL", trial, now); err != nil {
|
||||
if _, err := s.GetMaster().Exec("DELETE FROM NotifyAdmin WHERE Trial = ? AND CreateAt < ? AND SentAt IS NULL", trial, now); err != nil {
|
||||
return errors.Wrapf(err, "failed to remove all notification data with trial=%t", trial)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlNotifyAdminStore) Update(userId string, requiredPlan string, requiredFeature model.MattermostFeature, now int64) error {
|
||||
if _, err := s.GetMasterX().Exec("UPDATE NotifyAdmin SET SentAt = ? WHERE UserId = ? AND RequiredPlan = ? AND RequiredFeature = ?", now, userId, requiredPlan, requiredFeature); err != nil {
|
||||
if _, err := s.GetMaster().Exec("UPDATE NotifyAdmin SET SentAt = ? WHERE UserId = ? AND RequiredPlan = ? AND RequiredFeature = ?", now, userId, requiredPlan, requiredFeature); err != nil {
|
||||
return errors.Wrapf(err, "failed to update SentAt for userId=%s and requiredPlan=%s", userId, requiredPlan)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -31,7 +31,7 @@ func (as SqlOAuthStore) SaveApp(app *model.OAuthApp) (*model.OAuthApp, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := as.GetMasterX().NamedExec(`INSERT INTO OAuthApps
|
||||
if _, err := as.GetMaster().NamedExec(`INSERT INTO OAuthApps
|
||||
(Id, CreatorId, CreateAt, UpdateAt, ClientSecret, Name, Description, IconURL, CallbackUrls, Homepage, IsTrusted, MattermostAppID)
|
||||
VALUES
|
||||
(:Id, :CreatorId, :CreateAt, :UpdateAt, :ClientSecret, :Name, :Description, :IconURL, :CallbackUrls, :Homepage, :IsTrusted, :MattermostAppID)`, app); err != nil {
|
||||
@@ -48,7 +48,7 @@ func (as SqlOAuthStore) UpdateApp(app *model.OAuthApp) (*model.OAuthApp, error)
|
||||
}
|
||||
|
||||
var oldApp model.OAuthApp
|
||||
err := as.GetMasterX().Get(&oldApp, `SELECT * FROM OAuthApps
|
||||
err := as.GetMaster().Get(&oldApp, `SELECT * FROM OAuthApps
|
||||
WHERE id=?`, app.Id)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get OAuthApp with id=%s", app.Id)
|
||||
@@ -60,7 +60,7 @@ func (as SqlOAuthStore) UpdateApp(app *model.OAuthApp) (*model.OAuthApp, error)
|
||||
app.CreateAt = oldApp.CreateAt
|
||||
app.CreatorId = oldApp.CreatorId
|
||||
|
||||
res, err := as.GetMasterX().NamedExec(`UPDATE OAuthApps
|
||||
res, err := as.GetMaster().NamedExec(`UPDATE OAuthApps
|
||||
SET UpdateAt=:UpdateAt, ClientSecret=:ClientSecret, Name=:Name,
|
||||
Description=:Description, IconURL=:IconURL, CallbackUrls=:CallbackUrls,
|
||||
Homepage=:Homepage, IsTrusted=:IsTrusted, MattermostAppID=:MattermostAppID
|
||||
@@ -80,7 +80,7 @@ func (as SqlOAuthStore) UpdateApp(app *model.OAuthApp) (*model.OAuthApp, error)
|
||||
|
||||
func (as SqlOAuthStore) GetApp(id string) (*model.OAuthApp, error) {
|
||||
var app model.OAuthApp
|
||||
if err := as.GetReplicaX().Get(&app, `SELECT * FROM OAuthApps WHERE Id=?`, id); err != nil {
|
||||
if err := as.GetReplica().Get(&app, `SELECT * FROM OAuthApps WHERE Id=?`, id); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("OAuthApp", id)
|
||||
}
|
||||
@@ -95,7 +95,7 @@ func (as SqlOAuthStore) GetApp(id string) (*model.OAuthApp, error) {
|
||||
func (as SqlOAuthStore) GetAppByUser(userId string, offset, limit int) ([]*model.OAuthApp, error) {
|
||||
apps := []*model.OAuthApp{}
|
||||
|
||||
if err := as.GetReplicaX().Select(&apps, "SELECT * FROM OAuthApps WHERE CreatorId = ? LIMIT ? OFFSET ?", userId, limit, offset); err != nil {
|
||||
if err := as.GetReplica().Select(&apps, "SELECT * FROM OAuthApps WHERE CreatorId = ? LIMIT ? OFFSET ?", userId, limit, offset); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find OAuthApps with userId=%s", userId)
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ func (as SqlOAuthStore) GetAppByUser(userId string, offset, limit int) ([]*model
|
||||
func (as SqlOAuthStore) GetApps(offset, limit int) ([]*model.OAuthApp, error) {
|
||||
apps := []*model.OAuthApp{}
|
||||
|
||||
if err := as.GetReplicaX().Select(&apps, "SELECT * FROM OAuthApps LIMIT ? OFFSET ?", limit, offset); err != nil {
|
||||
if err := as.GetReplica().Select(&apps, "SELECT * FROM OAuthApps LIMIT ? OFFSET ?", limit, offset); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find OAuthApps")
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ func (as SqlOAuthStore) GetApps(offset, limit int) ([]*model.OAuthApp, error) {
|
||||
func (as SqlOAuthStore) GetAuthorizedApps(userId string, offset, limit int) ([]*model.OAuthApp, error) {
|
||||
apps := []*model.OAuthApp{}
|
||||
|
||||
if err := as.GetReplicaX().Select(&apps,
|
||||
if err := as.GetReplica().Select(&apps,
|
||||
`SELECT o.* FROM OAuthApps AS o INNER JOIN
|
||||
Preferences AS p ON p.Name=o.Id AND p.UserId=? LIMIT ? OFFSET ?`, userId, limit, offset); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find OAuthApps with userId=%s", userId)
|
||||
@@ -126,7 +126,7 @@ func (as SqlOAuthStore) GetAuthorizedApps(userId string, offset, limit int) ([]*
|
||||
|
||||
func (as SqlOAuthStore) DeleteApp(id string) (err error) {
|
||||
// wrap in a transaction so that if one fails, everything fails
|
||||
transaction, err := as.GetMasterX().Beginx()
|
||||
transaction, err := as.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -148,7 +148,7 @@ func (as SqlOAuthStore) SaveAccessData(accessData *model.AccessData) (*model.Acc
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := as.GetMasterX().NamedExec(`INSERT INTO OAuthAccessData
|
||||
if _, err := as.GetMaster().NamedExec(`INSERT INTO OAuthAccessData
|
||||
(ClientId, UserId, Token, RefreshToken, RedirectUri, ExpiresAt, Scope)
|
||||
VALUES
|
||||
(:ClientId, :UserId, :Token, :RefreshToken, :RedirectUri, :ExpiresAt, :Scope)`, accessData); err != nil {
|
||||
@@ -160,7 +160,7 @@ func (as SqlOAuthStore) SaveAccessData(accessData *model.AccessData) (*model.Acc
|
||||
func (as SqlOAuthStore) GetAccessData(token string) (*model.AccessData, error) {
|
||||
accessData := model.AccessData{}
|
||||
|
||||
if err := as.GetReplicaX().Get(&accessData, "SELECT * FROM OAuthAccessData WHERE Token = ?", token); err != nil {
|
||||
if err := as.GetReplica().Get(&accessData, "SELECT * FROM OAuthAccessData WHERE Token = ?", token); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get OAuthAccessData with token=%s", token)
|
||||
}
|
||||
return &accessData, nil
|
||||
@@ -169,7 +169,7 @@ func (as SqlOAuthStore) GetAccessData(token string) (*model.AccessData, error) {
|
||||
func (as SqlOAuthStore) GetAccessDataByUserForApp(userID, clientID string) ([]*model.AccessData, error) {
|
||||
accessData := []*model.AccessData{}
|
||||
|
||||
if err := as.GetReplicaX().Select(&accessData,
|
||||
if err := as.GetReplica().Select(&accessData,
|
||||
"SELECT * FROM OAuthAccessData WHERE UserId = ? AND ClientId = ?", userID, clientID); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to delete OAuthAccessData with userId=%s and clientId=%s", userID, clientID)
|
||||
}
|
||||
@@ -179,7 +179,7 @@ func (as SqlOAuthStore) GetAccessDataByUserForApp(userID, clientID string) ([]*m
|
||||
func (as SqlOAuthStore) GetAccessDataByRefreshToken(token string) (*model.AccessData, error) {
|
||||
accessData := model.AccessData{}
|
||||
|
||||
if err := as.GetReplicaX().Get(&accessData, "SELECT * FROM OAuthAccessData WHERE RefreshToken = ?", token); err != nil {
|
||||
if err := as.GetReplica().Get(&accessData, "SELECT * FROM OAuthAccessData WHERE RefreshToken = ?", token); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find OAuthAccessData with refreshToken=%s", token)
|
||||
}
|
||||
return &accessData, nil
|
||||
@@ -188,7 +188,7 @@ func (as SqlOAuthStore) GetAccessDataByRefreshToken(token string) (*model.Access
|
||||
func (as SqlOAuthStore) GetPreviousAccessData(userID, clientID string) (*model.AccessData, error) {
|
||||
accessData := model.AccessData{}
|
||||
|
||||
if err := as.GetReplicaX().Get(&accessData, "SELECT * FROM OAuthAccessData WHERE ClientId = ? AND UserId = ?", clientID, userID); err != nil {
|
||||
if err := as.GetReplica().Get(&accessData, "SELECT * FROM OAuthAccessData WHERE ClientId = ? AND UserId = ?", clientID, userID); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -203,21 +203,21 @@ func (as SqlOAuthStore) UpdateAccessData(accessData *model.AccessData) (*model.A
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := as.GetMasterX().NamedExec("UPDATE OAuthAccessData SET Token = :Token, ExpiresAt = :ExpiresAt, RefreshToken = :RefreshToken WHERE ClientId = :ClientId AND UserID = :UserId", accessData); err != nil {
|
||||
if _, err := as.GetMaster().NamedExec("UPDATE OAuthAccessData SET Token = :Token, ExpiresAt = :ExpiresAt, RefreshToken = :RefreshToken WHERE ClientId = :ClientId AND UserID = :UserId", accessData); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to update OAuthAccessData with userId=%s and clientId=%s", accessData.UserId, accessData.ClientId)
|
||||
}
|
||||
return accessData, nil
|
||||
}
|
||||
|
||||
func (as SqlOAuthStore) RemoveAccessData(token string) error {
|
||||
if _, err := as.GetMasterX().Exec("DELETE FROM OAuthAccessData WHERE Token = ?", token); err != nil {
|
||||
if _, err := as.GetMaster().Exec("DELETE FROM OAuthAccessData WHERE Token = ?", token); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete OAuthAccessData with token=%s", token)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (as SqlOAuthStore) RemoveAllAccessData() error {
|
||||
if _, err := as.GetMasterX().Exec("DELETE FROM OAuthAccessData"); err != nil {
|
||||
if _, err := as.GetMaster().Exec("DELETE FROM OAuthAccessData"); err != nil {
|
||||
return errors.Wrap(err, "failed to delete OAuthAccessData")
|
||||
}
|
||||
return nil
|
||||
@@ -229,7 +229,7 @@ func (as SqlOAuthStore) SaveAuthData(authData *model.AuthData) (*model.AuthData,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := as.GetMasterX().NamedExec(`INSERT INTO OAuthAuthData
|
||||
if _, err := as.GetMaster().NamedExec(`INSERT INTO OAuthAuthData
|
||||
(ClientId, UserId, Code, ExpiresIn, CreateAt, RedirectUri, State, Scope)
|
||||
VALUES
|
||||
(:ClientId, :UserId, :Code, :ExpiresIn, :CreateAt, :RedirectUri, :State, :Scope)`, authData); err != nil {
|
||||
@@ -240,7 +240,7 @@ func (as SqlOAuthStore) SaveAuthData(authData *model.AuthData) (*model.AuthData,
|
||||
|
||||
func (as SqlOAuthStore) GetAuthData(code string) (*model.AuthData, error) {
|
||||
var authData model.AuthData
|
||||
err := as.GetReplicaX().Get(&authData, `SELECT * FROM OAuthAuthData WHERE Code=?`, code)
|
||||
err := as.GetReplica().Get(&authData, `SELECT * FROM OAuthAuthData WHERE Code=?`, code)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("AuthData", fmt.Sprintf("code=%s", code))
|
||||
@@ -254,7 +254,7 @@ func (as SqlOAuthStore) GetAuthData(code string) (*model.AuthData, error) {
|
||||
}
|
||||
|
||||
func (as SqlOAuthStore) RemoveAuthData(code string) error {
|
||||
_, err := as.GetMasterX().Exec("DELETE FROM OAuthAuthData WHERE Code = ?", code)
|
||||
_, err := as.GetMaster().Exec("DELETE FROM OAuthAuthData WHERE Code = ?", code)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete AuthData with code=%s", code)
|
||||
}
|
||||
@@ -262,7 +262,7 @@ func (as SqlOAuthStore) RemoveAuthData(code string) error {
|
||||
}
|
||||
|
||||
func (as SqlOAuthStore) RemoveAuthDataByClientId(clientId string, userId string) error {
|
||||
_, err := as.GetMasterX().Exec("DELETE FROM OAuthAuthData WHERE ClientId = ? and UserId = ?", clientId, userId)
|
||||
_, err := as.GetMaster().Exec("DELETE FROM OAuthAuthData WHERE ClientId = ? and UserId = ?", clientId, userId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete AuthData with clientId=%s and userId=%s", clientId, userId)
|
||||
}
|
||||
@@ -270,7 +270,7 @@ func (as SqlOAuthStore) RemoveAuthDataByClientId(clientId string, userId string)
|
||||
}
|
||||
|
||||
func (as SqlOAuthStore) RemoveAuthDataByUserId(userId string) error {
|
||||
_, err := as.GetMasterX().Exec("DELETE FROM OAuthAuthData WHERE UserId = ?", userId)
|
||||
_, err := as.GetMaster().Exec("DELETE FROM OAuthAuthData WHERE UserId = ?", userId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete AuthData with userId=%s", userId)
|
||||
}
|
||||
@@ -278,7 +278,7 @@ func (as SqlOAuthStore) RemoveAuthDataByUserId(userId string) error {
|
||||
}
|
||||
|
||||
func (as SqlOAuthStore) PermanentDeleteAuthDataByUser(userId string) error {
|
||||
_, err := as.GetMasterX().Exec("DELETE FROM OAuthAccessData WHERE UserId = ?", userId)
|
||||
_, err := as.GetMaster().Exec("DELETE FROM OAuthAccessData WHERE UserId = ?", userId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete OAuthAccessData with userId=%s", userId)
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func (s *SqlOutgoingOAuthConnectionStore) SaveConnection(c request.CTX, conn *mo
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().NamedExec(`INSERT INTO OutgoingOAuthConnections
|
||||
if _, err := s.GetMaster().NamedExec(`INSERT INTO OutgoingOAuthConnections
|
||||
(Id, Name, ClientId, ClientSecret, CreateAt, UpdateAt, CreatorId, OAuthTokenURL, GrantType, Audiences)
|
||||
VALUES
|
||||
(:Id, :Name, :ClientId, :ClientSecret, :CreateAt, :UpdateAt, :CreatorId, :OAuthTokenURL, :GrantType, :Audiences)`, conn); err != nil {
|
||||
@@ -78,7 +78,7 @@ func (s *SqlOutgoingOAuthConnectionStore) UpdateConnection(c request.CTX, conn *
|
||||
query = query.Set("CredentialsPassword", conn.CredentialsPassword)
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().ExecBuilder(query); err != nil {
|
||||
if _, err := s.GetMaster().ExecBuilder(query); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to update OutgoingOAuthConnection")
|
||||
}
|
||||
return conn, nil
|
||||
@@ -86,7 +86,7 @@ func (s *SqlOutgoingOAuthConnectionStore) UpdateConnection(c request.CTX, conn *
|
||||
|
||||
func (s *SqlOutgoingOAuthConnectionStore) GetConnection(c request.CTX, id string) (*model.OutgoingOAuthConnection, error) {
|
||||
conn := &model.OutgoingOAuthConnection{}
|
||||
if err := s.GetReplicaX().Get(conn, `SELECT * FROM OutgoingOAuthConnections WHERE Id=?`, id); err != nil {
|
||||
if err := s.GetReplica().Get(conn, `SELECT * FROM OutgoingOAuthConnections WHERE Id=?`, id); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("OutgoingOAuthConnection", id)
|
||||
}
|
||||
@@ -113,7 +113,7 @@ func (s *SqlOutgoingOAuthConnectionStore) GetConnections(c request.CTX, filters
|
||||
query = query.Where(sq.Like{"Audiences": fmt.Sprint("%", filters.Audience, "%")})
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().SelectBuilder(&conns, query); err != nil {
|
||||
if err := s.GetReplica().SelectBuilder(&conns, query); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get OutgoingOAuthConnections")
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ func (s *SqlOutgoingOAuthConnectionStore) GetConnections(c request.CTX, filters
|
||||
}
|
||||
|
||||
func (s *SqlOutgoingOAuthConnectionStore) DeleteConnection(c request.CTX, id string) error {
|
||||
if _, err := s.GetMasterX().Exec(`DELETE FROM OutgoingOAuthConnections WHERE Id=?`, id); err != nil {
|
||||
if _, err := s.GetMaster().Exec(`DELETE FROM OutgoingOAuthConnections WHERE Id=?`, id); err != nil {
|
||||
return errors.Wrap(err, "failed to delete OutgoingOAuthConnection")
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -57,7 +57,7 @@ func (ps SqlPluginStore) SaveOrUpdate(kv *model.PluginKeyValue) (*model.PluginKe
|
||||
return nil, errors.Wrap(err, "plugin_tosql")
|
||||
}
|
||||
|
||||
if _, err := ps.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
if _, err := ps.GetMaster().Exec(queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to upsert PluginKeyValue")
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ func (ps SqlPluginStore) CompareAndSet(kv *model.PluginKeyValue, oldValue []byte
|
||||
return false, errors.Wrap(err, "plugin_tosql")
|
||||
}
|
||||
|
||||
if _, err = ps.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
if _, err = ps.GetMaster().Exec(queryString, args...); err != nil {
|
||||
return false, errors.Wrap(err, "failed to delete PluginKeyValue")
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ func (ps SqlPluginStore) CompareAndSet(kv *model.PluginKeyValue, oldValue []byte
|
||||
return false, errors.Wrap(err, "plugin_tosql")
|
||||
}
|
||||
|
||||
if _, err := ps.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
if _, err := ps.GetMaster().Exec(queryString, args...); err != nil {
|
||||
// If the error is from unique constraints violation, it's the result of a
|
||||
// race condition, return false and no error. Otherwise we have a real error and
|
||||
// need to return it.
|
||||
@@ -131,7 +131,7 @@ func (ps SqlPluginStore) CompareAndSet(kv *model.PluginKeyValue, oldValue []byte
|
||||
return false, errors.Wrap(err, "plugin_tosql")
|
||||
}
|
||||
|
||||
updateResult, err := ps.GetMasterX().Exec(queryString, args...)
|
||||
updateResult, err := ps.GetMaster().Exec(queryString, args...)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "failed to update PluginKeyValue")
|
||||
}
|
||||
@@ -163,7 +163,7 @@ func (ps SqlPluginStore) CompareAndSet(kv *model.PluginKeyValue, oldValue []byte
|
||||
}
|
||||
|
||||
var count int64
|
||||
err = ps.GetReplicaX().Get(&count, queryString, args...)
|
||||
err = ps.GetReplica().Get(&count, queryString, args...)
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "failed to count PluginKeyValue with pluginId=%s and key=%s", kv.PluginId, kv.Key)
|
||||
}
|
||||
@@ -210,7 +210,7 @@ func (ps SqlPluginStore) CompareAndDelete(kv *model.PluginKeyValue, oldValue []b
|
||||
return false, errors.Wrap(err, "plugin_tosql")
|
||||
}
|
||||
|
||||
deleteResult, err := ps.GetMasterX().Exec(queryString, args...)
|
||||
deleteResult, err := ps.GetMaster().Exec(queryString, args...)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "failed to delete PluginKeyValue")
|
||||
}
|
||||
@@ -258,7 +258,7 @@ func (ps SqlPluginStore) Get(pluginId, key string) (*model.PluginKeyValue, error
|
||||
return nil, errors.Wrap(err, "plugin_tosql")
|
||||
}
|
||||
|
||||
row := ps.GetReplicaX().QueryRowx(queryString, args...)
|
||||
row := ps.GetReplica().QueryRowx(queryString, args...)
|
||||
var kv model.PluginKeyValue
|
||||
if err := row.Scan(&kv.PluginId, &kv.Key, &kv.Value, &kv.ExpireAt); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
@@ -281,7 +281,7 @@ func (ps SqlPluginStore) Delete(pluginId, key string) error {
|
||||
return errors.Wrap(err, "plugin_tosql")
|
||||
}
|
||||
|
||||
if _, err := ps.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
if _, err := ps.GetMaster().Exec(queryString, args...); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete PluginKeyValue with pluginId=%s and key=%s", pluginId, key)
|
||||
}
|
||||
return nil
|
||||
@@ -297,7 +297,7 @@ func (ps SqlPluginStore) DeleteAllForPlugin(pluginId string) error {
|
||||
return errors.Wrap(err, "plugin_tosql")
|
||||
}
|
||||
|
||||
if _, err := ps.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
if _, err := ps.GetMaster().Exec(queryString, args...); err != nil {
|
||||
return errors.Wrapf(err, "failed to get all PluginKeyValues with pluginId=%s ", pluginId)
|
||||
}
|
||||
return nil
|
||||
@@ -315,7 +315,7 @@ func (ps SqlPluginStore) DeleteAllExpired() error {
|
||||
return errors.Wrap(err, "plugin_tosql")
|
||||
}
|
||||
|
||||
if _, err := ps.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
if _, err := ps.GetMaster().Exec(queryString, args...); err != nil {
|
||||
return errors.Wrap(err, "failed to delete all expired PluginKeyValues")
|
||||
}
|
||||
return nil
|
||||
@@ -348,7 +348,7 @@ func (ps SqlPluginStore) List(pluginId string, offset int, limit int) ([]string,
|
||||
}
|
||||
|
||||
keys := []string{}
|
||||
err = ps.GetReplicaX().Select(&keys, queryString, args...)
|
||||
err = ps.GetReplica().Select(&keys, queryString, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get PluginKeyValues with pluginId=%s", pluginId)
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func (s *SqlPostAcknowledgementStore) Get(postID, userID string) (*model.PostAck
|
||||
})
|
||||
|
||||
var acknowledgement model.PostAcknowledgement
|
||||
err := s.GetReplicaX().GetBuilder(&acknowledgement, query)
|
||||
err := s.GetReplica().GetBuilder(&acknowledgement, query)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("PostAcknowledgement", postID)
|
||||
@@ -59,7 +59,7 @@ func (s *SqlPostAcknowledgementStore) Save(postID, userID string, acknowledgedAt
|
||||
return nil, err
|
||||
}
|
||||
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -95,7 +95,7 @@ func (s *SqlPostAcknowledgementStore) Save(postID, userID string, acknowledgedAt
|
||||
}
|
||||
|
||||
func (s *SqlPostAcknowledgementStore) Delete(acknowledgement *model.PostAcknowledgement) error {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -138,7 +138,7 @@ func (s *SqlPostAcknowledgementStore) GetForPost(postID string) ([]*model.PostAc
|
||||
sq.Eq{"PostId": postID},
|
||||
})
|
||||
|
||||
err := s.GetReplicaX().SelectBuilder(&acknowledgements, query)
|
||||
err := s.GetReplica().SelectBuilder(&acknowledgements, query)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get PostAcknowledgements for postID=%s", postID)
|
||||
}
|
||||
@@ -165,7 +165,7 @@ func (s *SqlPostAcknowledgementStore) GetForPosts(postIds []string) ([]*model.Po
|
||||
})
|
||||
|
||||
var acknowledgementsBatch []*model.PostAcknowledgement
|
||||
err := s.GetReplicaX().SelectBuilder(&acknowledgementsBatch, query)
|
||||
err := s.GetReplica().SelectBuilder(&acknowledgementsBatch, query)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get PostAcknowledgements for post list")
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func (s *SqlPostPersistentNotificationStore) GetSingle(postID string) (*model.Po
|
||||
})
|
||||
|
||||
post := &model.PostPersistentNotifications{}
|
||||
err := s.GetReplicaX().GetBuilder(post, builder)
|
||||
err := s.GetReplica().GetBuilder(post, builder)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Persistent Notification Post", postID)
|
||||
@@ -62,7 +62,7 @@ func (s *SqlPostPersistentNotificationStore) Get(params model.GetPersistentNotif
|
||||
var posts []*model.PostPersistentNotifications
|
||||
// Replica may not have the latest changes(done by UpdateLastActivity func)
|
||||
// by the time this Get func is called again in the loop.
|
||||
err := s.GetMasterX().SelectBuilder(&posts, builder)
|
||||
err := s.GetMaster().SelectBuilder(&posts, builder)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get notifications")
|
||||
}
|
||||
@@ -77,7 +77,7 @@ func (s *SqlPostPersistentNotificationStore) UpdateLastActivity(postIds []string
|
||||
Set("SentCount", sq.Expr("SentCount+1")).
|
||||
Where(sq.Eq{"PostId": postIds})
|
||||
|
||||
_, err := s.GetMasterX().ExecBuilder(builder)
|
||||
_, err := s.GetMaster().ExecBuilder(builder)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to update last activity for posts %s", postIds)
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func (s *SqlPostPersistentNotificationStore) Delete(postIds []string) error {
|
||||
Set("DeleteAt", model.GetMillis()).
|
||||
Where(sq.Eq{"PostId": postIds})
|
||||
|
||||
_, err := s.GetMasterX().ExecBuilder(builder)
|
||||
_, err := s.GetMaster().ExecBuilder(builder)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete notifications for posts %s", postIds)
|
||||
}
|
||||
@@ -113,7 +113,7 @@ func (s *SqlPostPersistentNotificationStore) DeleteExpired(maxSentCount int16) e
|
||||
sq.GtOrEq{"SentCount": maxSentCount},
|
||||
})
|
||||
|
||||
_, err := s.GetMasterX().ExecBuilder(builder)
|
||||
_, err := s.GetMaster().ExecBuilder(builder)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to delete notifications")
|
||||
}
|
||||
@@ -148,7 +148,7 @@ func (s *SqlPostPersistentNotificationStore) DeleteByChannel(channelIds []string
|
||||
sq.Eq{"Posts.ChannelId": channelIds},
|
||||
})
|
||||
|
||||
_, err := s.GetMasterX().ExecBuilder(builder)
|
||||
_, err := s.GetMaster().ExecBuilder(builder)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete notifications for channels %s", channelIds)
|
||||
}
|
||||
@@ -184,7 +184,7 @@ func (s *SqlPostPersistentNotificationStore) DeleteByTeam(teamIds []string) erro
|
||||
sq.Eq{"Channels.TeamId": teamIds},
|
||||
})
|
||||
|
||||
_, err := s.GetMasterX().ExecBuilder(builder)
|
||||
_, err := s.GetMaster().ExecBuilder(builder)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete notifications for teams %s", teamIds)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ func (s *SqlPostPriorityStore) GetForPost(postId string) (*model.PostPriority, e
|
||||
Where(sq.Eq{"PostId": postId})
|
||||
|
||||
var postPriority model.PostPriority
|
||||
err := s.GetReplicaX().GetBuilder(&postPriority, query)
|
||||
err := s.GetReplica().GetBuilder(&postPriority, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -51,7 +51,7 @@ func (s *SqlPostPriorityStore) GetForPosts(postIds []string) ([]*model.PostPrior
|
||||
Where(sq.Eq{"PostId": postIds[i:j]})
|
||||
|
||||
var priorityBatch []*model.PostPriority
|
||||
err := s.GetReplicaX().SelectBuilder(&priority, query)
|
||||
err := s.GetReplica().SelectBuilder(&priority, query)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -218,7 +218,7 @@ func (s *SqlPostStore) SaveMultiple(posts []*model.Post) ([]*model.Post, int, er
|
||||
return nil, -1, errors.Wrap(err, "post_tosql")
|
||||
}
|
||||
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return posts, -1, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -248,7 +248,7 @@ func (s *SqlPostStore) SaveMultiple(posts []*model.Post) ([]*model.Post, int, er
|
||||
for channelId, count := range channelNewPosts {
|
||||
countRoot := channelNewRootPosts[channelId]
|
||||
|
||||
if _, err = s.GetMasterX().NamedExec(`UPDATE Channels
|
||||
if _, err = s.GetMaster().NamedExec(`UPDATE Channels
|
||||
SET LastPostAt = GREATEST(:lastpostat, LastPostAt),
|
||||
LastRootPostAt = GREATEST(:lastrootpostat, LastRootPostAt),
|
||||
TotalMsgCount = TotalMsgCount + :count,
|
||||
@@ -265,7 +265,7 @@ func (s *SqlPostStore) SaveMultiple(posts []*model.Post) ([]*model.Post, int, er
|
||||
}
|
||||
|
||||
for rootId := range rootIds {
|
||||
if _, err = s.GetMasterX().Exec("UPDATE Posts SET UpdateAt = ? WHERE Id = ?", maxDateRootIds[rootId], rootId); err != nil {
|
||||
if _, err = s.GetMaster().Exec("UPDATE Posts SET UpdateAt = ? WHERE Id = ?", maxDateRootIds[rootId], rootId); err != nil {
|
||||
mlog.Warn("Error updating Post UpdateAt.", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
@@ -319,7 +319,7 @@ func (s *SqlPostStore) populateReplyCount(posts []*model.Post) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "post_tosql")
|
||||
}
|
||||
err = s.GetMasterX().Select(&countList, queryString, args...)
|
||||
err = s.GetMaster().Select(&countList, queryString, args...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to count Posts")
|
||||
}
|
||||
@@ -356,7 +356,7 @@ func (s *SqlPostStore) Update(rctx request.CTX, newPost *model.Post, oldPost *mo
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().NamedExec(`UPDATE Posts
|
||||
if _, err := s.GetMaster().NamedExec(`UPDATE Posts
|
||||
SET CreateAt=:CreateAt,
|
||||
UpdateAt=:UpdateAt,
|
||||
EditAt=:EditAt,
|
||||
@@ -381,12 +381,12 @@ func (s *SqlPostStore) Update(rctx request.CTX, newPost *model.Post, oldPost *mo
|
||||
}
|
||||
|
||||
time := model.GetMillis()
|
||||
if _, err := s.GetMasterX().Exec("UPDATE Channels SET LastPostAt = ? WHERE Id = ? AND LastPostAt < ?", time, newPost.ChannelId, time); err != nil {
|
||||
if _, err := s.GetMaster().Exec("UPDATE Channels SET LastPostAt = ? WHERE Id = ? AND LastPostAt < ?", time, newPost.ChannelId, time); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to update lastpostat of channels")
|
||||
}
|
||||
|
||||
if newPost.RootId != "" {
|
||||
if _, err := s.GetMasterX().Exec("UPDATE Posts SET UpdateAt = ? WHERE Id = ? AND UpdateAt < ?", time, newPost.RootId, time); err != nil {
|
||||
if _, err := s.GetMaster().Exec("UPDATE Posts SET UpdateAt = ? WHERE Id = ? AND UpdateAt < ?", time, newPost.RootId, time); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to update updateAt of posts")
|
||||
}
|
||||
}
|
||||
@@ -400,7 +400,7 @@ func (s *SqlPostStore) Update(rctx request.CTX, newPost *model.Post, oldPost *mo
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "post_tosql")
|
||||
}
|
||||
_, err = s.GetMasterX().Exec(query, args...)
|
||||
_, err = s.GetMaster().Exec(query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to insert the old post")
|
||||
}
|
||||
@@ -418,7 +418,7 @@ func (s *SqlPostStore) OverwriteMultiple(posts []*model.Post) (_ []*model.Post,
|
||||
}
|
||||
}
|
||||
|
||||
tx, err := s.GetMasterX().Beginx()
|
||||
tx, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, -1, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -538,7 +538,7 @@ func (s *SqlPostStore) getFlaggedPosts(userId, channelId, teamId string, offset
|
||||
|
||||
queryParams = append(queryParams, limit, offset)
|
||||
|
||||
if err := s.GetReplicaX().Select(&posts, query, queryParams...); err != nil {
|
||||
if err := s.GetReplica().Select(&posts, query, queryParams...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Posts")
|
||||
}
|
||||
|
||||
@@ -594,7 +594,7 @@ func (s *SqlPostStore) getPostWithCollapsedThreads(id, userID string, opts model
|
||||
return nil, errors.Wrap(err, "getPostWithCollapsedThreads_ToSql2")
|
||||
}
|
||||
|
||||
err = s.GetReplicaX().Get(&post, postFetchQuery, args...)
|
||||
err = s.GetReplica().Get(&post, postFetchQuery, args...)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Post", id)
|
||||
@@ -662,7 +662,7 @@ func (s *SqlPostStore) getPostWithCollapsedThreads(id, userID string, opts model
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "getPostWithCollapsedThreads_Tosql2")
|
||||
}
|
||||
err = s.GetReplicaX().Select(&posts, sql, args...)
|
||||
err = s.GetReplica().Select(&posts, sql, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Posts for thread %s", id)
|
||||
}
|
||||
@@ -810,7 +810,7 @@ func (s *SqlPostStore) Get(ctx context.Context, id string, opts model.GetPostsOp
|
||||
}
|
||||
|
||||
posts := []*model.Post{}
|
||||
err = s.GetReplicaX().Select(&posts, sql, args...)
|
||||
err = s.GetReplica().Select(&posts, sql, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Posts")
|
||||
}
|
||||
@@ -893,7 +893,7 @@ func (s *SqlPostStore) GetEtag(channelId string, allowFromCache, collapsedThread
|
||||
sql, args := q.MustSql()
|
||||
|
||||
var et etagPosts
|
||||
err := s.GetReplicaX().Get(&et, sql, args...)
|
||||
err := s.GetReplica().Get(&et, sql, args...)
|
||||
var result string
|
||||
if err != nil {
|
||||
result = fmt.Sprintf("%v.%v", model.CurrentVersion, model.GetMillis())
|
||||
@@ -907,7 +907,7 @@ func (s *SqlPostStore) GetEtag(channelId string, allowFromCache, collapsedThread
|
||||
// Soft deletes a post
|
||||
// and cleans up the thread if it's a comment
|
||||
func (s *SqlPostStore) Delete(rctx request.CTX, postID string, time int64, deleteByID string) (err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -976,7 +976,7 @@ func (s *SqlPostStore) PermanentDelete(rctx request.CTX, postID string) (err err
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) permanentDelete(postIds []string) (err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -1017,7 +1017,7 @@ type postIds struct {
|
||||
|
||||
func (s *SqlPostStore) permanentDeleteAllCommentByUser(userId string) (err error) {
|
||||
results := []postIds{}
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -1068,7 +1068,7 @@ func (s *SqlPostStore) PermanentDeleteByUser(rctx request.CTX, userId string) er
|
||||
count := 0
|
||||
for {
|
||||
var ids []string
|
||||
err := s.GetMasterX().Select(&ids, "SELECT Id FROM Posts WHERE UserId = ? LIMIT 1000", userId)
|
||||
err := s.GetMaster().Select(&ids, "SELECT Id FROM Posts WHERE UserId = ? LIMIT 1000", userId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to find Posts with userId=%s", userId)
|
||||
}
|
||||
@@ -1096,7 +1096,7 @@ func (s *SqlPostStore) PermanentDeleteByUser(rctx request.CTX, userId string) er
|
||||
// deletes all reactions
|
||||
// no thread comment cleanup needed, since we are deleting threads and thread memberships
|
||||
func (s *SqlPostStore) PermanentDeleteByChannel(rctx request.CTX, channelId string) (err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -1233,7 +1233,7 @@ func (s *SqlPostStore) getPostsCollapsedThreads(options model.GetPostsOptions, s
|
||||
Offset(uint64(offset)).
|
||||
OrderBy("Posts.CreateAt DESC").ToSql()
|
||||
|
||||
err := s.GetReplicaX().Select(&posts, postFetchQuery, args...)
|
||||
err := s.GetReplica().Select(&posts, postFetchQuery, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Posts with channelId=%s", options.ChannelId)
|
||||
}
|
||||
@@ -1321,7 +1321,7 @@ func (s *SqlPostStore) getPostsSinceCollapsedThreads(options model.GetPostsSince
|
||||
return nil, errors.Wrapf(err, "getPostsSinceCollapsedThreads_ToSql")
|
||||
}
|
||||
|
||||
err = s.GetReplicaX().Select(&posts, postFetchQuery, args...)
|
||||
err = s.GetReplica().Select(&posts, postFetchQuery, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Posts with channelId=%s", options.ChannelId)
|
||||
}
|
||||
@@ -1396,7 +1396,7 @@ func (s *SqlPostStore) GetPostsSince(options model.GetPostsSinceOptions, allowFr
|
||||
|
||||
params = []any{options.Time, options.ChannelId}
|
||||
}
|
||||
err := s.GetReplicaX().Select(&posts, query, params...)
|
||||
err := s.GetReplica().Select(&posts, query, params...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Posts with channelId=%s", options.ChannelId)
|
||||
}
|
||||
@@ -1429,7 +1429,7 @@ func (s *SqlPostStore) HasAutoResponsePostByUserSince(options model.GetPostsSinc
|
||||
LIMIT 1)`
|
||||
|
||||
var exist bool
|
||||
err := s.GetReplicaX().Get(&exist, query, options.Time, options.ChannelId, userId, model.PostTypeAutoResponder)
|
||||
err := s.GetReplica().Get(&exist, query, options.Time, options.ChannelId, userId, model.PostTypeAutoResponder)
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err,
|
||||
"failed to check if autoresponse posts in channelId=%s for userId=%s since %s", options.ChannelId, userId, model.GetTimeForMillis(options.Time))
|
||||
@@ -1476,7 +1476,7 @@ func (s *SqlPostStore) GetPostsSinceForSync(options model.GetPostsSinceForSyncOp
|
||||
}
|
||||
|
||||
posts := []*model.Post{}
|
||||
err = s.GetReplicaX().Select(&posts, queryString, args...)
|
||||
err = s.GetReplica().Select(&posts, queryString, args...)
|
||||
if err != nil {
|
||||
return nil, cursor, errors.Wrapf(err, "error getting Posts with channelId=%s", options.ChannelId)
|
||||
}
|
||||
@@ -1510,7 +1510,7 @@ func (s *SqlPostStore) GetPostsByThread(threadId string, since int64) ([]*model.
|
||||
Where(sq.GtOrEq{"CreateAt": since})
|
||||
|
||||
result := []*model.Post{}
|
||||
err := s.GetReplicaX().SelectBuilder(&result, query)
|
||||
err := s.GetReplica().SelectBuilder(&result, query)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to fetch thread posts")
|
||||
}
|
||||
@@ -1588,7 +1588,7 @@ func (s *SqlPostStore) getPostsAround(before bool, options model.GetPostsOptions
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "post_tosql")
|
||||
}
|
||||
err = s.GetReplicaX().Select(&posts, queryString, args...)
|
||||
err = s.GetReplica().Select(&posts, queryString, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Posts with channelId=%s", options.ChannelId)
|
||||
}
|
||||
@@ -1626,7 +1626,7 @@ func (s *SqlPostStore) getPostsAround(before bool, options model.GetPostsOptions
|
||||
if nErr != nil {
|
||||
return nil, errors.Wrap(nErr, "post_tosql")
|
||||
}
|
||||
nErr = s.GetReplicaX().Select(&parents, rootQueryString, rootArgs...)
|
||||
nErr = s.GetReplica().Select(&parents, rootQueryString, rootArgs...)
|
||||
if nErr != nil {
|
||||
return nil, errors.Wrapf(nErr, "failed to find Posts with channelId=%s", options.ChannelId)
|
||||
}
|
||||
@@ -1695,7 +1695,7 @@ func (s *SqlPostStore) getPostIdAroundTime(channelId string, time int64, before
|
||||
}
|
||||
|
||||
var postId string
|
||||
if err := s.GetMasterX().Get(&postId, queryString, args...); err != nil {
|
||||
if err := s.GetMaster().Get(&postId, queryString, args...); err != nil {
|
||||
if err != sql.ErrNoRows {
|
||||
return "", errors.Wrapf(err, "failed to get Post id with channelId=%s", channelId)
|
||||
}
|
||||
@@ -1736,7 +1736,7 @@ func (s *SqlPostStore) GetPostAfterTime(channelId string, time int64, collapsedT
|
||||
}
|
||||
|
||||
var post model.Post
|
||||
if err := s.GetMasterX().Get(&post, queryString, args...); err != nil {
|
||||
if err := s.GetMaster().Get(&post, queryString, args...); err != nil {
|
||||
if err != sql.ErrNoRows {
|
||||
return nil, errors.Wrapf(err, "failed to get Post with channelId=%s", channelId)
|
||||
}
|
||||
@@ -1760,7 +1760,7 @@ func (s *SqlPostStore) getRootPosts(channelId string, offset int, limit int, ski
|
||||
}
|
||||
}
|
||||
|
||||
err := s.GetReplicaX().Select(&posts, fetchQuery, channelId, limit, offset)
|
||||
err := s.GetReplica().Select(&posts, fetchQuery, channelId, limit, offset)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Posts")
|
||||
}
|
||||
@@ -1793,7 +1793,7 @@ func (s *SqlPostStore) getParentsPosts(channelId string, offset int, limit int,
|
||||
LIMIT ? OFFSET ?) q
|
||||
WHERE q.RootId != ''`
|
||||
|
||||
err := s.GetReplicaX().Select(&roots, rootQuery, channelId, limit, offset)
|
||||
err := s.GetReplica().Select(&roots, rootQuery, channelId, limit, offset)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Posts")
|
||||
}
|
||||
@@ -1836,7 +1836,7 @@ func (s *SqlPostStore) getParentsPosts(channelId string, offset int, limit int,
|
||||
}
|
||||
|
||||
posts := []*model.Post{}
|
||||
err = s.GetReplicaX().Select(&posts, sql, args...)
|
||||
err = s.GetReplica().Select(&posts, sql, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Posts")
|
||||
}
|
||||
@@ -1862,7 +1862,7 @@ func (s *SqlPostStore) getParentsPostsPostgreSQL(channelId string, offset int, l
|
||||
deleteAtQueryCondition, deleteAtSubQueryCondition = "", ""
|
||||
}
|
||||
|
||||
err := s.GetReplicaX().Select(&posts,
|
||||
err := s.GetReplica().Select(&posts,
|
||||
`SELECT q2.*`+replyCountQuery+`
|
||||
FROM
|
||||
Posts q2
|
||||
@@ -1913,7 +1913,7 @@ func (s *SqlPostStore) GetNthRecentPostTime(n int64) (int64, error) {
|
||||
}
|
||||
|
||||
var createAt int64
|
||||
if err := s.GetMasterX().Get(&createAt, query, queryArgs...); err != nil {
|
||||
if err := s.GetMaster().Get(&createAt, query, queryArgs...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return 0, store.NewErrNotFound("Post", "none")
|
||||
}
|
||||
@@ -2281,7 +2281,7 @@ func (s *SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) (model.A
|
||||
args = append(args, start, end)
|
||||
|
||||
rows := model.AnalyticsRows{}
|
||||
err := s.GetReplicaX().Select(
|
||||
err := s.GetReplica().Select(
|
||||
&rows,
|
||||
query,
|
||||
args...)
|
||||
@@ -2349,7 +2349,7 @@ func (s *SqlPostStore) AnalyticsPostCountsByDay(options *model.AnalyticsPostCoun
|
||||
args = append(args, end, start)
|
||||
|
||||
rows := model.AnalyticsRows{}
|
||||
err := s.GetReplicaX().Select(
|
||||
err := s.GetReplica().Select(
|
||||
&rows,
|
||||
query,
|
||||
args...)
|
||||
@@ -2409,7 +2409,7 @@ func (s *SqlPostStore) AnalyticsPostCount(options *model.PostCountOptions) (int6
|
||||
}
|
||||
|
||||
var v int64
|
||||
err = s.GetReplicaX().Get(&v, queryString, args...)
|
||||
err = s.GetReplica().Get(&v, queryString, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count Posts")
|
||||
}
|
||||
@@ -2421,7 +2421,7 @@ func (s *SqlPostStore) GetPostsCreatedAt(channelId string, time int64) ([]*model
|
||||
query := `SELECT * FROM Posts WHERE CreateAt = ? AND ChannelId = ?`
|
||||
|
||||
posts := []*model.Post{}
|
||||
err := s.GetReplicaX().Select(&posts, query, time, channelId)
|
||||
err := s.GetReplica().Select(&posts, query, time, channelId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Posts with channelId=%s", channelId)
|
||||
}
|
||||
@@ -2440,7 +2440,7 @@ func (s *SqlPostStore) GetPostsByIds(postIds []string) ([]*model.Post, error) {
|
||||
}
|
||||
posts := []*model.Post{}
|
||||
|
||||
err = s.GetReplicaX().Select(&posts, query, args...)
|
||||
err = s.GetReplica().Select(&posts, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Posts")
|
||||
}
|
||||
@@ -2466,7 +2466,7 @@ func (s *SqlPostStore) GetEditHistoryForPost(postId string) ([]*model.Post, erro
|
||||
}
|
||||
|
||||
posts := []*model.Post{}
|
||||
err = s.GetReplicaX().Select(&posts, queryString, args...)
|
||||
err = s.GetReplica().Select(&posts, queryString, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "error getting posts edit history with postId=%s", postId)
|
||||
}
|
||||
@@ -2559,7 +2559,7 @@ func (s *SqlPostStore) PermanentDeleteBatch(endTime int64, limit int64) (int64,
|
||||
query = "DELETE from Posts WHERE CreateAt < ? LIMIT ?"
|
||||
}
|
||||
|
||||
sqlResult, err := s.GetMasterX().Exec(query, endTime, limit)
|
||||
sqlResult, err := s.GetMaster().Exec(query, endTime, limit)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to delete Posts")
|
||||
}
|
||||
@@ -2573,7 +2573,7 @@ func (s *SqlPostStore) PermanentDeleteBatch(endTime int64, limit int64) (int64,
|
||||
|
||||
func (s *SqlPostStore) GetOldest() (*model.Post, error) {
|
||||
var post model.Post
|
||||
err := s.GetReplicaX().Get(&post, "SELECT * FROM Posts ORDER BY CreateAt LIMIT 1")
|
||||
err := s.GetReplica().Get(&post, "SELECT * FROM Posts ORDER BY CreateAt LIMIT 1")
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Post", "none")
|
||||
@@ -2591,7 +2591,7 @@ func (s *SqlPostStore) determineMaxPostSize() int {
|
||||
if s.DriverName() == model.DatabaseDriverPostgres {
|
||||
// The Post.Message column in Postgres has historically been VARCHAR(4000), but
|
||||
// may be manually enlarged to support longer posts.
|
||||
if err := s.GetReplicaX().Get(&maxPostSizeBytes, `
|
||||
if err := s.GetReplica().Get(&maxPostSizeBytes, `
|
||||
SELECT
|
||||
COALESCE(character_maximum_length, 0)
|
||||
FROM
|
||||
@@ -2605,7 +2605,7 @@ func (s *SqlPostStore) determineMaxPostSize() int {
|
||||
} else if s.DriverName() == model.DatabaseDriverMysql {
|
||||
// The Post.Message column in MySQL has historically been TEXT, with a maximum
|
||||
// limit of 65535.
|
||||
if err := s.GetReplicaX().Get(&maxPostSizeBytes, `
|
||||
if err := s.GetReplica().Get(&maxPostSizeBytes, `
|
||||
SELECT
|
||||
COALESCE(CHARACTER_MAXIMUM_LENGTH, 0)
|
||||
FROM
|
||||
@@ -2649,7 +2649,7 @@ func (s *SqlPostStore) GetMaxPostSize() int {
|
||||
func (s *SqlPostStore) GetParentsForExportAfter(limit int, afterId string, includeArchivedChannel bool) ([]*model.PostForExport, error) {
|
||||
for {
|
||||
rootIds := []string{}
|
||||
err := s.GetReplicaX().Select(&rootIds,
|
||||
err := s.GetReplica().Select(&rootIds,
|
||||
`SELECT
|
||||
Id
|
||||
FROM
|
||||
@@ -2780,7 +2780,7 @@ func (s *SqlPostStore) GetDirectPostParentsForExportAfter(limit int, afterId str
|
||||
return nil, errors.Wrap(err, "post_tosql")
|
||||
}
|
||||
|
||||
if err2 := s.GetReplicaX().Select(&result, queryString, args...); err2 != nil {
|
||||
if err2 := s.GetReplica().Select(&result, queryString, args...); err2 != nil {
|
||||
return nil, errors.Wrap(err2, "failed to find Posts")
|
||||
}
|
||||
var channelIds []string
|
||||
@@ -2801,7 +2801,7 @@ func (s *SqlPostStore) GetDirectPostParentsForExportAfter(limit int, afterId str
|
||||
}
|
||||
|
||||
channelMembers := []*model.ChannelMemberForExport{}
|
||||
if err = s.GetReplicaX().Select(&channelMembers, queryString, args...); err != nil {
|
||||
if err = s.GetReplica().Select(&channelMembers, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find ChannelMembers")
|
||||
}
|
||||
|
||||
@@ -2889,7 +2889,7 @@ func (s *SqlPostStore) GetOldestEntityCreationTime() (int64, error) {
|
||||
}
|
||||
|
||||
var oldest int64
|
||||
err = s.GetReplicaX().Get(&oldest, queryString, args...)
|
||||
err = s.GetReplica().Get(&oldest, queryString, args...)
|
||||
if err != nil {
|
||||
return -1, errors.Wrap(err, "unable to scan oldest entity creation time")
|
||||
}
|
||||
@@ -3206,7 +3206,7 @@ func (s *SqlPostStore) updateThreadsFromPosts(transaction *sqlxTxWrapper, posts
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) SetPostReminder(reminder *model.PostReminder) error {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -3249,7 +3249,7 @@ func (s *SqlPostStore) SetPostReminder(reminder *model.PostReminder) error {
|
||||
func (s *SqlPostStore) GetPostReminders(now int64) (_ []*model.PostReminder, err error) {
|
||||
reminders := []*model.PostReminder{}
|
||||
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -3284,7 +3284,7 @@ func (s *SqlPostStore) GetPostReminders(now int64) (_ []*model.PostReminder, err
|
||||
|
||||
func (s *SqlPostStore) GetPostReminderMetadata(postID string) (*store.PostReminderMetadata, error) {
|
||||
meta := &store.PostReminderMetadata{}
|
||||
err := s.GetReplicaX().Get(meta, `SELECT c.id as ChannelID,
|
||||
err := s.GetReplica().Get(meta, `SELECT c.id as ChannelID,
|
||||
COALESCE(t.name, '') as TeamName,
|
||||
u.locale as UserLocale, u.username as Username
|
||||
FROM Posts p
|
||||
|
||||
@@ -30,14 +30,14 @@ func (s SqlPreferenceStore) deleteUnusedFeatures() {
|
||||
if err != nil {
|
||||
mlog.Warn("Could not build sql query to delete unused features", mlog.Err(err))
|
||||
}
|
||||
if _, err = s.GetMasterX().Exec(sql, args...); err != nil {
|
||||
if _, err = s.GetMaster().Exec(sql, args...); err != nil {
|
||||
mlog.Warn("Failed to delete unused features", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
func (s SqlPreferenceStore) Save(preferences model.Preferences) (err error) {
|
||||
// wrap in a transaction so that if one fails, everything fails
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func (s SqlPreferenceStore) Get(userId string, category string, name string) (*m
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not build sql query to get preference")
|
||||
}
|
||||
if err = s.GetReplicaX().Get(&preference, query, args...); err != nil {
|
||||
if err = s.GetReplica().Get(&preference, query, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Preference with userId=%s, category=%s, name=%s", userId, category, name)
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ func (s SqlPreferenceStore) GetCategoryAndName(category string, name string) (mo
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not build sql query to get preference")
|
||||
}
|
||||
if err = s.GetReplicaX().Select(&preferences, query, args...); err != nil {
|
||||
if err = s.GetReplica().Select(&preferences, query, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Preference with category=%s, name=%s", category, name)
|
||||
}
|
||||
return preferences, nil
|
||||
@@ -167,7 +167,7 @@ func (s SqlPreferenceStore) GetCategory(userId string, category string) (model.P
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not build sql query to get preference")
|
||||
}
|
||||
if err = s.GetReplicaX().Select(&preferences, query, args...); err != nil {
|
||||
if err = s.GetReplica().Select(&preferences, query, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Preference with userId=%s, category=%s", userId, category)
|
||||
}
|
||||
return preferences, nil
|
||||
@@ -183,7 +183,7 @@ func (s SqlPreferenceStore) GetAll(userId string) (model.Preferences, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not build sql query to get preference")
|
||||
}
|
||||
if err = s.GetReplicaX().Select(&preferences, query, args...); err != nil {
|
||||
if err = s.GetReplica().Select(&preferences, query, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Preference with userId=%s", userId)
|
||||
}
|
||||
return preferences, nil
|
||||
@@ -196,7 +196,7 @@ func (s SqlPreferenceStore) PermanentDeleteByUser(userId string) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not build sql query to get delete preference by user")
|
||||
}
|
||||
if _, err := s.GetMasterX().Exec(sql, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(sql, args...); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete Preference with userId=%s", userId)
|
||||
}
|
||||
return nil
|
||||
@@ -213,7 +213,7 @@ func (s SqlPreferenceStore) Delete(userId, category, name string) error {
|
||||
return errors.Wrap(err, "could not build sql query to get delete preference")
|
||||
}
|
||||
|
||||
if _, err = s.GetMasterX().Exec(sql, args...); err != nil {
|
||||
if _, err = s.GetMaster().Exec(sql, args...); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete Preference with userId=%s, category=%s and name=%s", userId, category, name)
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ func (s SqlPreferenceStore) DeleteCategory(userId string, category string) error
|
||||
return errors.Wrap(err, "could not build sql query to get delete preference by category")
|
||||
}
|
||||
|
||||
if _, err = s.GetMasterX().Exec(sql, args...); err != nil {
|
||||
if _, err = s.GetMaster().Exec(sql, args...); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete Preference with userId=%s and category=%s", userId, category)
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ func (s SqlPreferenceStore) DeleteCategoryAndName(category string, name string)
|
||||
return errors.Wrap(err, "could not build sql query to get delete preference by category and name")
|
||||
}
|
||||
|
||||
if _, err = s.GetMasterX().Exec(sql, args...); err != nil {
|
||||
if _, err = s.GetMaster().Exec(sql, args...); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete Preference with category=%s and name=%s", category, name)
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ func (s *SqlPreferenceStore) DeleteOrphanedRows(limit int) (deleted int64, err e
|
||||
) AS A
|
||||
)`
|
||||
|
||||
result, err := s.GetMasterX().Exec(query, model.PreferenceCategoryFlaggedPost, limit)
|
||||
result, err := s.GetMaster().Exec(query, model.PreferenceCategoryFlaggedPost, limit)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -304,7 +304,7 @@ func (s SqlPreferenceStore) CleanupFlagsBatch(limit int64) (int64, error) {
|
||||
return int64(0), errors.Wrap(err, "could not build sql query to delete preference")
|
||||
}
|
||||
|
||||
sqlResult, err := s.GetMasterX().Exec(query, args...)
|
||||
sqlResult, err := s.GetMaster().Exec(query, args...)
|
||||
if err != nil {
|
||||
return int64(0), errors.Wrap(err, "failed to delete Preference")
|
||||
}
|
||||
@@ -356,7 +356,7 @@ func (s SqlPreferenceStore) DeleteInvalidVisibleDmsGms() (int64, error) {
|
||||
}
|
||||
}
|
||||
|
||||
result, err := s.GetMasterX().Exec(queryString, args...)
|
||||
result, err := s.GetMaster().Exec(queryString, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to delete Preference")
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ func TestDeleteUnusedFeatures(t *testing.T) {
|
||||
|
||||
//make sure features with value "false" have actually been deleted from the database
|
||||
var val int64
|
||||
if err := ss.Preference().(*SqlPreferenceStore).GetReplicaX().Get(&val, `SELECT COUNT(*)
|
||||
if err := ss.Preference().(*SqlPreferenceStore).GetReplica().Get(&val, `SELECT COUNT(*)
|
||||
FROM Preferences
|
||||
WHERE Category = ?
|
||||
AND Value = ?
|
||||
@@ -71,7 +71,7 @@ func TestDeleteUnusedFeatures(t *testing.T) {
|
||||
}
|
||||
//
|
||||
// make sure features with value "true" remain saved
|
||||
if err := ss.Preference().(*SqlPreferenceStore).GetReplicaX().Get(&val, `SELECT COUNT(*)
|
||||
if err := ss.Preference().(*SqlPreferenceStore).GetReplica().Get(&val, `SELECT COUNT(*)
|
||||
FROM Preferences
|
||||
WHERE Category = ?
|
||||
AND Value = ?
|
||||
|
||||
@@ -27,7 +27,7 @@ func (s SqlProductNoticesStore) Clear(notices []string) error {
|
||||
return errors.Wrap(err, "product_notice_view_state_tosql")
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().Exec(sql, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(sql, args...); err != nil {
|
||||
return errors.Wrap(err, "failed to delete records from ProductNoticeViewState")
|
||||
}
|
||||
return nil
|
||||
@@ -43,14 +43,14 @@ func (s SqlProductNoticesStore) ClearOldNotices(currentNotices model.ProductNoti
|
||||
return errors.Wrap(err, "product_notice_view_state_tosql")
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().Exec(sql, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(sql, args...); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete records from ProductNoticeViewState")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlProductNoticesStore) View(userId string, notices []string) (err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -119,7 +119,7 @@ func (s SqlProductNoticesStore) GetViews(userId string) ([]model.ProductNoticeVi
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "product_notice_view_state_tosql")
|
||||
}
|
||||
if err := s.GetReplicaX().Select(¬iceStates, sql, args...); err != nil {
|
||||
if err := s.GetReplica().Select(¬iceStates, sql, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get ProductNoticeViewState with userId=%s", userId)
|
||||
}
|
||||
return noticeStates, nil
|
||||
|
||||
@@ -30,7 +30,7 @@ func (s *SqlReactionStore) Save(reaction *model.Reaction) (re *model.Reaction, e
|
||||
if err := reaction.IsValid(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -68,7 +68,7 @@ func (s *SqlReactionStore) Save(reaction *model.Reaction) (re *model.Reaction, e
|
||||
func (s *SqlReactionStore) Delete(reaction *model.Reaction) (re *model.Reaction, err error) {
|
||||
reaction.PreUpdate()
|
||||
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func (s *SqlReactionStore) GetForPost(postId string, allowFromCache bool) ([]*mo
|
||||
OrderBy("CreateAt")
|
||||
|
||||
var reactions []*model.Reaction
|
||||
if err := s.GetReplicaX().SelectBuilder(&reactions, builder); err != nil {
|
||||
if err := s.GetReplica().SelectBuilder(&reactions, builder); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get Reactions with postId=%s", postId)
|
||||
}
|
||||
return reactions, nil
|
||||
@@ -111,7 +111,7 @@ func (s *SqlReactionStore) ExistsOnPost(postId string, emojiName string) (bool,
|
||||
Where(sq.Eq{"COALESCE(DeleteAt, 0)": 0})
|
||||
|
||||
var hasRows bool
|
||||
if err := s.GetReplicaX().GetBuilder(&hasRows, query); err != nil {
|
||||
if err := s.GetReplica().GetBuilder(&hasRows, query); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return false, nil
|
||||
}
|
||||
@@ -140,7 +140,7 @@ func (s *SqlReactionStore) GetForPostSince(postId string, since int64, excludeRe
|
||||
}
|
||||
|
||||
var reactions []*model.Reaction
|
||||
if err := s.GetReplicaX().SelectBuilder(&reactions, query); err != nil {
|
||||
if err := s.GetReplica().SelectBuilder(&reactions, query); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find reactions")
|
||||
}
|
||||
return reactions, nil
|
||||
@@ -154,7 +154,7 @@ func (s *SqlReactionStore) GetUniqueCountForPost(postId string) (int, error) {
|
||||
Where(sq.Eq{"DeleteAt": 0})
|
||||
|
||||
var count int64
|
||||
err := s.GetReplicaX().GetBuilder(&count, query)
|
||||
err := s.GetReplica().GetBuilder(&count, query)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count Reactions")
|
||||
}
|
||||
@@ -165,7 +165,7 @@ func (s *SqlReactionStore) BulkGetForPosts(postIds []string) ([]*model.Reaction,
|
||||
placeholder, values := constructArrayArgs(postIds)
|
||||
var reactions []*model.Reaction
|
||||
|
||||
if err := s.GetReplicaX().Select(&reactions,
|
||||
if err := s.GetReplica().Select(&reactions,
|
||||
`SELECT
|
||||
UserId,
|
||||
PostId,
|
||||
@@ -198,7 +198,7 @@ func (s *SqlReactionStore) GetSingle(userID, postID, remoteID, emojiName string)
|
||||
Where(sq.Eq{"EmojiName": emojiName})
|
||||
|
||||
var reactions []*model.Reaction
|
||||
if err := s.GetReplicaX().SelectBuilder(&reactions, query); err != nil {
|
||||
if err := s.GetReplica().SelectBuilder(&reactions, query); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find reaction")
|
||||
}
|
||||
if len(reactions) == 0 {
|
||||
@@ -212,7 +212,7 @@ func (s *SqlReactionStore) DeleteAllWithEmojiName(emojiName string) error {
|
||||
var reactions []*model.Reaction
|
||||
now := model.GetMillis()
|
||||
|
||||
if err := s.GetReplicaX().Select(&reactions,
|
||||
if err := s.GetReplica().Select(&reactions,
|
||||
`SELECT
|
||||
UserId,
|
||||
PostId,
|
||||
@@ -228,7 +228,7 @@ func (s *SqlReactionStore) DeleteAllWithEmojiName(emojiName string) error {
|
||||
return errors.Wrapf(err, "failed to get Reactions with emojiName=%s", emojiName)
|
||||
}
|
||||
|
||||
_, err := s.GetMasterX().Exec(
|
||||
_, err := s.GetMaster().Exec(
|
||||
`UPDATE
|
||||
Reactions
|
||||
SET
|
||||
@@ -241,7 +241,7 @@ func (s *SqlReactionStore) DeleteAllWithEmojiName(emojiName string) error {
|
||||
|
||||
for _, reaction := range reactions {
|
||||
reaction := reaction
|
||||
_, err := s.GetMasterX().Exec(UpdatePostHasReactionsOnDeleteQuery, now, reaction.PostId, reaction.PostId)
|
||||
_, err := s.GetMaster().Exec(UpdatePostHasReactionsOnDeleteQuery, now, reaction.PostId, reaction.PostId)
|
||||
if err != nil {
|
||||
mlog.Warn("Unable to update Post.HasReactions while removing reactions",
|
||||
mlog.String("post_id", reaction.PostId),
|
||||
@@ -253,7 +253,7 @@ func (s *SqlReactionStore) DeleteAllWithEmojiName(emojiName string) error {
|
||||
}
|
||||
|
||||
func (s *SqlReactionStore) permanentDeleteReactions(userId string) ([]string, error) {
|
||||
txn, err := s.GetMasterX().Beginx()
|
||||
txn, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -290,7 +290,7 @@ func (s SqlReactionStore) PermanentDeleteByUser(userId string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -313,7 +313,7 @@ func (s SqlReactionStore) PermanentDeleteByUser(userId string) error {
|
||||
}
|
||||
|
||||
func (s *SqlReactionStore) DeleteOrphanedRowsByIds(r *model.RetentionIdsForDeletion) (int64, error) {
|
||||
txn, err := s.GetMasterX().Beginx()
|
||||
txn, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -353,7 +353,7 @@ func (s *SqlReactionStore) PermanentDeleteBatch(endTime int64, limit int64) (int
|
||||
query = "DELETE from Reactions WHERE CreateAt < ? LIMIT ?"
|
||||
}
|
||||
|
||||
sqlResult, err := s.GetMasterX().Exec(query, endTime, limit)
|
||||
sqlResult, err := s.GetMaster().Exec(query, endTime, limit)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to delete Reactions")
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func (s sqlRemoteClusterStore) Save(remoteCluster *model.RemoteCluster) (*model.
|
||||
(:RemoteId, :RemoteTeamId, :Name, :DisplayName, :SiteURL, :DefaultTeamId, :CreateAt,
|
||||
:DeleteAt, :LastPingAt, :Token, :RemoteToken, :Topics, :CreatorId, :PluginID, :Options)`
|
||||
|
||||
if _, err := s.GetMasterX().NamedExec(query, remoteCluster); err != nil {
|
||||
if _, err := s.GetMaster().NamedExec(query, remoteCluster); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to save RemoteCluster")
|
||||
}
|
||||
return remoteCluster, nil
|
||||
@@ -102,14 +102,14 @@ func (s sqlRemoteClusterStore) Update(remoteCluster *model.RemoteCluster) (*mode
|
||||
Options = :Options
|
||||
WHERE RemoteId = :RemoteId AND Name = :Name`
|
||||
|
||||
if _, err := s.GetMasterX().NamedExec(query, remoteCluster); err != nil {
|
||||
if _, err := s.GetMaster().NamedExec(query, remoteCluster); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to update RemoteCluster")
|
||||
}
|
||||
return remoteCluster, nil
|
||||
}
|
||||
|
||||
func (s sqlRemoteClusterStore) Delete(remoteId string) (bool, error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "DeleteRemoteCluster: begin_transaction")
|
||||
}
|
||||
@@ -175,7 +175,7 @@ func (s sqlRemoteClusterStore) Get(remoteId string, includeDeleted bool) (*model
|
||||
}
|
||||
|
||||
var rc model.RemoteCluster
|
||||
if err := s.GetReplicaX().Get(&rc, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&rc, queryString, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find RemoteCluster")
|
||||
}
|
||||
return &rc, nil
|
||||
@@ -193,7 +193,7 @@ func (s sqlRemoteClusterStore) GetByPluginID(pluginID string) (*model.RemoteClus
|
||||
}
|
||||
|
||||
var rc model.RemoteCluster
|
||||
if err := s.GetReplicaX().Get(&rc, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&rc, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find RemoteCluster by plugin_id")
|
||||
}
|
||||
return &rc, nil
|
||||
@@ -269,7 +269,7 @@ func (s sqlRemoteClusterStore) GetAll(offset, limit int, filter model.RemoteClus
|
||||
}
|
||||
|
||||
list := []*model.RemoteCluster{}
|
||||
if err := s.GetReplicaX().Select(&list, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&list, queryString, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find RemoteClusters")
|
||||
}
|
||||
return list, nil
|
||||
@@ -288,7 +288,7 @@ func (s sqlRemoteClusterStore) UpdateTopics(remoteClusterid string, topics strin
|
||||
SET Topics = :Topics
|
||||
WHERE RemoteId = :RemoteId`
|
||||
|
||||
if _, err = s.GetMasterX().NamedExec(query, rc); err != nil {
|
||||
if _, err = s.GetMaster().NamedExec(query, rc); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rc, nil
|
||||
@@ -305,7 +305,7 @@ func (s sqlRemoteClusterStore) SetLastPingAt(remoteClusterId string) error {
|
||||
return errors.Wrap(err, "remote_cluster_tosql")
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(queryString, args...); err != nil {
|
||||
return errors.Wrap(err, "failed to update RemoteCluster")
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -80,7 +80,7 @@ func (s *SqlRetentionPolicyStore) Save(policy *model.RetentionPolicyWithTeamAndC
|
||||
return nil, err
|
||||
}
|
||||
|
||||
txn, err := s.GetMasterX().Beginx()
|
||||
txn, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -121,7 +121,7 @@ func (s *SqlRetentionPolicyStore) checkTeamsExist(teamIDs []string) error {
|
||||
return err
|
||||
}
|
||||
rows := []*string{}
|
||||
err = s.GetReplicaX().Select(&rows, teamsSelectQuery, teamsSelectArgs...)
|
||||
err = s.GetReplica().Select(&rows, teamsSelectQuery, teamsSelectArgs...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -152,7 +152,7 @@ func (s *SqlRetentionPolicyStore) checkChannelsExist(channelIDs []string) error
|
||||
return err
|
||||
}
|
||||
rows := []*string{}
|
||||
err = s.GetReplicaX().Select(&rows, channelsSelectQuery, channelsSelectArgs...)
|
||||
err = s.GetReplica().Select(&rows, channelsSelectQuery, channelsSelectArgs...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -275,7 +275,7 @@ func (s *SqlRetentionPolicyStore) Patch(patch *model.RetentionPolicyWithTeamAndC
|
||||
return nil, err
|
||||
}
|
||||
|
||||
txn, err := s.GetMasterX().Beginx()
|
||||
txn, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -389,7 +389,7 @@ func (s *SqlRetentionPolicyStore) Get(id string) (*model.RetentionPolicyWithTeam
|
||||
}
|
||||
|
||||
var policy model.RetentionPolicyWithTeamAndChannelCounts
|
||||
if err := s.GetReplicaX().Get(&policy, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&policy, queryString, args...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &policy, nil
|
||||
@@ -401,13 +401,13 @@ func (s *SqlRetentionPolicyStore) GetAll(offset, limit int) ([]*model.RetentionP
|
||||
if err != nil {
|
||||
return policies, err
|
||||
}
|
||||
err = s.GetReplicaX().Select(&policies, queryString, args...)
|
||||
err = s.GetReplica().Select(&policies, queryString, args...)
|
||||
return policies, err
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) GetCount() (int64, error) {
|
||||
var count int64
|
||||
err := s.GetReplicaX().Get(&count, "SELECT COUNT(*) FROM RetentionPolicies")
|
||||
err := s.GetReplica().Get(&count, "SELECT COUNT(*) FROM RetentionPolicies")
|
||||
if err != nil {
|
||||
return count, err
|
||||
}
|
||||
@@ -425,7 +425,7 @@ func (s *SqlRetentionPolicyStore) Delete(id string) error {
|
||||
return errors.Wrap(err, "retention_policies_tosql")
|
||||
}
|
||||
|
||||
sqlResult, err := s.GetMasterX().Exec(queryString, args...)
|
||||
sqlResult, err := s.GetMaster().Exec(queryString, args...)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to permanent delete retention policy with id=%s", id)
|
||||
}
|
||||
@@ -457,7 +457,7 @@ func (s *SqlRetentionPolicyStore) GetChannels(policyId string, offset, limit int
|
||||
}
|
||||
|
||||
channels := model.ChannelListWithTeamData{}
|
||||
if err := s.GetReplicaX().Select(&channels, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&channels, queryString, args...); err != nil {
|
||||
return channels, errors.Wrap(err, "failed to find RetentionPoliciesChannels")
|
||||
}
|
||||
|
||||
@@ -481,7 +481,7 @@ func (s *SqlRetentionPolicyStore) GetChannelsCount(policyId string) (int64, erro
|
||||
}
|
||||
|
||||
var count int64
|
||||
if err := s.GetReplicaX().Get(&count, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&count, queryString, args...); err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count RetentionPolicies")
|
||||
}
|
||||
|
||||
@@ -508,7 +508,7 @@ func (s *SqlRetentionPolicyStore) AddChannels(policyId string, channelIds []stri
|
||||
return errors.Wrap(err, "retention_policies_channels_tosql")
|
||||
}
|
||||
|
||||
_, err = s.GetMasterX().Exec(queryString, args...)
|
||||
_, err = s.GetMaster().Exec(queryString, args...)
|
||||
if err != nil {
|
||||
switch dbErr := err.(type) {
|
||||
case *pq.Error:
|
||||
@@ -541,7 +541,7 @@ func (s *SqlRetentionPolicyStore) RemoveChannels(policyId string, channelIds []s
|
||||
return errors.Wrap(err, "retention_policies_channels_tosql")
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(queryString, args...); err != nil {
|
||||
return errors.Wrapf(err, "failed to permanent delete retention policy channels with policyid=%s", policyId)
|
||||
}
|
||||
|
||||
@@ -564,7 +564,7 @@ func (s *SqlRetentionPolicyStore) GetTeams(policyId string, offset, limit int) (
|
||||
}
|
||||
|
||||
teams := []*model.Team{}
|
||||
if err = s.GetReplicaX().Select(&teams, queryString, args...); err != nil {
|
||||
if err = s.GetReplica().Select(&teams, queryString, args...); err != nil {
|
||||
return teams, errors.Wrap(err, "failed to find Teams")
|
||||
}
|
||||
|
||||
@@ -584,7 +584,7 @@ func (s *SqlRetentionPolicyStore) GetTeamsCount(policyId string) (int64, error)
|
||||
}
|
||||
|
||||
var count int64
|
||||
if err := s.GetReplicaX().Get(&count, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&count, queryString, args...); err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count RetentionPolicies")
|
||||
}
|
||||
|
||||
@@ -610,7 +610,7 @@ func (s *SqlRetentionPolicyStore) AddTeams(policyId string, teamIds []string) er
|
||||
return errors.Wrap(err, "retention_policies_teams_tosql")
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(queryString, args...); err != nil {
|
||||
return errors.Wrap(err, "failed to insert retention policies teams")
|
||||
}
|
||||
|
||||
@@ -633,7 +633,7 @@ func (s *SqlRetentionPolicyStore) RemoveTeams(policyId string, teamIds []string)
|
||||
return errors.Wrap(err, "retention_policies_teams_tosql")
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(queryString, args...); err != nil {
|
||||
return errors.Wrapf(err, "unable to permanent delete retention policies teams with policyid=%s", policyId)
|
||||
}
|
||||
|
||||
@@ -678,7 +678,7 @@ func (s *SqlRetentionPolicyStore) DeleteOrphanedRows(limit int) (deleted int64,
|
||||
return int64(0), errors.Wrap(err, "retention_policies_teams_tosql")
|
||||
}
|
||||
|
||||
result, err := s.GetMasterX().Exec(rpcDeleteQuery, rpcArgs...)
|
||||
result, err := s.GetMaster().Exec(rpcDeleteQuery, rpcArgs...)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -686,7 +686,7 @@ func (s *SqlRetentionPolicyStore) DeleteOrphanedRows(limit int) (deleted int64,
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
result, err = s.GetMasterX().Exec(rptDeleteQuery, rptArgs...)
|
||||
result, err = s.GetMaster().Exec(rptDeleteQuery, rptArgs...)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -723,7 +723,7 @@ func (s *SqlRetentionPolicyStore) GetTeamPoliciesForUser(userID string, offset,
|
||||
}
|
||||
|
||||
policies := []*model.RetentionPolicyForTeam{}
|
||||
if err := s.GetReplicaX().Select(&policies, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&policies, queryString, args...); err != nil {
|
||||
return policies, errors.Wrap(err, "failed to find Users")
|
||||
}
|
||||
|
||||
@@ -752,7 +752,7 @@ func (s *SqlRetentionPolicyStore) GetTeamPoliciesCountForUser(userID string) (in
|
||||
}
|
||||
|
||||
var count int64
|
||||
if err := s.GetReplicaX().Get(&count, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&count, queryString, args...); err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count TeamPoliciesCountForUser")
|
||||
}
|
||||
|
||||
@@ -783,7 +783,7 @@ func (s *SqlRetentionPolicyStore) GetChannelPoliciesForUser(userID string, offse
|
||||
}
|
||||
|
||||
policies := []*model.RetentionPolicyForChannel{}
|
||||
if err := s.GetReplicaX().Select(&policies, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&policies, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Users")
|
||||
}
|
||||
|
||||
@@ -811,7 +811,7 @@ func (s *SqlRetentionPolicyStore) GetChannelPoliciesCountForUser(userID string)
|
||||
}
|
||||
|
||||
var count int64
|
||||
if err := s.GetReplicaX().Get(&count, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&count, queryString, args...); err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count ChannelPoliciesCountForUser")
|
||||
}
|
||||
|
||||
@@ -862,7 +862,7 @@ func (s *SqlRetentionPolicyStore) GetIdsForDeletionByTableName(tableName string,
|
||||
return nil, errors.Wrap(err, "get_ids_for_deletion_tosql")
|
||||
}
|
||||
|
||||
rows, err := s.GetReplicaX().DB.Query(queryString, args...)
|
||||
rows, err := s.GetReplica().DB.Query(queryString, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get ids for deletion")
|
||||
}
|
||||
@@ -1048,7 +1048,7 @@ func genericRetentionPoliciesDeletion(
|
||||
}
|
||||
|
||||
if r.StoreDeletedIds {
|
||||
txn, err := s.GetMasterX().Beginx()
|
||||
txn, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -1130,7 +1130,7 @@ func genericRetentionPoliciesDeletion(
|
||||
} else {
|
||||
query = getDeleteQueriesForMySQL(r, query)
|
||||
}
|
||||
result, err := s.GetMasterX().Exec(query, args...)
|
||||
result, err := s.GetMaster().Exec(query, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to delete "+r.Table)
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func (s *SqlRoleStore) Save(role *model.Role) (_ *model.Role, err error) {
|
||||
}
|
||||
|
||||
if role.Id == "" {
|
||||
transaction, terr := s.GetMasterX().Beginx()
|
||||
transaction, terr := s.GetMaster().Beginx()
|
||||
if terr != nil {
|
||||
return nil, errors.Wrap(terr, "begin_transaction")
|
||||
}
|
||||
@@ -111,7 +111,7 @@ func (s *SqlRoleStore) Save(role *model.Role) (_ *model.Role, err error) {
|
||||
dbRole := NewRoleFromModel(role)
|
||||
dbRole.UpdateAt = model.GetMillis()
|
||||
|
||||
res, err := s.GetMasterX().NamedExec(`UPDATE Roles
|
||||
res, err := s.GetMaster().NamedExec(`UPDATE Roles
|
||||
SET UpdateAt=:UpdateAt, DeleteAt=:DeleteAt, CreateAt=:CreateAt, Name=:Name, DisplayName=:DisplayName,
|
||||
Description=:Description, Permissions=:Permissions, SchemeManaged=:SchemeManaged, BuiltIn=:BuiltIn
|
||||
WHERE Id=:Id`, &dbRole)
|
||||
@@ -157,7 +157,7 @@ func (s *SqlRoleStore) createRole(role *model.Role, transaction *sqlxTxWrapper)
|
||||
func (s *SqlRoleStore) Get(roleId string) (*model.Role, error) {
|
||||
dbRole := Role{}
|
||||
|
||||
if err := s.GetReplicaX().Get(&dbRole, "SELECT * from Roles WHERE Id = ?", roleId); err != nil {
|
||||
if err := s.GetReplica().Get(&dbRole, "SELECT * from Roles WHERE Id = ?", roleId); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Role", roleId)
|
||||
}
|
||||
@@ -170,7 +170,7 @@ func (s *SqlRoleStore) Get(roleId string) (*model.Role, error) {
|
||||
func (s *SqlRoleStore) GetAll() ([]*model.Role, error) {
|
||||
dbRoles := []Role{}
|
||||
|
||||
if err := s.GetReplicaX().Select(&dbRoles, "SELECT * from Roles"); err != nil {
|
||||
if err := s.GetReplica().Select(&dbRoles, "SELECT * from Roles"); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Roles")
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ func (s *SqlRoleStore) GetByNames(names []string) ([]*model.Role, error) {
|
||||
return nil, errors.Wrap(err, "role_tosql")
|
||||
}
|
||||
|
||||
rows, err := s.GetReplicaX().DB.Query(queryString, args...)
|
||||
rows, err := s.GetReplica().DB.Query(queryString, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Roles")
|
||||
}
|
||||
@@ -235,7 +235,7 @@ func (s *SqlRoleStore) GetByNames(names []string) ([]*model.Role, error) {
|
||||
func (s *SqlRoleStore) Delete(roleId string) (*model.Role, error) {
|
||||
// Get the role.
|
||||
var role Role
|
||||
if err := s.GetReplicaX().Get(&role, "SELECT * from Roles WHERE Id = ?", roleId); err != nil {
|
||||
if err := s.GetReplica().Get(&role, "SELECT * from Roles WHERE Id = ?", roleId); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Role", roleId)
|
||||
}
|
||||
@@ -246,7 +246,7 @@ func (s *SqlRoleStore) Delete(roleId string) (*model.Role, error) {
|
||||
role.DeleteAt = time
|
||||
role.UpdateAt = time
|
||||
|
||||
res, err := s.GetMasterX().NamedExec(`UPDATE Roles
|
||||
res, err := s.GetMaster().NamedExec(`UPDATE Roles
|
||||
SET UpdateAt=:UpdateAt, DeleteAt=:DeleteAt, CreateAt=:CreateAt, Name=:Name, DisplayName=:DisplayName,
|
||||
Description=:Description, Permissions=:Permissions, SchemeManaged=:SchemeManaged, BuiltIn=:BuiltIn
|
||||
WHERE Id=:Id`, &role)
|
||||
@@ -268,7 +268,7 @@ func (s *SqlRoleStore) Delete(roleId string) (*model.Role, error) {
|
||||
}
|
||||
|
||||
func (s *SqlRoleStore) PermanentDeleteAll() error {
|
||||
if _, err := s.GetMasterX().Exec("DELETE FROM Roles"); err != nil {
|
||||
if _, err := s.GetMaster().Exec("DELETE FROM Roles"); err != nil {
|
||||
return errors.Wrap(err, "failed to delete Roles")
|
||||
}
|
||||
|
||||
@@ -353,7 +353,7 @@ func (s *SqlRoleStore) ChannelHigherScopedPermissions(roleNames []string) (map[s
|
||||
query := s.channelHigherScopedPermissionsQuery(roleNames)
|
||||
|
||||
rolesPermissions := []*channelRolesPermissions{}
|
||||
if err := s.GetReplicaX().Select(&rolesPermissions, query); err != nil {
|
||||
if err := s.GetReplica().Select(&rolesPermissions, query); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find RolePermissions")
|
||||
}
|
||||
|
||||
@@ -383,7 +383,7 @@ func (s *SqlRoleStore) AllChannelSchemeRoles() ([]*model.Role, error) {
|
||||
}
|
||||
|
||||
dbRoles := []*Role{}
|
||||
if err = s.GetReplicaX().Select(&dbRoles, queryString, args...); err != nil {
|
||||
if err = s.GetReplica().Select(&dbRoles, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Roles")
|
||||
}
|
||||
|
||||
@@ -420,7 +420,7 @@ func (s *SqlRoleStore) ChannelRolesUnderTeamRole(roleName string) ([]*model.Role
|
||||
}
|
||||
|
||||
dbRoles := []*Role{}
|
||||
if err = s.GetReplicaX().Select(&dbRoles, queryString, args...); err != nil {
|
||||
if err = s.GetReplica().Select(&dbRoles, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Roles")
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ func (s *SqlScheduledPostStore) CreateScheduledPost(scheduledPost *model.Schedul
|
||||
return nil, errors.Wrap(err, "SqlScheduledPostStore.CreateScheduledPost failed to generate SQL from query builder")
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(query, args...); err != nil {
|
||||
mlog.Error("SqlScheduledPostStore.CreateScheduledPost failed to insert scheduled post", mlog.Err(err))
|
||||
return nil, errors.Wrap(err, "SqlScheduledPostStore.CreateScheduledPost failed to insert scheduled post")
|
||||
}
|
||||
@@ -113,7 +113,7 @@ func (s *SqlScheduledPostStore) GetScheduledPostsForUser(userId, teamId string)
|
||||
|
||||
var scheduledPosts []*model.ScheduledPost
|
||||
|
||||
if err := s.GetReplicaX().SelectBuilder(&scheduledPosts, query); err != nil {
|
||||
if err := s.GetReplica().SelectBuilder(&scheduledPosts, query); err != nil {
|
||||
mlog.Error("SqlScheduledPostStore.GetScheduledPostsForUser: failed to fetch scheduled posts for user", mlog.String("user_id", userId), mlog.String("team_id", teamId), mlog.Err(err))
|
||||
|
||||
return nil, errors.Wrapf(err, "SqlScheduledPostStore.GetScheduledPostsForUser: failed to fetch scheduled posts for user, userId: %s, teamID: %s", userId, teamId)
|
||||
@@ -164,7 +164,7 @@ func (s *SqlScheduledPostStore) GetPendingScheduledPosts(beforeTime, afterTime i
|
||||
}
|
||||
|
||||
var scheduledPosts []*model.ScheduledPost
|
||||
if err := s.GetReplicaX().SelectBuilder(&scheduledPosts, query); err != nil {
|
||||
if err := s.GetReplica().SelectBuilder(&scheduledPosts, query); err != nil {
|
||||
mlog.Error(
|
||||
"SqlScheduledPostStore.GetPendingScheduledPosts: failed to fetch pending scheduled posts for processing",
|
||||
mlog.Int("before_time", beforeTime),
|
||||
@@ -198,7 +198,7 @@ func (s *SqlScheduledPostStore) PermanentlyDeleteScheduledPosts(scheduledPostIDs
|
||||
return errToReturn
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().Exec(sql, params...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(sql, params...); err != nil {
|
||||
errToReturn := errors.Wrapf(err, "PermanentlyDeleteScheduledPosts: failed to delete batch of scheduled posts from database")
|
||||
s.Logger().Error(errToReturn.Error())
|
||||
return errToReturn
|
||||
@@ -221,7 +221,7 @@ func (s *SqlScheduledPostStore) UpdatedScheduledPost(scheduledPost *model.Schedu
|
||||
return errors.Wrap(err, "SqlScheduledPostStore.UpdatedScheduledPost failed to generate SQL from bulk updating scheduled posts")
|
||||
}
|
||||
|
||||
_, err = s.GetMasterX().Exec(query, args...)
|
||||
_, err = s.GetMaster().Exec(query, args...)
|
||||
if err != nil {
|
||||
mlog.Error("SqlScheduledPostStore.UpdatedScheduledPost failed to update scheduled post", mlog.String("scheduled_post_id", scheduledPost.Id), mlog.Err(err))
|
||||
return errors.Wrap(err, "SqlScheduledPostStore.UpdatedScheduledPost failed to update scheduled post")
|
||||
@@ -254,7 +254,7 @@ func (s *SqlScheduledPostStore) Get(scheduledPostId string) (*model.ScheduledPos
|
||||
|
||||
scheduledPost := &model.ScheduledPost{}
|
||||
|
||||
if err := s.GetReplicaX().GetBuilder(scheduledPost, query); err != nil {
|
||||
if err := s.GetReplica().GetBuilder(scheduledPost, query); err != nil {
|
||||
mlog.Error("SqlScheduledPostStore.Get: failed to get single scheduled post by ID from database", mlog.String("scheduled_post_id", scheduledPostId), mlog.Err(err))
|
||||
|
||||
return nil, errors.Wrapf(err, "SqlScheduledPostStore.Get: failed to get single scheduled post by ID from database, scheduledPostId: %s", scheduledPostId)
|
||||
@@ -279,7 +279,7 @@ func (s *SqlScheduledPostStore) UpdateOldScheduledPosts(beforeTime int64) error
|
||||
return errors.Wrap(err, "SqlScheduledPostStore.UpdateOldScheduledPosts failed to generate SQL from updating old scheduled posts")
|
||||
}
|
||||
|
||||
_, err = s.GetMasterX().Exec(query, args...)
|
||||
_, err = s.GetMaster().Exec(query, args...)
|
||||
if err != nil {
|
||||
mlog.Error("SqlScheduledPostStore.UpdateOldScheduledPosts failed to update old scheduled posts", mlog.Err(err))
|
||||
return errors.Wrap(err, "SqlScheduledPostStore.UpdateOldScheduledPosts failed to update old scheduled posts")
|
||||
@@ -300,7 +300,7 @@ func (s *SqlScheduledPostStore) PermanentDeleteByUser(userId string) error {
|
||||
return errToReturn
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().Exec(sql, params...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(sql, params...); err != nil {
|
||||
errToReturn := errors.Wrapf(err, "PermanentDeleteByUser: failed to delete scheduled posts by user from database")
|
||||
s.Logger().Error(errToReturn.Error())
|
||||
return errToReturn
|
||||
|
||||
@@ -40,7 +40,7 @@ func newSqlSchemeStore(sqlStore *SqlStore) store.SchemeStore {
|
||||
|
||||
func (s *SqlSchemeStore) Save(scheme *model.Scheme) (_ *model.Scheme, err error) {
|
||||
if scheme.Id == "" {
|
||||
transaction, terr := s.GetMasterX().Beginx()
|
||||
transaction, terr := s.GetMaster().Beginx()
|
||||
if terr != nil {
|
||||
return nil, errors.Wrap(terr, "begin_transaction")
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func (s *SqlSchemeStore) Save(scheme *model.Scheme) (_ *model.Scheme, err error)
|
||||
|
||||
scheme.UpdateAt = model.GetMillis()
|
||||
|
||||
res, err := s.GetMasterX().NamedExec(`UPDATE Schemes
|
||||
res, err := s.GetMaster().NamedExec(`UPDATE Schemes
|
||||
SET UpdateAt=:UpdateAt, CreateAt=:CreateAt, DeleteAt=:DeleteAt, Name=:Name, DisplayName=:DisplayName, Description=:Description, Scope=:Scope,
|
||||
DefaultTeamAdminRole=:DefaultTeamAdminRole, DefaultTeamUserRole=:DefaultTeamUserRole, DefaultTeamGuestRole=:DefaultTeamGuestRole,
|
||||
DefaultChannelAdminRole=:DefaultChannelAdminRole, DefaultChannelUserRole=:DefaultChannelUserRole, DefaultChannelGuestRole=:DefaultChannelGuestRole,
|
||||
@@ -299,7 +299,7 @@ func filterModerated(permissions []string) []string {
|
||||
|
||||
func (s *SqlSchemeStore) Get(schemeId string) (*model.Scheme, error) {
|
||||
var scheme model.Scheme
|
||||
if err := s.GetReplicaX().Get(&scheme, "SELECT * from Schemes WHERE Id = ?", schemeId); err != nil {
|
||||
if err := s.GetReplica().Get(&scheme, "SELECT * from Schemes WHERE Id = ?", schemeId); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Scheme", fmt.Sprintf("schemeId=%s", schemeId))
|
||||
}
|
||||
@@ -312,7 +312,7 @@ func (s *SqlSchemeStore) Get(schemeId string) (*model.Scheme, error) {
|
||||
func (s *SqlSchemeStore) GetByName(schemeName string) (*model.Scheme, error) {
|
||||
var scheme model.Scheme
|
||||
|
||||
if err := s.GetReplicaX().Get(&scheme, "SELECT * from Schemes WHERE Name = ?", schemeName); err != nil {
|
||||
if err := s.GetReplica().Get(&scheme, "SELECT * from Schemes WHERE Name = ?", schemeName); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Scheme", fmt.Sprintf("schemeName=%s", schemeName))
|
||||
}
|
||||
@@ -325,7 +325,7 @@ func (s *SqlSchemeStore) GetByName(schemeName string) (*model.Scheme, error) {
|
||||
func (s *SqlSchemeStore) Delete(schemeId string) (*model.Scheme, error) {
|
||||
// Get the scheme
|
||||
scheme := model.Scheme{}
|
||||
if err := s.GetMasterX().Get(&scheme, `SELECT * from Schemes WHERE Id = ?`, schemeId); err != nil {
|
||||
if err := s.GetMaster().Get(&scheme, `SELECT * from Schemes WHERE Id = ?`, schemeId); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Scheme", fmt.Sprintf("schemeId=%s", schemeId))
|
||||
}
|
||||
@@ -334,13 +334,13 @@ func (s *SqlSchemeStore) Delete(schemeId string) (*model.Scheme, error) {
|
||||
|
||||
// Update any teams or channels using this scheme to the default scheme.
|
||||
if scheme.Scope == model.SchemeScopeTeam {
|
||||
if _, err := s.GetMasterX().Exec(`UPDATE Teams SET SchemeId = '' WHERE SchemeId = ?`, schemeId); err != nil {
|
||||
if _, err := s.GetMaster().Exec(`UPDATE Teams SET SchemeId = '' WHERE SchemeId = ?`, schemeId); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to update Teams with schemeId=%s", schemeId)
|
||||
}
|
||||
|
||||
s.Team().ClearCaches()
|
||||
} else if scheme.Scope == model.SchemeScopeChannel {
|
||||
if _, err := s.GetMasterX().Exec(`UPDATE Channels SET SchemeId = '' WHERE SchemeId = ?`, schemeId); err != nil {
|
||||
if _, err := s.GetMaster().Exec(`UPDATE Channels SET SchemeId = '' WHERE SchemeId = ?`, schemeId); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to update Channels with schemeId=%s", schemeId)
|
||||
}
|
||||
}
|
||||
@@ -374,7 +374,7 @@ func (s *SqlSchemeStore) Delete(schemeId string) (*model.Scheme, error) {
|
||||
return nil, errors.Wrap(err, "status_tosql")
|
||||
}
|
||||
|
||||
if _, err = s.GetMasterX().Exec(updateQuery, args...); err != nil {
|
||||
if _, err = s.GetMaster().Exec(updateQuery, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to update Roles with name in (%s)", roleNames)
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ func (s *SqlSchemeStore) Delete(schemeId string) (*model.Scheme, error) {
|
||||
scheme.UpdateAt = time
|
||||
scheme.DeleteAt = time
|
||||
|
||||
res, err := s.GetMasterX().NamedExec(`UPDATE Schemes
|
||||
res, err := s.GetMaster().NamedExec(`UPDATE Schemes
|
||||
SET UpdateAt=:UpdateAt, DeleteAt=:DeleteAt, CreateAt=:CreateAt, Name=:Name, DisplayName=:DisplayName, Description=:Description, Scope=:Scope,
|
||||
DefaultTeamAdminRole=:DefaultTeamAdminRole, DefaultTeamUserRole=:DefaultTeamUserRole, DefaultTeamGuestRole=:DefaultTeamGuestRole,
|
||||
DefaultChannelAdminRole=:DefaultChannelAdminRole, DefaultChannelUserRole=:DefaultChannelUserRole, DefaultChannelGuestRole=:DefaultChannelGuestRole
|
||||
@@ -423,7 +423,7 @@ func (s *SqlSchemeStore) GetAllPage(scope string, offset int, limit int) ([]*mod
|
||||
return nil, errors.Wrap(err, "status_tosql")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Select(&schemes, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&schemes, queryString, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get Schemes")
|
||||
}
|
||||
|
||||
@@ -431,7 +431,7 @@ func (s *SqlSchemeStore) GetAllPage(scope string, offset int, limit int) ([]*mod
|
||||
}
|
||||
|
||||
func (s *SqlSchemeStore) PermanentDeleteAll() error {
|
||||
if _, err := s.GetMasterX().Exec("DELETE from Schemes"); err != nil {
|
||||
if _, err := s.GetMaster().Exec("DELETE from Schemes"); err != nil {
|
||||
return errors.Wrap(err, "failed to delete Schemes")
|
||||
}
|
||||
|
||||
@@ -440,7 +440,7 @@ func (s *SqlSchemeStore) PermanentDeleteAll() error {
|
||||
|
||||
func (s *SqlSchemeStore) CountByScope(scope string) (int64, error) {
|
||||
var count int64
|
||||
err := s.GetReplicaX().Get(&count, `SELECT count(*) FROM Schemes WHERE Scope = ? AND DeleteAt = 0`, scope)
|
||||
err := s.GetReplica().Get(&count, `SELECT count(*) FROM Schemes WHERE Scope = ? AND DeleteAt = 0`, scope)
|
||||
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count Schemes by scope")
|
||||
@@ -462,7 +462,7 @@ func (s *SqlSchemeStore) CountWithoutPermission(schemeScope, permissionID string
|
||||
`, joinCol, schemeScope, permissionID)
|
||||
|
||||
var count int64
|
||||
err := s.GetReplicaX().Get(&count, query)
|
||||
err := s.GetReplica().Get(&count, query)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count Schemes without permission")
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ func (me SqlSessionStore) Save(c request.CTX, session *model.Session) (*model.Se
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "sessions_tosql")
|
||||
}
|
||||
if _, err = me.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err = me.GetMaster().Exec(query, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to save Session with id=%s", session.Id)
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ func (me SqlSessionStore) Get(c request.CTX, sessionIdOrToken string) (*model.Se
|
||||
func (me SqlSessionStore) GetSessions(c request.CTX, userId string) ([]*model.Session, error) {
|
||||
sessions := []*model.Session{}
|
||||
|
||||
if err := me.GetReplicaX().Select(&sessions, "SELECT * FROM Sessions WHERE UserId = ? ORDER BY LastActivityAt DESC", userId); err != nil {
|
||||
if err := me.GetReplica().Select(&sessions, "SELECT * FROM Sessions WHERE UserId = ? ORDER BY LastActivityAt DESC", userId); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Sessions with userId=%s", userId)
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ func (me SqlSessionStore) GetLRUSessions(c request.CTX, userId string, limit uin
|
||||
}
|
||||
|
||||
var sessions []*model.Session
|
||||
if err := me.GetReplicaX().Select(&sessions, query, args...); err != nil {
|
||||
if err := me.GetReplica().Select(&sessions, query, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Sessions with userId=%s", userId)
|
||||
}
|
||||
return sessions, nil
|
||||
@@ -163,7 +163,7 @@ func (me SqlSessionStore) GetSessionsWithActiveDeviceIds(userId string) ([]*mode
|
||||
|
||||
sessions := []*model.Session{}
|
||||
|
||||
if err := me.GetReplicaX().Select(&sessions, query, userId, model.GetMillis()); err != nil {
|
||||
if err := me.GetReplica().Select(&sessions, query, userId, model.GetMillis()); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Sessions with userId=%s", userId)
|
||||
}
|
||||
return sessions, nil
|
||||
@@ -194,7 +194,7 @@ func (me SqlSessionStore) GetMobileSessionMetadata() ([]*model.MobileSessionMeta
|
||||
}
|
||||
|
||||
versions := []*model.MobileSessionMetadata{}
|
||||
err = me.GetReplicaX().Select(&versions, query, args...)
|
||||
err = me.GetReplica().Select(&versions, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed get mobile session metadata")
|
||||
}
|
||||
@@ -223,7 +223,7 @@ func (me SqlSessionStore) GetSessionsExpired(thresholdMillis int64, mobileOnly b
|
||||
|
||||
sessions := []*model.Session{}
|
||||
|
||||
err = me.GetReplicaX().Select(&sessions, query, args...)
|
||||
err = me.GetReplica().Select(&sessions, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Sessions")
|
||||
}
|
||||
@@ -240,7 +240,7 @@ func (me SqlSessionStore) UpdateExpiredNotify(sessionId string, notified bool) e
|
||||
return errors.Wrap(err, "sessions_tosql")
|
||||
}
|
||||
|
||||
_, err = me.GetMasterX().Exec(query, args...)
|
||||
_, err = me.GetMaster().Exec(query, args...)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to update Session with id=%s", sessionId)
|
||||
}
|
||||
@@ -248,7 +248,7 @@ func (me SqlSessionStore) UpdateExpiredNotify(sessionId string, notified bool) e
|
||||
}
|
||||
|
||||
func (me SqlSessionStore) Remove(sessionIdOrToken string) error {
|
||||
_, err := me.GetMasterX().Exec("DELETE FROM Sessions WHERE Id = ? Or Token = ?", sessionIdOrToken, sessionIdOrToken)
|
||||
_, err := me.GetMaster().Exec("DELETE FROM Sessions WHERE Id = ? Or Token = ?", sessionIdOrToken, sessionIdOrToken)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete Session with sessionIdOrToken=%s", sessionIdOrToken)
|
||||
}
|
||||
@@ -256,7 +256,7 @@ func (me SqlSessionStore) Remove(sessionIdOrToken string) error {
|
||||
}
|
||||
|
||||
func (me SqlSessionStore) RemoveAllSessions() error {
|
||||
_, err := me.GetMasterX().Exec("DELETE FROM Sessions")
|
||||
_, err := me.GetMaster().Exec("DELETE FROM Sessions")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to delete all Sessions")
|
||||
}
|
||||
@@ -264,7 +264,7 @@ func (me SqlSessionStore) RemoveAllSessions() error {
|
||||
}
|
||||
|
||||
func (me SqlSessionStore) PermanentDeleteSessionsByUser(userId string) error {
|
||||
_, err := me.GetMasterX().Exec("DELETE FROM Sessions WHERE UserId = ?", userId)
|
||||
_, err := me.GetMaster().Exec("DELETE FROM Sessions WHERE UserId = ?", userId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete Session with userId=%s", userId)
|
||||
}
|
||||
@@ -273,7 +273,7 @@ func (me SqlSessionStore) PermanentDeleteSessionsByUser(userId string) error {
|
||||
}
|
||||
|
||||
func (me SqlSessionStore) UpdateExpiresAt(sessionId string, time int64) error {
|
||||
_, err := me.GetMasterX().Exec("UPDATE Sessions SET ExpiresAt = ?, ExpiredNotify = false WHERE Id = ?", time, sessionId)
|
||||
_, err := me.GetMaster().Exec("UPDATE Sessions SET ExpiresAt = ?, ExpiredNotify = false WHERE Id = ?", time, sessionId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to update Session with sessionId=%s", sessionId)
|
||||
}
|
||||
@@ -281,7 +281,7 @@ func (me SqlSessionStore) UpdateExpiresAt(sessionId string, time int64) error {
|
||||
}
|
||||
|
||||
func (me SqlSessionStore) UpdateLastActivityAt(sessionId string, time int64) error {
|
||||
_, err := me.GetMasterX().Exec("UPDATE Sessions SET LastActivityAt = ? WHERE Id = ?", time, sessionId)
|
||||
_, err := me.GetMaster().Exec("UPDATE Sessions SET LastActivityAt = ? WHERE Id = ?", time, sessionId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to update Session with id=%s", sessionId)
|
||||
}
|
||||
@@ -293,7 +293,7 @@ func (me SqlSessionStore) UpdateRoles(userId, roles string) (string, error) {
|
||||
return "", fmt.Errorf("given session roles length (%d) exceeds max storage limit (%d)", len(roles), model.UserRolesMaxLength)
|
||||
}
|
||||
|
||||
_, err := me.GetMasterX().Exec("UPDATE Sessions SET Roles = ? WHERE UserId = ?", roles, userId)
|
||||
_, err := me.GetMaster().Exec("UPDATE Sessions SET Roles = ? WHERE UserId = ?", roles, userId)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "failed to update Session with userId=%s and roles=%s", userId, roles)
|
||||
}
|
||||
@@ -303,7 +303,7 @@ func (me SqlSessionStore) UpdateRoles(userId, roles string) (string, error) {
|
||||
func (me SqlSessionStore) UpdateDeviceId(id string, deviceId string, expiresAt int64) (string, error) {
|
||||
query := "UPDATE Sessions SET DeviceId = ?, ExpiresAt = ?, ExpiredNotify = false WHERE Id = ?"
|
||||
|
||||
_, err := me.GetMasterX().Exec(query, deviceId, expiresAt, id)
|
||||
_, err := me.GetMaster().Exec(query, deviceId, expiresAt, id)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "failed to update Session with id=%s", id)
|
||||
}
|
||||
@@ -326,7 +326,7 @@ func (me SqlSessionStore) UpdateProps(session *model.Session) error {
|
||||
if err != nil {
|
||||
errors.Wrap(err, "sessions_tosql")
|
||||
}
|
||||
_, err = me.GetMasterX().Exec(query, args...)
|
||||
_, err = me.GetMaster().Exec(query, args...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to update Session")
|
||||
}
|
||||
@@ -341,7 +341,7 @@ func (me SqlSessionStore) AnalyticsSessionCount() (int64, error) {
|
||||
FROM
|
||||
Sessions
|
||||
WHERE ExpiresAt > ?`
|
||||
if err := me.GetReplicaX().Get(&count, query, model.GetMillis()); err != nil {
|
||||
if err := me.GetReplica().Get(&count, query, model.GetMillis()); err != nil {
|
||||
return int64(0), errors.Wrap(err, "failed to count Sessions")
|
||||
}
|
||||
return count, nil
|
||||
@@ -358,7 +358,7 @@ func (me SqlSessionStore) Cleanup(expiryTime int64, batchSize int64) error {
|
||||
var rowsAffected int64 = 1
|
||||
|
||||
for rowsAffected > 0 {
|
||||
sqlResult, err := me.GetMasterX().Exec(query, expiryTime, batchSize)
|
||||
sqlResult, err := me.GetMaster().Exec(query, expiryTime, batchSize)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable to delete sessions")
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func (s SqlSharedChannelStore) Save(sc *model.SharedChannel) (sh *model.SharedCh
|
||||
return nil, fmt.Errorf("invalid channel: %w", err)
|
||||
}
|
||||
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func (s SqlSharedChannelStore) Get(channelId string) (*model.SharedChannel, erro
|
||||
return nil, errors.Wrapf(err, "getsharedchannel_tosql")
|
||||
}
|
||||
|
||||
if err := s.GetMasterX().Get(&sc, squery, args...); err != nil {
|
||||
if err := s.GetMaster().Get(&sc, squery, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("SharedChannel", channelId)
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func (s SqlSharedChannelStore) HasChannel(channelID string) (bool, error) {
|
||||
}
|
||||
|
||||
var exists bool
|
||||
if err := s.GetReplicaX().Get(&exists, query, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&exists, query, args...); err != nil {
|
||||
return exists, errors.Wrapf(err, "failed to get shared channel for channel_id=%s", channelID)
|
||||
}
|
||||
return exists, nil
|
||||
@@ -170,7 +170,7 @@ func (s SqlSharedChannelStore) GetAll(offset, limit int, opts model.SharedChanne
|
||||
}
|
||||
|
||||
channels := []*model.SharedChannel{}
|
||||
err = s.GetReplicaX().Select(&channels, squery, args...)
|
||||
err = s.GetReplica().Select(&channels, squery, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get shared channels")
|
||||
}
|
||||
@@ -190,7 +190,7 @@ func (s SqlSharedChannelStore) GetAllCount(opts model.SharedChannelFilterOpts) (
|
||||
}
|
||||
|
||||
var count int64
|
||||
err = s.GetReplicaX().Get(&count, squery, args...)
|
||||
err = s.GetReplica().Get(&count, squery, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count channels")
|
||||
}
|
||||
@@ -255,7 +255,7 @@ func (s SqlSharedChannelStore) Update(sc *model.SharedChannel) (*model.SharedCha
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "updatesharedchannel_tosql")
|
||||
}
|
||||
res, err := s.GetMasterX().Exec(query, args...)
|
||||
res, err := s.GetMaster().Exec(query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to update shared channel with channelId=%s", sc.ChannelId)
|
||||
}
|
||||
@@ -274,7 +274,7 @@ func (s SqlSharedChannelStore) Update(sc *model.SharedChannel) (*model.SharedCha
|
||||
// Returns true if shared channel found and deleted, false if not
|
||||
// found.
|
||||
func (s SqlSharedChannelStore) Delete(channelId string) (ok bool, err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "DeleteSharedChannel: begin_transaction")
|
||||
}
|
||||
@@ -351,7 +351,7 @@ func (s SqlSharedChannelStore) SaveRemote(remote *model.SharedChannelRemote) (*m
|
||||
return nil, errors.Wrapf(err, "savesharedchannelremote_tosql")
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(query, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "save_shared_channel_remote: channel_id=%s, id=%s", remote.ChannelId, remote.Id)
|
||||
}
|
||||
return remote, nil
|
||||
@@ -384,7 +384,7 @@ func (s SqlSharedChannelStore) UpdateRemote(remote *model.SharedChannelRemote) (
|
||||
return nil, errors.Wrapf(err, "updatesharedchannelremote_tosql")
|
||||
}
|
||||
|
||||
res, err := s.GetMasterX().Exec(query, args...)
|
||||
res, err := s.GetMaster().Exec(query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to update shared channel remote with remoteId=%s", remote.Id)
|
||||
}
|
||||
@@ -434,7 +434,7 @@ func (s SqlSharedChannelStore) GetRemote(id string) (*model.SharedChannelRemote,
|
||||
return nil, errors.Wrapf(err, "get_shared_channel_remote_tosql")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Get(&remote, squery, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&remote, squery, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("SharedChannelRemote", id)
|
||||
}
|
||||
@@ -458,7 +458,7 @@ func (s SqlSharedChannelStore) GetRemoteByIds(channelId string, remoteId string)
|
||||
return nil, errors.Wrapf(err, "get_shared_channel_remote_by_ids_tosql")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Get(&remote, squery, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&remote, squery, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("SharedChannelRemote", fmt.Sprintf("channelId=%s, remoteId=%s", channelId, remoteId))
|
||||
}
|
||||
@@ -522,7 +522,7 @@ func (s SqlSharedChannelStore) GetRemotes(offset, limit int, opts model.SharedCh
|
||||
return nil, errors.Wrapf(err, "get_shared_channel_remotes_tosql")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Select(&remotes, squery, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&remotes, squery, args...); err != nil {
|
||||
if err != sql.ErrNoRows {
|
||||
return nil, errors.Wrapf(err, "failed to get shared channel remotes for channel_id=%s; remote_id=%s",
|
||||
opts.ChannelId, opts.RemoteId)
|
||||
@@ -548,7 +548,7 @@ func (s SqlSharedChannelStore) HasRemote(channelID string, remoteId string) (boo
|
||||
}
|
||||
|
||||
var hasRemote bool
|
||||
if err := s.GetReplicaX().Get(&hasRemote, query, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&hasRemote, query, args...); err != nil {
|
||||
return hasRemote, errors.Wrapf(err, "failed to get channel remotes for channel_id=%s", channelID)
|
||||
}
|
||||
return hasRemote, nil
|
||||
@@ -572,7 +572,7 @@ func (s SqlSharedChannelStore) GetRemoteForUser(remoteId string, userId string)
|
||||
}
|
||||
|
||||
var rc model.RemoteCluster
|
||||
if err := s.GetReplicaX().Get(&rc, query, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&rc, query, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("RemoteCluster", remoteId)
|
||||
}
|
||||
@@ -611,7 +611,7 @@ func (s SqlSharedChannelStore) UpdateRemoteCursor(id string, cursor model.GetPos
|
||||
return errors.Wrap(err, "update_shared_channel_remote_cursor_tosql")
|
||||
}
|
||||
|
||||
result, err := s.GetMasterX().Exec(squery, args...)
|
||||
result, err := s.GetMaster().Exec(squery, args...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to update cursor for SharedChannelRemote")
|
||||
}
|
||||
@@ -641,7 +641,7 @@ func (s SqlSharedChannelStore) DeleteRemote(id string) (bool, error) {
|
||||
return false, errors.Wrap(err, "delete_shared_channel_remote_tosql")
|
||||
}
|
||||
|
||||
result, err := s.GetMasterX().Exec(squery, args...)
|
||||
result, err := s.GetMaster().Exec(squery, args...)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "failed to delete SharedChannelRemote")
|
||||
}
|
||||
@@ -672,7 +672,7 @@ func (s SqlSharedChannelStore) GetRemotesStatus(channelId string) ([]*model.Shar
|
||||
return nil, errors.Wrapf(err, "get_shared_channel_remotes_status_tosql")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Select(&status, squery, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&status, squery, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("SharedChannelRemoteStatus", channelId)
|
||||
}
|
||||
@@ -709,7 +709,7 @@ func (s SqlSharedChannelStore) SaveUser(scUser *model.SharedChannelUser) (*model
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "savesharedchanneluser_tosql")
|
||||
}
|
||||
if _, err := s.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(query, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "save_shared_channel_user: user_id=%s, remote_id=%s", scUser.UserId, scUser.RemoteId)
|
||||
}
|
||||
return scUser, nil
|
||||
@@ -731,7 +731,7 @@ func (s SqlSharedChannelStore) GetSingleUser(userID string, channelID string, re
|
||||
return nil, errors.Wrapf(err, "getsharedchannelsingleuser_tosql")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Get(&scu, squery, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&scu, squery, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("SharedChannelUser", userID)
|
||||
}
|
||||
@@ -753,7 +753,7 @@ func (s SqlSharedChannelStore) GetUsersForUser(userID string) ([]*model.SharedCh
|
||||
}
|
||||
|
||||
users := []*model.SharedChannelUser{}
|
||||
if err := s.GetReplicaX().Select(&users, squery, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&users, squery, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return make([]*model.SharedChannelUser, 0), nil
|
||||
}
|
||||
@@ -795,7 +795,7 @@ func (s SqlSharedChannelStore) GetUsersForSync(filter model.GetUsersForSyncFilte
|
||||
}
|
||||
|
||||
users := []*model.User{}
|
||||
if err := s.GetReplicaX().Select(&users, sqlQuery, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&users, sqlQuery, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return make([]*model.User, 0), nil
|
||||
}
|
||||
@@ -829,7 +829,7 @@ func (s SqlSharedChannelStore) UpdateUserLastSyncAt(userID string, channelID str
|
||||
"scu.RemoteId": remoteID,
|
||||
})
|
||||
|
||||
_, err = s.GetMasterX().ExecBuilder(query)
|
||||
_, err = s.GetMaster().ExecBuilder(query)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to update LastSyncAt for SharedChannelUser with userId=%s, channelId=%s, remoteId=%s: %w",
|
||||
userID, channelID, remoteID, err)
|
||||
@@ -865,7 +865,7 @@ func (s SqlSharedChannelStore) SaveAttachment(attachment *model.SharedChannelAtt
|
||||
return nil, errors.Wrapf(err, "savesahredchannelattachment_tosql")
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(query, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "save_shared_channel_attachment: file_id=%s, remote_id=%s", attachment.FileId, attachment.RemoteId)
|
||||
}
|
||||
return attachment, nil
|
||||
@@ -893,7 +893,7 @@ func (s SqlSharedChannelStore) UpsertAttachment(attachment *model.SharedChannelA
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "upsertsharedchannelattachment_tosql")
|
||||
}
|
||||
if _, err := s.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(queryString, args...); err != nil {
|
||||
return "", errors.Wrap(err, "failed to upsert SharedChannelAttachments")
|
||||
}
|
||||
return attachment.Id, nil
|
||||
@@ -914,7 +914,7 @@ func (s SqlSharedChannelStore) GetAttachment(fileId string, remoteId string) (*m
|
||||
return nil, errors.Wrapf(err, "getsharedchannelattachment_tosql")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Get(&attachment, squery, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&attachment, squery, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("SharedChannelAttachment", fileId)
|
||||
}
|
||||
@@ -934,7 +934,7 @@ func (s SqlSharedChannelStore) UpdateAttachmentLastSyncAt(id string, syncTime in
|
||||
return errors.Wrap(err, "update_shared_channel_attachment_last_sync_at_tosql")
|
||||
}
|
||||
|
||||
result, err := s.GetMasterX().Exec(squery, args...)
|
||||
result, err := s.GetMaster().Exec(squery, args...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to update LastSyncAt for SharedChannelAttachment")
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ func NewStoreTestWrapper(orig *SqlStore) *StoreTestWrapper {
|
||||
return &StoreTestWrapper{orig}
|
||||
}
|
||||
|
||||
func (w *StoreTestWrapper) GetMasterX() storetest.SqlXExecutor {
|
||||
return w.orig.GetMasterX()
|
||||
func (w *StoreTestWrapper) GetMaster() storetest.SqlXExecutor {
|
||||
return w.orig.GetMaster()
|
||||
}
|
||||
|
||||
func (w *StoreTestWrapper) DriverName() string {
|
||||
|
||||
@@ -42,7 +42,7 @@ func TestSqlX(t *testing.T) {
|
||||
|
||||
defer store.Close()
|
||||
|
||||
tx, err := store.GetMasterX().Beginx()
|
||||
tx, err := store.GetMaster().Beginx()
|
||||
require.NoError(t, err)
|
||||
|
||||
var query string
|
||||
|
||||
@@ -42,7 +42,7 @@ func (s SqlStatusStore) SaveOrUpdate(st *model.Status) error {
|
||||
return errors.Wrap(err, "status_tosql")
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(queryString, args...); err != nil {
|
||||
return errors.Wrap(err, "failed to upsert Status")
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func (s SqlStatusStore) SaveOrUpdate(st *model.Status) error {
|
||||
func (s SqlStatusStore) Get(userId string) (*model.Status, error) {
|
||||
var status model.Status
|
||||
|
||||
if err := s.GetReplicaX().Get(&status, "SELECT * FROM Status WHERE UserId = ?", userId); err != nil {
|
||||
if err := s.GetReplica().Get(&status, "SELECT * FROM Status WHERE UserId = ?", userId); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Status", fmt.Sprintf("userId=%s", userId))
|
||||
}
|
||||
@@ -70,7 +70,7 @@ func (s SqlStatusStore) GetByIds(userIds []string) ([]*model.Status, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "status_tosql")
|
||||
}
|
||||
rows, err := s.GetReplicaX().DB.Query(queryString, args...)
|
||||
rows, err := s.GetReplica().DB.Query(queryString, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Statuses")
|
||||
}
|
||||
@@ -139,7 +139,7 @@ func (s SqlStatusStore) updateExpiredStatuses(t *sqlxTxWrapper) ([]*model.Status
|
||||
|
||||
func (s SqlStatusStore) UpdateExpiredDNDStatuses() (_ []*model.Status, err error) {
|
||||
if s.DriverName() == model.DatabaseDriverMysql {
|
||||
transaction, terr := s.GetMasterX().Beginx()
|
||||
transaction, terr := s.GetMaster().Beginx()
|
||||
if terr != nil {
|
||||
return nil, errors.Wrap(terr, "UpdateExpiredDNDStatuses: begin_transaction")
|
||||
}
|
||||
@@ -182,7 +182,7 @@ func (s SqlStatusStore) UpdateExpiredDNDStatuses() (_ []*model.Status, err error
|
||||
return nil, errors.Wrap(err, "status_tosql")
|
||||
}
|
||||
|
||||
rows, err := s.GetMasterX().Query(queryString, args...)
|
||||
rows, err := s.GetMaster().Query(queryString, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Statuses")
|
||||
}
|
||||
@@ -204,7 +204,7 @@ func (s SqlStatusStore) UpdateExpiredDNDStatuses() (_ []*model.Status, err error
|
||||
}
|
||||
|
||||
func (s SqlStatusStore) ResetAll() error {
|
||||
if _, err := s.GetMasterX().Exec(fmt.Sprintf("UPDATE Status SET Status = ? WHERE %s = false", quoteColumnName(s.DriverName(), "Manual")), model.StatusOffline); err != nil {
|
||||
if _, err := s.GetMaster().Exec(fmt.Sprintf("UPDATE Status SET Status = ? WHERE %s = false", quoteColumnName(s.DriverName(), "Manual")), model.StatusOffline); err != nil {
|
||||
return errors.Wrap(err, "failed to update Statuses")
|
||||
}
|
||||
return nil
|
||||
@@ -213,7 +213,7 @@ func (s SqlStatusStore) ResetAll() error {
|
||||
func (s SqlStatusStore) GetTotalActiveUsersCount() (int64, error) {
|
||||
time := model.GetMillis() - (1000 * 60 * 60 * 24)
|
||||
var count int64
|
||||
err := s.GetReplicaX().Get(&count, "SELECT COUNT(UserId) FROM Status WHERE LastActivityAt > ?", time)
|
||||
err := s.GetReplica().Get(&count, "SELECT COUNT(UserId) FROM Status WHERE LastActivityAt > ?", time)
|
||||
if err != nil {
|
||||
return count, errors.Wrap(err, "failed to count active users")
|
||||
}
|
||||
@@ -221,7 +221,7 @@ func (s SqlStatusStore) GetTotalActiveUsersCount() (int64, error) {
|
||||
}
|
||||
|
||||
func (s SqlStatusStore) UpdateLastActivityAt(userId string, lastActivityAt int64) error {
|
||||
if _, err := s.GetMasterX().Exec("UPDATE Status SET LastActivityAt = ? WHERE UserId = ?", lastActivityAt, userId); err != nil {
|
||||
if _, err := s.GetMaster().Exec("UPDATE Status SET LastActivityAt = ? WHERE UserId = ?", lastActivityAt, userId); err != nil {
|
||||
return errors.Wrapf(err, "failed to update last activity for userId=%s", userId)
|
||||
}
|
||||
|
||||
|
||||
@@ -374,7 +374,7 @@ func (ss *SqlStore) computeDefaultTextSearchConfig() (string, error) {
|
||||
}
|
||||
|
||||
var defaultTextSearchConfig string
|
||||
err := ss.GetMasterX().Get(&defaultTextSearchConfig, `SHOW default_text_search_config`)
|
||||
err := ss.GetMaster().Get(&defaultTextSearchConfig, `SHOW default_text_search_config`)
|
||||
return defaultTextSearchConfig, err
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ func (ss *SqlStore) GetDbVersion(numerical bool) (string, error) {
|
||||
}
|
||||
|
||||
var version string
|
||||
err := ss.GetReplicaX().Get(&version, sqlVersion)
|
||||
err := ss.GetReplica().Get(&version, sqlVersion)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -408,7 +408,7 @@ func (ss *SqlStore) GetDbVersion(numerical bool) (string, error) {
|
||||
return version, nil
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetMasterX() *sqlxDBWrapper {
|
||||
func (ss *SqlStore) GetMaster() *sqlxDBWrapper {
|
||||
return ss.masterX
|
||||
}
|
||||
|
||||
@@ -422,16 +422,16 @@ func (ss *SqlStore) SetMasterX(db *sql.DB) {
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetInternalMasterDB() *sql.DB {
|
||||
return ss.GetMasterX().DB.DB
|
||||
return ss.GetMaster().DB.DB
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetSearchReplicaX() *sqlxDBWrapper {
|
||||
if !ss.hasLicense() {
|
||||
return ss.GetMasterX()
|
||||
return ss.GetMaster()
|
||||
}
|
||||
|
||||
if len(ss.settings.DataSourceSearchReplicas) == 0 {
|
||||
return ss.GetReplicaX()
|
||||
return ss.GetReplica()
|
||||
}
|
||||
|
||||
for i := 0; i < len(ss.searchReplicaXs); i++ {
|
||||
@@ -442,12 +442,12 @@ func (ss *SqlStore) GetSearchReplicaX() *sqlxDBWrapper {
|
||||
}
|
||||
|
||||
// If all search replicas are down, then go with replica.
|
||||
return ss.GetReplicaX()
|
||||
return ss.GetReplica()
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetReplicaX() *sqlxDBWrapper {
|
||||
func (ss *SqlStore) GetReplica() *sqlxDBWrapper {
|
||||
if len(ss.settings.DataSourceReplicas) == 0 || ss.lockedToMaster || !ss.hasLicense() {
|
||||
return ss.GetMasterX()
|
||||
return ss.GetMaster()
|
||||
}
|
||||
|
||||
for i := 0; i < len(ss.ReplicaXs); i++ {
|
||||
@@ -458,7 +458,7 @@ func (ss *SqlStore) GetReplicaX() *sqlxDBWrapper {
|
||||
}
|
||||
|
||||
// If all replicas are down, then go with master.
|
||||
return ss.GetMasterX()
|
||||
return ss.GetMaster()
|
||||
}
|
||||
|
||||
func (ss *SqlStore) monitorReplicas() {
|
||||
@@ -512,7 +512,7 @@ func (ss *SqlStore) setDB(replica *atomic.Pointer[sqlxDBWrapper], handle *dbsql.
|
||||
|
||||
func (ss *SqlStore) GetInternalReplicaDB() *sql.DB {
|
||||
if len(ss.settings.DataSourceReplicas) == 0 || ss.lockedToMaster || !ss.hasLicense() {
|
||||
return ss.GetMasterX().DB.DB
|
||||
return ss.GetMaster().DB.DB
|
||||
}
|
||||
|
||||
rrNum := atomic.AddInt64(&ss.rrCounter, 1) % int64(len(ss.ReplicaXs))
|
||||
@@ -520,7 +520,7 @@ func (ss *SqlStore) GetInternalReplicaDB() *sql.DB {
|
||||
}
|
||||
|
||||
func (ss *SqlStore) TotalMasterDbConnections() int {
|
||||
return ss.GetMasterX().Stats().OpenConnections
|
||||
return ss.GetMaster().Stats().OpenConnections
|
||||
}
|
||||
|
||||
// ReplicaLagAbs queries all the replica databases to get the absolute replica lag value
|
||||
@@ -609,7 +609,7 @@ func (ss *SqlStore) MarkSystemRanUnitTests() {
|
||||
func (ss *SqlStore) DoesTableExist(tableName string) bool {
|
||||
if ss.DriverName() == model.DatabaseDriverPostgres {
|
||||
var count int64
|
||||
err := ss.GetMasterX().Get(&count,
|
||||
err := ss.GetMaster().Get(&count,
|
||||
`SELECT count(relname) FROM pg_class WHERE relname=$1`,
|
||||
strings.ToLower(tableName),
|
||||
)
|
||||
@@ -621,7 +621,7 @@ func (ss *SqlStore) DoesTableExist(tableName string) bool {
|
||||
return count > 0
|
||||
} else if ss.DriverName() == model.DatabaseDriverMysql {
|
||||
var count int64
|
||||
err := ss.GetMasterX().Get(&count,
|
||||
err := ss.GetMaster().Get(&count,
|
||||
`SELECT
|
||||
COUNT(0) AS table_exists
|
||||
FROM
|
||||
@@ -646,7 +646,7 @@ func (ss *SqlStore) DoesTableExist(tableName string) bool {
|
||||
func (ss *SqlStore) DoesColumnExist(tableName string, columnName string) bool {
|
||||
if ss.DriverName() == model.DatabaseDriverPostgres {
|
||||
var count int64
|
||||
err := ss.GetMasterX().Get(&count,
|
||||
err := ss.GetMaster().Get(&count,
|
||||
`SELECT COUNT(0)
|
||||
FROM pg_attribute
|
||||
WHERE attrelid = $1::regclass
|
||||
@@ -667,7 +667,7 @@ func (ss *SqlStore) DoesColumnExist(tableName string, columnName string) bool {
|
||||
return count > 0
|
||||
} else if ss.DriverName() == model.DatabaseDriverMysql {
|
||||
var count int64
|
||||
err := ss.GetMasterX().Get(&count,
|
||||
err := ss.GetMaster().Get(&count,
|
||||
`SELECT
|
||||
COUNT(0) AS column_exists
|
||||
FROM
|
||||
@@ -693,7 +693,7 @@ func (ss *SqlStore) DoesColumnExist(tableName string, columnName string) bool {
|
||||
func (ss *SqlStore) DoesTriggerExist(triggerName string) bool {
|
||||
if ss.DriverName() == model.DatabaseDriverPostgres {
|
||||
var count int64
|
||||
err := ss.GetMasterX().Get(&count, `
|
||||
err := ss.GetMaster().Get(&count, `
|
||||
SELECT
|
||||
COUNT(0)
|
||||
FROM
|
||||
@@ -709,7 +709,7 @@ func (ss *SqlStore) DoesTriggerExist(triggerName string) bool {
|
||||
return count > 0
|
||||
} else if ss.DriverName() == model.DatabaseDriverMysql {
|
||||
var count int64
|
||||
err := ss.GetMasterX().Get(&count, `
|
||||
err := ss.GetMaster().Get(&count, `
|
||||
SELECT
|
||||
COUNT(0)
|
||||
FROM
|
||||
@@ -735,14 +735,14 @@ func (ss *SqlStore) CreateColumnIfNotExists(tableName string, columnName string,
|
||||
}
|
||||
|
||||
if ss.DriverName() == model.DatabaseDriverPostgres {
|
||||
_, err := ss.GetMasterX().ExecNoTimeout("ALTER TABLE " + tableName + " ADD " + columnName + " " + postgresColType + " DEFAULT '" + defaultValue + "'")
|
||||
_, err := ss.GetMaster().ExecNoTimeout("ALTER TABLE " + tableName + " ADD " + columnName + " " + postgresColType + " DEFAULT '" + defaultValue + "'")
|
||||
if err != nil {
|
||||
mlog.Fatal("Failed to create column", mlog.Err(err))
|
||||
}
|
||||
|
||||
return true
|
||||
} else if ss.DriverName() == model.DatabaseDriverMysql {
|
||||
_, err := ss.GetMasterX().ExecNoTimeout("ALTER TABLE " + tableName + " ADD " + columnName + " " + mySqlColType + " DEFAULT '" + defaultValue + "'")
|
||||
_, err := ss.GetMaster().ExecNoTimeout("ALTER TABLE " + tableName + " ADD " + columnName + " " + mySqlColType + " DEFAULT '" + defaultValue + "'")
|
||||
if err != nil {
|
||||
mlog.Fatal("Failed to create column", mlog.Err(err))
|
||||
}
|
||||
@@ -758,7 +758,7 @@ func (ss *SqlStore) RemoveTableIfExists(tableName string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
_, err := ss.GetMasterX().ExecNoTimeout("DROP TABLE " + tableName)
|
||||
_, err := ss.GetMaster().ExecNoTimeout("DROP TABLE " + tableName)
|
||||
if err != nil {
|
||||
mlog.Fatal("Failed to drop table", mlog.Err(err))
|
||||
}
|
||||
@@ -1195,7 +1195,7 @@ func (ss *SqlStore) ensureDatabaseCollation() error {
|
||||
Variable_name string
|
||||
Value string
|
||||
}
|
||||
if err := ss.GetMasterX().Get(&connCollation, "SHOW VARIABLES LIKE 'collation_connection'"); err != nil {
|
||||
if err := ss.GetMaster().Get(&connCollation, "SHOW VARIABLES LIKE 'collation_connection'"); err != nil {
|
||||
return errors.Wrap(err, "unable to select variables")
|
||||
}
|
||||
|
||||
@@ -1205,14 +1205,14 @@ func (ss *SqlStore) ensureDatabaseCollation() error {
|
||||
// we check if table exists because this code runs before the migrations applied
|
||||
// which means if there is a fresh db, we may fail on selecting the table_collation
|
||||
var exists int
|
||||
if err := ss.GetMasterX().Get(&exists, "SELECT count(*) FROM information_schema.tables WHERE table_schema = DATABASE() AND LOWER(table_name) = ?", tableName); err != nil {
|
||||
if err := ss.GetMaster().Get(&exists, "SELECT count(*) FROM information_schema.tables WHERE table_schema = DATABASE() AND LOWER(table_name) = ?", tableName); err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("unable to check if table exists for collation check: %q", tableName))
|
||||
} else if exists == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
var tableCollation string
|
||||
if err := ss.GetMasterX().Get(&tableCollation, "SELECT table_collation FROM information_schema.tables WHERE table_schema = DATABASE() AND LOWER(table_name) = ?", tableName); err != nil {
|
||||
if err := ss.GetMaster().Get(&tableCollation, "SELECT table_collation FROM information_schema.tables WHERE table_schema = DATABASE() AND LOWER(table_name) = ?", tableName); err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("unable to get table collation: %q", tableName))
|
||||
}
|
||||
|
||||
@@ -1283,7 +1283,7 @@ func (ss *SqlStore) GetLocalSchemaVersion() (int, error) {
|
||||
|
||||
func (ss *SqlStore) GetDBSchemaVersion() (int, error) {
|
||||
var version int
|
||||
if err := ss.GetMasterX().Get(&version, "SELECT Version FROM db_migrations ORDER BY Version DESC LIMIT 1"); err != nil {
|
||||
if err := ss.GetMaster().Get(&version, "SELECT Version FROM db_migrations ORDER BY Version DESC LIMIT 1"); err != nil {
|
||||
return 0, errors.Wrap(err, "unable to select from db_migrations")
|
||||
}
|
||||
return version, nil
|
||||
@@ -1291,7 +1291,7 @@ func (ss *SqlStore) GetDBSchemaVersion() (int, error) {
|
||||
|
||||
func (ss *SqlStore) GetAppliedMigrations() ([]model.AppliedMigration, error) {
|
||||
migrations := []model.AppliedMigration{}
|
||||
if err := ss.GetMasterX().Select(&migrations, "SELECT Version, Name FROM db_migrations ORDER BY Version DESC"); err != nil {
|
||||
if err := ss.GetMaster().Select(&migrations, "SELECT Version, Name FROM db_migrations ORDER BY Version DESC"); err != nil {
|
||||
return nil, errors.Wrap(err, "unable to select from db_migrations")
|
||||
}
|
||||
|
||||
@@ -1303,7 +1303,7 @@ func (ss *SqlStore) determineMaxColumnSize(tableName, columnName string) (int, e
|
||||
ss.getQueryPlaceholder()
|
||||
|
||||
if ss.DriverName() == model.DatabaseDriverPostgres {
|
||||
if err := ss.GetReplicaX().Get(&columnSizeBytes, `
|
||||
if err := ss.GetReplica().Get(&columnSizeBytes, `
|
||||
SELECT
|
||||
COALESCE(character_maximum_length, 0)
|
||||
FROM
|
||||
@@ -1316,7 +1316,7 @@ func (ss *SqlStore) determineMaxColumnSize(tableName, columnName string) (int, e
|
||||
return 0, err
|
||||
}
|
||||
} else if ss.DriverName() == model.DatabaseDriverMysql {
|
||||
if err := ss.GetReplicaX().Get(&columnSizeBytes, `
|
||||
if err := ss.GetReplica().Get(&columnSizeBytes, `
|
||||
SELECT
|
||||
COALESCE(CHARACTER_MAXIMUM_LENGTH, 0)
|
||||
FROM
|
||||
|
||||
@@ -207,7 +207,7 @@ func TestStoreLicenseRace(t *testing.T) {
|
||||
}()
|
||||
|
||||
go func() {
|
||||
store.GetReplicaX()
|
||||
store.GetReplica()
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
@@ -305,7 +305,7 @@ func TestGetReplica(t *testing.T) {
|
||||
|
||||
replicas := make(map[*sqlxDBWrapper]bool)
|
||||
for i := 0; i < 5; i++ {
|
||||
replicas[store.GetReplicaX()] = true
|
||||
replicas[store.GetReplica()] = true
|
||||
}
|
||||
|
||||
searchReplicas := make(map[*sqlxDBWrapper]bool)
|
||||
@@ -318,12 +318,12 @@ func TestGetReplica(t *testing.T) {
|
||||
assert.Len(t, replicas, testCase.DataSourceReplicaNum)
|
||||
|
||||
for replica := range replicas {
|
||||
assert.NotSame(t, store.GetMasterX(), replica)
|
||||
assert.NotSame(t, store.GetMaster(), replica)
|
||||
}
|
||||
} else if assert.Len(t, replicas, 1) {
|
||||
// Otherwise ensure the replicas contains only the master.
|
||||
for replica := range replicas {
|
||||
assert.Same(t, store.GetMasterX(), replica)
|
||||
assert.Same(t, store.GetMaster(), replica)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,7 +332,7 @@ func TestGetReplica(t *testing.T) {
|
||||
assert.Len(t, searchReplicas, testCase.DataSourceSearchReplicaNum)
|
||||
|
||||
for searchReplica := range searchReplicas {
|
||||
assert.NotSame(t, store.GetMasterX(), searchReplica)
|
||||
assert.NotSame(t, store.GetMaster(), searchReplica)
|
||||
for replica := range replicas {
|
||||
assert.NotSame(t, searchReplica, replica)
|
||||
}
|
||||
@@ -345,7 +345,7 @@ func TestGetReplica(t *testing.T) {
|
||||
} else if testCase.DataSourceReplicaNum == 0 && assert.Len(t, searchReplicas, 1) {
|
||||
// Otherwise ensure the search replicas contains the master.
|
||||
for searchReplica := range searchReplicas {
|
||||
assert.Same(t, store.GetMasterX(), searchReplica)
|
||||
assert.Same(t, store.GetMaster(), searchReplica)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -376,7 +376,7 @@ func TestGetReplica(t *testing.T) {
|
||||
|
||||
replicas := make(map[*sqlxDBWrapper]bool)
|
||||
for i := 0; i < 5; i++ {
|
||||
replicas[store.GetReplicaX()] = true
|
||||
replicas[store.GetReplica()] = true
|
||||
}
|
||||
|
||||
searchReplicas := make(map[*sqlxDBWrapper]bool)
|
||||
@@ -389,12 +389,12 @@ func TestGetReplica(t *testing.T) {
|
||||
assert.Len(t, replicas, 1)
|
||||
|
||||
for replica := range replicas {
|
||||
assert.Same(t, store.GetMasterX(), replica)
|
||||
assert.Same(t, store.GetMaster(), replica)
|
||||
}
|
||||
} else if assert.Len(t, replicas, 1) {
|
||||
// Otherwise ensure the replicas contains only the master.
|
||||
for replica := range replicas {
|
||||
assert.Same(t, store.GetMasterX(), replica)
|
||||
assert.Same(t, store.GetMaster(), replica)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -403,7 +403,7 @@ func TestGetReplica(t *testing.T) {
|
||||
assert.Len(t, searchReplicas, 1)
|
||||
|
||||
for searchReplica := range searchReplicas {
|
||||
assert.Same(t, store.GetMasterX(), searchReplica)
|
||||
assert.Same(t, store.GetMaster(), searchReplica)
|
||||
}
|
||||
} else if testCase.DataSourceReplicaNum > 0 {
|
||||
assert.Equal(t, len(replicas), len(searchReplicas))
|
||||
@@ -413,7 +413,7 @@ func TestGetReplica(t *testing.T) {
|
||||
} else if assert.Len(t, searchReplicas, 1) {
|
||||
// Otherwise ensure the search replicas contains the master.
|
||||
for searchReplica := range searchReplicas {
|
||||
assert.Same(t, store.GetMasterX(), searchReplica)
|
||||
assert.Same(t, store.GetMaster(), searchReplica)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -831,7 +831,7 @@ func TestExecNoTimeout(t *testing.T) {
|
||||
} else if sqlStore.DriverName() == model.DatabaseDriverPostgres {
|
||||
query = `SELECT pg_sleep(2);`
|
||||
}
|
||||
_, err := sqlStore.GetMasterX().ExecNoTimeout(query)
|
||||
_, err := sqlStore.GetMaster().ExecNoTimeout(query)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
@@ -858,7 +858,7 @@ func TestMySQLReadTimeout(t *testing.T) {
|
||||
require.NoError(t, store.initConnection())
|
||||
defer store.Close()
|
||||
|
||||
_, err = store.GetMasterX().ExecNoTimeout(`SELECT SLEEP(3)`)
|
||||
_, err = store.GetMaster().ExecNoTimeout(`SELECT SLEEP(3)`)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ func newSqlSystemStore(sqlStore *SqlStore) store.SystemStore {
|
||||
|
||||
func (s SqlSystemStore) Save(system *model.System) error {
|
||||
query := "INSERT INTO Systems (Name, Value) VALUES (:Name, :Value)"
|
||||
if _, err := s.GetMasterX().NamedExec(query, system); err != nil {
|
||||
if _, err := s.GetMaster().NamedExec(query, system); err != nil {
|
||||
return errors.Wrapf(err, "failed to save system property with name=%s", system.Name)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func (s SqlSystemStore) SaveOrUpdate(system *model.System) error {
|
||||
return errors.Wrap(err, "system_tosql")
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(queryString, args...); err != nil {
|
||||
return errors.Wrap(err, "failed to upsert system property")
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func (s SqlSystemStore) SaveOrUpdate(system *model.System) error {
|
||||
|
||||
func (s SqlSystemStore) Update(system *model.System) error {
|
||||
query := "UPDATE Systems SET Value=:Value WHERE Name=:Name"
|
||||
if _, err := s.GetMasterX().NamedExec(query, system); err != nil {
|
||||
if _, err := s.GetMaster().NamedExec(query, system); err != nil {
|
||||
return errors.Wrapf(err, "failed to update system property with name=%s", system.Name)
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ func (s SqlSystemStore) Get() (model.StringMap, error) {
|
||||
systems := []model.System{}
|
||||
props := make(model.StringMap)
|
||||
|
||||
if err := s.GetReplicaX().Select(&systems, "SELECT * FROM Systems"); err != nil {
|
||||
if err := s.GetReplica().Select(&systems, "SELECT * FROM Systems"); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get System list")
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ func (s SqlSystemStore) Get() (model.StringMap, error) {
|
||||
|
||||
func (s SqlSystemStore) GetByName(name string) (*model.System, error) {
|
||||
var system model.System
|
||||
if err := s.GetMasterX().Get(&system, "SELECT * FROM Systems WHERE Name = ?", name); err != nil {
|
||||
if err := s.GetMaster().Get(&system, "SELECT * FROM Systems WHERE Name = ?", name); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("System", fmt.Sprintf("name=%s", system.Name))
|
||||
}
|
||||
@@ -93,7 +93,7 @@ func (s SqlSystemStore) GetByName(name string) (*model.System, error) {
|
||||
|
||||
func (s SqlSystemStore) PermanentDeleteByName(name string) (*model.System, error) {
|
||||
var system model.System
|
||||
if _, err := s.GetMasterX().Exec("DELETE FROM Systems WHERE Name = ?", name); err != nil {
|
||||
if _, err := s.GetMaster().Exec("DELETE FROM Systems WHERE Name = ?", name); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to permanent delete system property with name=%s", system.Name)
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ func (s SqlSystemStore) PermanentDeleteByName(name string) (*model.System, error
|
||||
// InsertIfExists inserts a given system value if it does not already exist. If a value
|
||||
// already exists, it returns the old one, else returns the new one.
|
||||
func (s SqlSystemStore) InsertIfExists(system *model.System) (_ *model.System, err error) {
|
||||
tx, err := s.GetMasterX().BeginXWithIsolation(&sql.TxOptions{
|
||||
tx, err := s.GetMaster().BeginXWithIsolation(&sql.TxOptions{
|
||||
Isolation: sql.LevelSerializable,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -231,7 +231,7 @@ func (s SqlTeamStore) Save(team *model.Team) (*model.Team, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().NamedExec(`INSERT INTO Teams
|
||||
if _, err := s.GetMaster().NamedExec(`INSERT INTO Teams
|
||||
(Id, CreateAt, UpdateAt, DeleteAt, DisplayName, Name, Description, Email, Type, CompanyName, AllowedDomains,
|
||||
InviteId, AllowOpenInvite, LastTeamIconUpdate, SchemeId, GroupConstrained, CloudLimitsArchived)
|
||||
VALUES
|
||||
@@ -256,7 +256,7 @@ func (s SqlTeamStore) Update(team *model.Team) (*model.Team, error) {
|
||||
}
|
||||
|
||||
oldTeam := model.Team{}
|
||||
err := s.GetMasterX().Get(&oldTeam, `SELECT * FROM Teams WHERE Id=?`, team.Id)
|
||||
err := s.GetMaster().Get(&oldTeam, `SELECT * FROM Teams WHERE Id=?`, team.Id)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get Team with id=%s", team.Id)
|
||||
}
|
||||
@@ -268,7 +268,7 @@ func (s SqlTeamStore) Update(team *model.Team) (*model.Team, error) {
|
||||
team.CreateAt = oldTeam.CreateAt
|
||||
team.UpdateAt = model.GetMillis()
|
||||
|
||||
res, err := s.GetMasterX().NamedExec(`UPDATE Teams
|
||||
res, err := s.GetMaster().NamedExec(`UPDATE Teams
|
||||
SET CreateAt=:CreateAt, UpdateAt=:UpdateAt, DeleteAt=:DeleteAt, DisplayName=:DisplayName, Name=:Name,
|
||||
Description=:Description, Email=:Email, Type=:Type, CompanyName=:CompanyName, AllowedDomains=:AllowedDomains,
|
||||
InviteId=:InviteId, AllowOpenInvite=:AllowOpenInvite, LastTeamIconUpdate=:LastTeamIconUpdate,
|
||||
@@ -294,7 +294,7 @@ func (s SqlTeamStore) Update(team *model.Team) (*model.Team, error) {
|
||||
// http.StatusNotFound in the StatusCode field.
|
||||
func (s SqlTeamStore) Get(id string) (*model.Team, error) {
|
||||
team := model.Team{}
|
||||
if err := s.GetReplicaX().Get(&team, `SELECT * FROM Teams WHERE Id=?`, id); err != nil {
|
||||
if err := s.GetReplica().Get(&team, `SELECT * FROM Teams WHERE Id=?`, id); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Team", id)
|
||||
}
|
||||
@@ -318,7 +318,7 @@ func (s SqlTeamStore) GetMany(ids []string) ([]*model.Team, error) {
|
||||
}
|
||||
|
||||
teams := []*model.Team{}
|
||||
err = s.GetReplicaX().Select(&teams, sql, args...)
|
||||
err = s.GetReplica().Select(&teams, sql, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get teams with ids %v", ids)
|
||||
}
|
||||
@@ -340,7 +340,7 @@ func (s SqlTeamStore) GetByInviteId(inviteId string) (*model.Team, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
err = s.GetReplicaX().Get(&team, query, args...)
|
||||
err = s.GetReplica().Get(&team, query, args...)
|
||||
if err != nil {
|
||||
return nil, store.NewErrNotFound("Team", fmt.Sprintf("inviteId=%s", inviteId))
|
||||
}
|
||||
@@ -353,7 +353,7 @@ func (s SqlTeamStore) GetByInviteId(inviteId string) (*model.Team, error) {
|
||||
|
||||
func (s SqlTeamStore) GetByEmptyInviteID() ([]*model.Team, error) {
|
||||
teams := []*model.Team{}
|
||||
err := s.GetReplicaX().Select(&teams, "SELECT * FROM Teams WHERE InviteId = ''")
|
||||
err := s.GetReplica().Select(&teams, "SELECT * FROM Teams WHERE InviteId = ''")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Teams with empty InviteID")
|
||||
}
|
||||
@@ -369,7 +369,7 @@ func (s SqlTeamStore) GetByName(name string) (*model.Team, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
err = s.GetReplicaX().Get(&team, query, args...)
|
||||
err = s.GetReplica().Get(&team, query, args...)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Team", fmt.Sprintf("name=%s", name))
|
||||
@@ -389,7 +389,7 @@ func (s SqlTeamStore) GetByNames(names []string) ([]*model.Team, error) {
|
||||
}
|
||||
|
||||
teams := []*model.Team{}
|
||||
err = s.GetReplicaX().Select(&teams, query, args...)
|
||||
err = s.GetReplica().Select(&teams, query, args...)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Team", fmt.Sprintf("nameIn=%v", names))
|
||||
@@ -511,7 +511,7 @@ func (s SqlTeamStore) SearchAll(opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
return nil, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
|
||||
if err = s.GetReplicaX().Select(&teams, queryString, args...); err != nil {
|
||||
if err = s.GetReplica().Select(&teams, queryString, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Teams with term=%s", opts.Term)
|
||||
}
|
||||
|
||||
@@ -527,7 +527,7 @@ func (s SqlTeamStore) SearchAllPaged(opts *model.TeamSearch) ([]*model.Team, int
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
if err = s.GetReplicaX().Select(&teams, queryString, args...); err != nil {
|
||||
if err = s.GetReplica().Select(&teams, queryString, args...); err != nil {
|
||||
return nil, 0, errors.Wrapf(err, "failed to find Teams with term=%s", opts.Term)
|
||||
}
|
||||
|
||||
@@ -536,7 +536,7 @@ func (s SqlTeamStore) SearchAllPaged(opts *model.TeamSearch) ([]*model.Team, int
|
||||
return nil, 0, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
|
||||
err = s.GetReplicaX().Get(&totalCount, queryString, args...)
|
||||
err = s.GetReplica().Get(&totalCount, queryString, args...)
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrapf(err, "failed to count Teams with term=%s", opts.Term)
|
||||
}
|
||||
@@ -570,7 +570,7 @@ func (s SqlTeamStore) GetAll() ([]*model.Team, error) {
|
||||
return nil, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
|
||||
err = s.GetReplicaX().Select(&teams, query, args...)
|
||||
err = s.GetReplica().Select(&teams, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Teams")
|
||||
}
|
||||
@@ -611,7 +611,7 @@ func (s SqlTeamStore) GetAllPage(offset int, limit int, opts *model.TeamSearch)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
if err = s.GetReplicaX().Select(&teams, query, args...); err != nil {
|
||||
if err = s.GetReplica().Select(&teams, query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Teams")
|
||||
}
|
||||
|
||||
@@ -629,7 +629,7 @@ func (s SqlTeamStore) GetTeamsByUserId(userId string) ([]*model.Team, error) {
|
||||
return nil, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
|
||||
if err = s.GetReplicaX().Select(&teams, query, args...); err != nil {
|
||||
if err = s.GetReplica().Select(&teams, query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Teams")
|
||||
}
|
||||
|
||||
@@ -644,7 +644,7 @@ func (s SqlTeamStore) GetAllPrivateTeamListing() ([]*model.Team, error) {
|
||||
return nil, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
data := []*model.Team{}
|
||||
if err = s.GetReplicaX().Select(&data, query, args...); err != nil {
|
||||
if err = s.GetReplica().Select(&data, query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Teams")
|
||||
}
|
||||
return data, nil
|
||||
@@ -660,7 +660,7 @@ func (s SqlTeamStore) GetAllTeamListing() ([]*model.Team, error) {
|
||||
}
|
||||
|
||||
data := []*model.Team{}
|
||||
if err = s.GetReplicaX().Select(&data, query, args...); err != nil {
|
||||
if err = s.GetReplica().Select(&data, query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Teams")
|
||||
}
|
||||
|
||||
@@ -676,7 +676,7 @@ func (s SqlTeamStore) PermanentDelete(teamId string) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
if _, err = s.GetMasterX().Exec(sql, args...); err != nil {
|
||||
if _, err = s.GetMaster().Exec(sql, args...); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete Team with id=%s", teamId)
|
||||
}
|
||||
return nil
|
||||
@@ -698,7 +698,7 @@ func (s SqlTeamStore) AnalyticsTeamCount(opts *model.TeamSearch) (int64, error)
|
||||
}
|
||||
|
||||
var c int64
|
||||
err = s.GetReplicaX().Get(&c, queryString, args...)
|
||||
err = s.GetReplica().Get(&c, queryString, args...)
|
||||
|
||||
if err != nil {
|
||||
return int64(0), errors.Wrap(err, "failed to count Teams")
|
||||
@@ -769,7 +769,7 @@ func (s SqlTeamStore) SaveMultipleMembers(members []*model.TeamMember, maxUsersP
|
||||
User sql.NullString
|
||||
Admin sql.NullString
|
||||
}{}
|
||||
err = s.GetMasterX().Select(&defaultTeamsRoles, sqlRolesQuery, argsRoles...)
|
||||
err = s.GetMaster().Select(&defaultTeamsRoles, sqlRolesQuery, argsRoles...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "default_team_roles_select")
|
||||
}
|
||||
@@ -800,7 +800,7 @@ func (s SqlTeamStore) SaveMultipleMembers(members []*model.TeamMember, maxUsersP
|
||||
TeamId string
|
||||
}{}
|
||||
|
||||
err = s.GetMasterX().Select(&counters, sqlCountQuery, argsCount...)
|
||||
err = s.GetMaster().Select(&counters, sqlCountQuery, argsCount...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to count users in the teams of the memberships")
|
||||
}
|
||||
@@ -828,7 +828,7 @@ func (s SqlTeamStore) SaveMultipleMembers(members []*model.TeamMember, maxUsersP
|
||||
return nil, errors.Wrap(err, "insert_members_to_sql")
|
||||
}
|
||||
|
||||
if _, err = s.GetMasterX().Exec(sql, args...); err != nil {
|
||||
if _, err = s.GetMaster().Exec(sql, args...); err != nil {
|
||||
if IsUniqueConstraintError(err, []string{"TeamId", "teammembers_pkey", "PRIMARY"}) {
|
||||
return nil, store.NewErrConflict("TeamMember", err, "")
|
||||
}
|
||||
@@ -873,7 +873,7 @@ func (s SqlTeamStore) UpdateMultipleMembers(members []*model.TeamMember) ([]*mod
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().NamedExec(`UPDATE TeamMembers
|
||||
if _, err := s.GetMaster().NamedExec(`UPDATE TeamMembers
|
||||
SET Roles=:Roles, DeleteAt=:DeleteAt, CreateAt=:CreateAt, SchemeGuest=:SchemeGuest,
|
||||
SchemeUser=:SchemeUser, SchemeAdmin=:SchemeAdmin
|
||||
WHERE TeamId=:TeamId AND UserId=:UserId`, newTeamMember); err != nil {
|
||||
@@ -903,7 +903,7 @@ func (s SqlTeamStore) UpdateMultipleMembers(members []*model.TeamMember) ([]*mod
|
||||
User sql.NullString
|
||||
Admin sql.NullString
|
||||
}{}
|
||||
err = s.GetMasterX().Select(&defaultTeamsRoles, sqlQuery, args...)
|
||||
err = s.GetMaster().Select(&defaultTeamsRoles, sqlQuery, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Teams")
|
||||
}
|
||||
@@ -1008,7 +1008,7 @@ func (s SqlTeamStore) GetMembers(teamId string, offset int, limit int, teamMembe
|
||||
}
|
||||
|
||||
dbMembers := teamMemberWithSchemeRolesList{}
|
||||
err = s.GetReplicaX().Select(&dbMembers, queryString, args...)
|
||||
err = s.GetReplica().Select(&dbMembers, queryString, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find TeamMembers with teamId=%s", teamId)
|
||||
}
|
||||
@@ -1033,7 +1033,7 @@ func (s SqlTeamStore) GetTotalMemberCount(teamId string, restrictions *model.Vie
|
||||
}
|
||||
|
||||
var count int64
|
||||
err = s.GetReplicaX().Get(&count, queryString, args...)
|
||||
err = s.GetReplica().Get(&count, queryString, args...)
|
||||
if err != nil {
|
||||
return int64(0), errors.Wrap(err, "failed to count TeamMembers")
|
||||
}
|
||||
@@ -1058,7 +1058,7 @@ func (s SqlTeamStore) GetActiveMemberCount(teamId string, restrictions *model.Vi
|
||||
}
|
||||
|
||||
var count int64
|
||||
err = s.GetReplicaX().Get(&count, queryString, args...)
|
||||
err = s.GetReplica().Get(&count, queryString, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count TeamMembers")
|
||||
}
|
||||
@@ -1086,7 +1086,7 @@ func (s SqlTeamStore) GetMembersByIds(teamId string, userIds []string, restricti
|
||||
}
|
||||
|
||||
dbMembers := teamMemberWithSchemeRolesList{}
|
||||
if err = s.GetReplicaX().Select(&dbMembers, queryString, args...); err != nil {
|
||||
if err = s.GetReplica().Select(&dbMembers, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find TeamMembers")
|
||||
}
|
||||
return dbMembers.ToModel(), nil
|
||||
@@ -1133,7 +1133,7 @@ func (s SqlTeamStore) GetTeamsForUserWithPagination(userId string, page, perPage
|
||||
}
|
||||
|
||||
dbMembers := teamMemberWithSchemeRolesList{}
|
||||
err = s.GetReplicaX().Select(&dbMembers, queryString, args...)
|
||||
err = s.GetReplica().Select(&dbMembers, queryString, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find TeamMembers with userId=%s", userId)
|
||||
}
|
||||
@@ -1155,7 +1155,7 @@ func (s SqlTeamStore) GetChannelUnreadsForAllTeams(excludeTeamId, userId string)
|
||||
return nil, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
data := []*model.ChannelUnread{}
|
||||
err = s.GetReplicaX().Select(&data, query, args...)
|
||||
err = s.GetReplica().Select(&data, query, args...)
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Channels with userId=%s and teamId!=%s", userId, excludeTeamId)
|
||||
@@ -1177,7 +1177,7 @@ func (s SqlTeamStore) GetChannelUnreadsForTeam(teamId, userId string) ([]*model.
|
||||
}
|
||||
|
||||
channels := []*model.ChannelUnread{}
|
||||
err = s.GetReplicaX().Select(&channels, query, args...)
|
||||
err = s.GetReplica().Select(&channels, query, args...)
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Channels with teamId=%s and userId=%s", teamId, userId)
|
||||
@@ -1195,7 +1195,7 @@ func (s SqlTeamStore) RemoveMembers(rctx request.CTX, teamId string, userIds []s
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
_, err = s.GetMasterX().Exec(query, args...)
|
||||
_, err = s.GetMaster().Exec(query, args...)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete TeamMembers with teamId=%s and userId in %v", teamId, userIds)
|
||||
}
|
||||
@@ -1216,7 +1216,7 @@ func (s SqlTeamStore) RemoveAllMembersByTeam(teamId string) error {
|
||||
return errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
|
||||
_, err = s.GetMasterX().Exec(query, args...)
|
||||
_, err = s.GetMaster().Exec(query, args...)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete TeamMembers with teamId=%s", teamId)
|
||||
}
|
||||
@@ -1231,7 +1231,7 @@ func (s SqlTeamStore) RemoveAllMembersByUser(rctx request.CTX, userId string) er
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
_, err = s.GetMasterX().Exec(query, args...)
|
||||
_, err = s.GetMaster().Exec(query, args...)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete TeamMembers with userId=%s", userId)
|
||||
}
|
||||
@@ -1250,7 +1250,7 @@ func (s SqlTeamStore) UpdateLastTeamIconUpdate(teamId string, curTime int64) err
|
||||
return errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
|
||||
if _, err = s.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err = s.GetMaster().Exec(query, args...); err != nil {
|
||||
return errors.Wrap(err, "failed to update Team")
|
||||
}
|
||||
return nil
|
||||
@@ -1269,7 +1269,7 @@ func (s SqlTeamStore) GetTeamsByScheme(schemeId string, offset int, limit int) (
|
||||
}
|
||||
|
||||
teams := []*model.Team{}
|
||||
err = s.GetReplicaX().Select(&teams, query, args...)
|
||||
err = s.GetReplica().Select(&teams, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Teams with schemeId=%s", schemeId)
|
||||
}
|
||||
@@ -1283,7 +1283,7 @@ func (s SqlTeamStore) GetTeamsByScheme(schemeId string, offset int, limit int) (
|
||||
func (s SqlTeamStore) MigrateTeamMembers(fromTeamId string, fromUserId string) (_ map[string]string, err error) {
|
||||
var transaction *sqlxTxWrapper
|
||||
|
||||
if transaction, err = s.GetMasterX().Beginx(); err != nil {
|
||||
if transaction, err = s.GetMaster().Beginx(); err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
defer finalizeTransactionX(transaction, &err)
|
||||
@@ -1350,7 +1350,7 @@ func (s SqlTeamStore) MigrateTeamMembers(fromTeamId string, fromUserId string) (
|
||||
|
||||
// ResetAllTeamSchemes Set all Team's SchemeId values to an empty string.
|
||||
func (s SqlTeamStore) ResetAllTeamSchemes() error {
|
||||
if _, err := s.GetMasterX().Exec("UPDATE Teams SET SchemeId=''"); err != nil {
|
||||
if _, err := s.GetMaster().Exec("UPDATE Teams SET SchemeId=''"); err != nil {
|
||||
return errors.Wrap(err, "failed to update Teams")
|
||||
}
|
||||
return nil
|
||||
@@ -1374,7 +1374,7 @@ func (s SqlTeamStore) ClearAllCustomRoleAssignments() (err error) {
|
||||
var transaction *sqlxTxWrapper
|
||||
var err error
|
||||
|
||||
if transaction, err = s.GetMasterX().Beginx(); err != nil {
|
||||
if transaction, err = s.GetMaster().Beginx(); err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
defer finalizeTransactionX(transaction, &err)
|
||||
@@ -1430,7 +1430,7 @@ func (s SqlTeamStore) AnalyticsGetTeamCountForScheme(schemeId string) (int64, er
|
||||
}
|
||||
|
||||
var count int64
|
||||
err = s.GetReplicaX().Get(&count, query, args...)
|
||||
err = s.GetReplica().Get(&count, query, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "failed to count Teams with schemeId=%s", schemeId)
|
||||
}
|
||||
@@ -1452,7 +1452,7 @@ func (s SqlTeamStore) GetAllForExportAfter(limit int, afterId string) ([]*model.
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
if err = s.GetReplicaX().Select(&data, query, args...); err != nil {
|
||||
if err = s.GetReplica().Select(&data, query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Teams")
|
||||
}
|
||||
|
||||
@@ -1473,7 +1473,7 @@ func (s SqlTeamStore) GetUserTeamIds(userId string, allowFromCache bool) ([]stri
|
||||
if err != nil {
|
||||
return []string{}, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
err = s.GetReplicaX().Select(&teamIds, query, args...)
|
||||
err = s.GetReplica().Select(&teamIds, query, args...)
|
||||
if err != nil {
|
||||
return []string{}, errors.Wrapf(err, "failed to find TeamMembers with userId=%s", userId)
|
||||
}
|
||||
@@ -1501,7 +1501,7 @@ func (s SqlTeamStore) GetCommonTeamIDsForTwoUsers(userID, otherUserID string) ([
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
err = s.GetReplicaX().Select(&teamIDs, query, args...)
|
||||
err = s.GetReplica().Select(&teamIDs, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find TeamMembers with user IDs %s and %s", userID, otherUserID)
|
||||
}
|
||||
@@ -1542,7 +1542,7 @@ func (s SqlTeamStore) GetCommonTeamIDsForMultipleUsers(userIDs []string) ([]stri
|
||||
|
||||
var teamIDs []string
|
||||
|
||||
if err := s.GetReplicaX().Select(&teamIDs, querySQL, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&teamIDs, querySQL, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find common team for users %v", userIDs)
|
||||
}
|
||||
|
||||
@@ -1563,7 +1563,7 @@ func (s SqlTeamStore) GetTeamMembersForExport(userId string) ([]*model.TeamMembe
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
err = s.GetReplicaX().Select(&members, query, args...)
|
||||
err = s.GetReplica().Select(&members, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find TeamMembers with userId=%s", userId)
|
||||
}
|
||||
@@ -1584,7 +1584,7 @@ func (s SqlTeamStore) UserBelongsToTeams(userId string, teamIds []string) (bool,
|
||||
}
|
||||
|
||||
var c int64
|
||||
err = s.GetReplicaX().Get(&c, query, params...)
|
||||
err = s.GetReplica().Get(&c, query, params...)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "failed to count TeamMembers")
|
||||
}
|
||||
@@ -1596,7 +1596,7 @@ func (s SqlTeamStore) UserBelongsToTeams(userId string, teamIds []string) (bool,
|
||||
// users as not being admin.
|
||||
// It returns the list of userIDs whose roles got updated.
|
||||
func (s SqlTeamStore) UpdateMembersRole(teamID string, adminIDs []string) (_ []*model.TeamMember, err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1732,7 +1732,7 @@ func (s SqlTeamStore) GroupSyncedTeamCount() (int64, error) {
|
||||
}
|
||||
|
||||
var count int64
|
||||
err = s.GetReplicaX().Get(&count, query, args...)
|
||||
err = s.GetReplica().Get(&count, query, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count Teams")
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func (s SqlTermsOfServiceStore) Save(termsOfService *model.TermsOfService) (*mod
|
||||
(:Id, :CreateAt, :UserId, :Text)
|
||||
`
|
||||
|
||||
if _, err := s.GetMasterX().NamedExec(query, termsOfService); err != nil {
|
||||
if _, err := s.GetMaster().NamedExec(query, termsOfService); err != nil {
|
||||
return nil, errors.Wrapf(err, "could not save a new TermsOfService")
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ func (s SqlTermsOfServiceStore) GetLatest(allowFromCache bool) (*model.TermsOfSe
|
||||
return nil, errors.Wrap(err, "could not build sql query to get latest TOS")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Get(&termsOfService, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&termsOfService, queryString, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("TermsOfService", "CreateAt=latest")
|
||||
}
|
||||
@@ -81,7 +81,7 @@ func (s SqlTermsOfServiceStore) Get(id string, allowFromCache bool) (*model.Term
|
||||
return nil, errors.Wrap(err, "terms_of_service_to_sql")
|
||||
}
|
||||
|
||||
err = s.GetReplicaX().Get(&termsOfService, queryString, id)
|
||||
err = s.GetReplica().Get(&termsOfService, queryString, id)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("TermsOfService", "id")
|
||||
|
||||
@@ -112,7 +112,7 @@ func (s *SqlThreadStore) Get(id string) (*model.Thread, error) {
|
||||
query := s.threadsSelectQuery.
|
||||
Where(sq.Eq{"PostId": id})
|
||||
|
||||
err := s.GetReplicaX().GetBuilder(&thread, query)
|
||||
err := s.GetReplica().GetBuilder(&thread, query)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
@@ -160,7 +160,7 @@ func (s *SqlThreadStore) GetTotalUnreadThreads(userId, teamId string, opts model
|
||||
Where(sq.Expr("ThreadMemberships.LastViewed < Threads.LastReplyAt"))
|
||||
|
||||
var totalUnreadThreads int64
|
||||
err := s.GetReplicaX().GetBuilder(&totalUnreadThreads, query)
|
||||
err := s.GetReplica().GetBuilder(&totalUnreadThreads, query)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "failed to count unread threads for user id=%s", userId)
|
||||
}
|
||||
@@ -178,7 +178,7 @@ func (s *SqlThreadStore) GetTotalThreads(userId, teamId string, opts model.GetUs
|
||||
query := s.getTotalThreadsQuery(userId, teamId, opts)
|
||||
|
||||
var totalThreads int64
|
||||
err := s.GetReplicaX().GetBuilder(&totalThreads, query)
|
||||
err := s.GetReplica().GetBuilder(&totalThreads, query)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "failed to count threads for user id=%s", userId)
|
||||
}
|
||||
@@ -217,7 +217,7 @@ func (s *SqlThreadStore) GetTotalUnreadMentions(userId, teamId string, opts mode
|
||||
query = query.Where(sq.Eq{"COALESCE(Threads.ThreadDeleteAt, 0)": 0})
|
||||
}
|
||||
|
||||
err := s.GetReplicaX().GetBuilder(&totalUnreadMentions, query)
|
||||
err := s.GetReplica().GetBuilder(&totalUnreadMentions, query)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "failed to count unread mentions for user id=%s", userId)
|
||||
}
|
||||
@@ -262,7 +262,7 @@ func (s *SqlThreadStore) GetTotalUnreadUrgentMentions(userId, teamId string, opt
|
||||
Where(sq.Eq{"COALESCE(Threads.ThreadDeleteAt, 0)": 0})
|
||||
}
|
||||
|
||||
err := s.GetReplicaX().GetBuilder(&totalUnreadUrgentMentions, query)
|
||||
err := s.GetReplica().GetBuilder(&totalUnreadUrgentMentions, query)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "failed to count unread urgent mentions for user id=%s", userId)
|
||||
}
|
||||
@@ -359,7 +359,7 @@ func (s *SqlThreadStore) GetThreadsForUser(userId, teamId string, opts model.Get
|
||||
Limit(pageSize)
|
||||
|
||||
var threads []*JoinedThread
|
||||
err := s.GetReplicaX().SelectBuilder(&threads, query)
|
||||
err := s.GetReplica().SelectBuilder(&threads, query)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to fetch threads for user id=%s", userId)
|
||||
}
|
||||
@@ -434,7 +434,7 @@ func (s *SqlThreadStore) GetTeamsUnreadForUser(userID string, teamIDs []string,
|
||||
Where("Threads.LastReplyAt > ThreadMemberships.LastViewed").
|
||||
GroupBy("Threads.ThreadTeamId")
|
||||
|
||||
return errors.Wrap(s.GetReplicaX().SelectBuilder(&unreadThreads, repliesQuery), "failed to get total unread threads")
|
||||
return errors.Wrap(s.GetReplica().SelectBuilder(&unreadThreads, repliesQuery), "failed to get total unread threads")
|
||||
})
|
||||
|
||||
eg.Go(func() error {
|
||||
@@ -445,7 +445,7 @@ func (s *SqlThreadStore) GetTeamsUnreadForUser(userID string, teamIDs []string,
|
||||
Where(fetchConditions).
|
||||
GroupBy("Threads.ThreadTeamId")
|
||||
|
||||
return errors.Wrap(s.GetReplicaX().SelectBuilder(&unreadMentions, mentionsQuery), "failed to get total unread mentions")
|
||||
return errors.Wrap(s.GetReplica().SelectBuilder(&unreadMentions, mentionsQuery), "failed to get total unread mentions")
|
||||
})
|
||||
|
||||
if includeUrgentMentionCount {
|
||||
@@ -459,7 +459,7 @@ func (s *SqlThreadStore) GetTeamsUnreadForUser(userID string, teamIDs []string,
|
||||
Where(fetchConditions).
|
||||
GroupBy("Threads.ThreadTeamId")
|
||||
|
||||
return errors.Wrap(s.GetReplicaX().SelectBuilder(&unreadUrgentMentions, urgentMentionsQuery), "failed to get total unread urgent mentions")
|
||||
return errors.Wrap(s.GetReplica().SelectBuilder(&unreadUrgentMentions, urgentMentionsQuery), "failed to get total unread urgent mentions")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -517,7 +517,7 @@ func (s *SqlThreadStore) GetThreadFollowers(threadID string, fetchOnlyActive boo
|
||||
From("ThreadMemberships").
|
||||
Where(fetchConditions)
|
||||
|
||||
err := s.GetReplicaX().SelectBuilder(&users, query)
|
||||
err := s.GetReplica().SelectBuilder(&users, query)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get thread followers for thread id=%s", threadID)
|
||||
}
|
||||
@@ -539,7 +539,7 @@ func (s *SqlThreadStore) GetThreadMembershipsForExport(postID string) ([]*model.
|
||||
InnerJoin("Users ON ThreadMemberships.UserId = Users.Id").
|
||||
Where(fetchConditions)
|
||||
|
||||
err := s.GetReplicaX().SelectBuilder(&members, query)
|
||||
err := s.GetReplica().SelectBuilder(&members, query)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get thread members for thread id=%s", postID)
|
||||
}
|
||||
@@ -584,7 +584,7 @@ func (s *SqlThreadStore) GetThreadForUser(threadMembership *model.ThreadMembersh
|
||||
LeftJoin("PostsPriority ON PostsPriority.PostId = Threads.PostId")
|
||||
}
|
||||
|
||||
err := s.GetReplicaX().GetBuilder(&thread, query)
|
||||
err := s.GetReplica().GetBuilder(&thread, query)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Thread", threadMembership.PostId)
|
||||
@@ -641,7 +641,7 @@ func (s *SqlThreadStore) MarkAllAsReadByChannels(userID string, channelIDs []str
|
||||
Where(sq.Eq{"Threads.ChannelId": channelIDs}).
|
||||
Where(sq.Expr("Threads.LastReplyAt > ThreadMemberships.LastViewed"))
|
||||
|
||||
if _, err := s.GetMasterX().ExecBuilder(query); err != nil {
|
||||
if _, err := s.GetMaster().ExecBuilder(query); err != nil {
|
||||
return errors.Wrapf(err, "failed to mark all threads as read by channels for user id=%s", userID)
|
||||
}
|
||||
|
||||
@@ -659,7 +659,7 @@ func (s *SqlThreadStore) MarkAllAsRead(userId string, threadIds []string) error
|
||||
Set("UnreadMentions", 0).
|
||||
Set("LastUpdated", model.GetMillis())
|
||||
|
||||
_, err := s.GetMasterX().ExecBuilder(query)
|
||||
_, err := s.GetMaster().ExecBuilder(query)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to mark %d threads as read for user id=%s", len(threadIds), userId)
|
||||
}
|
||||
@@ -687,7 +687,7 @@ func (s *SqlThreadStore) MarkAllAsReadByTeam(userId, teamId string) error {
|
||||
Set("UnreadMentions", 0).
|
||||
Set("LastUpdated", timestamp)
|
||||
|
||||
_, err := s.GetMasterX().ExecBuilder(query)
|
||||
_, err := s.GetMaster().ExecBuilder(query)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to update thread read state for user id=%s", userId)
|
||||
}
|
||||
@@ -704,7 +704,7 @@ func (s *SqlThreadStore) MarkAsRead(userId, threadId string, timestamp int64) er
|
||||
Set("LastViewed", timestamp).
|
||||
Set("LastUpdated", model.GetMillis())
|
||||
|
||||
_, err := s.GetMasterX().ExecBuilder(query)
|
||||
_, err := s.GetMaster().ExecBuilder(query)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to update thread read state for user id=%s thread_id=%v", userId, threadId)
|
||||
}
|
||||
@@ -726,7 +726,7 @@ func (s *SqlThreadStore) saveMembership(ex sqlxExecutor, membership *model.Threa
|
||||
}
|
||||
|
||||
func (s *SqlThreadStore) UpdateMembership(membership *model.ThreadMembership) (*model.ThreadMembership, error) {
|
||||
return s.updateMembership(s.GetMasterX(), membership)
|
||||
return s.updateMembership(s.GetMaster(), membership)
|
||||
}
|
||||
|
||||
func (s *SqlThreadStore) DeleteMembershipsForChannel(userID, channelID string) error {
|
||||
@@ -743,7 +743,7 @@ func (s *SqlThreadStore) DeleteMembershipsForChannel(userID, channelID string) e
|
||||
Where(sq.Eq{"UserId": userID}).
|
||||
Where(sq.Expr("EXISTS (?)", subQuery))
|
||||
|
||||
_, err := s.GetMasterX().ExecBuilder(query)
|
||||
_, err := s.GetMaster().ExecBuilder(query)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to remove thread memberships with userid=%s channelid=%s", userID, channelID)
|
||||
}
|
||||
@@ -788,7 +788,7 @@ func (s *SqlThreadStore) GetMembershipsForUser(userId, teamId string) ([]*model.
|
||||
Where(sq.Or{sq.Eq{"Threads.ThreadTeamId": teamId}, sq.Eq{"Threads.ThreadTeamId": ""}}).
|
||||
Where(sq.Eq{"ThreadMemberships.UserId": userId})
|
||||
|
||||
err := s.GetReplicaX().SelectBuilder(&memberships, query)
|
||||
err := s.GetReplica().SelectBuilder(&memberships, query)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get thread membership with userid=%s", userId)
|
||||
}
|
||||
@@ -796,7 +796,7 @@ func (s *SqlThreadStore) GetMembershipsForUser(userId, teamId string) ([]*model.
|
||||
}
|
||||
|
||||
func (s *SqlThreadStore) GetMembershipForUser(userId, postId string) (*model.ThreadMembership, error) {
|
||||
return s.getMembershipForUser(s.GetReplicaX(), userId, postId)
|
||||
return s.getMembershipForUser(s.GetReplica(), userId, postId)
|
||||
}
|
||||
|
||||
func (s *SqlThreadStore) getMembershipForUser(ex sqlxExecutor, userId, postId string) (*model.ThreadMembership, error) {
|
||||
@@ -835,7 +835,7 @@ func (s *SqlThreadStore) DeleteMembershipForUser(userId string, postId string) e
|
||||
sq.Eq{"UserId": userId},
|
||||
})
|
||||
|
||||
_, err := s.GetMasterX().ExecBuilder(query)
|
||||
_, err := s.GetMaster().ExecBuilder(query)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to delete thread membership")
|
||||
}
|
||||
@@ -850,7 +850,7 @@ func (s *SqlThreadStore) DeleteMembershipForUser(userId string, postId string) e
|
||||
// - channel marked unread
|
||||
// - user explicitly following a thread
|
||||
func (s *SqlThreadStore) MaintainMembership(userID, postID string, opts store.ThreadMembershipOpts) (_ *model.ThreadMembership, err error) {
|
||||
trx, err := s.GetMasterX().Beginx()
|
||||
trx, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -869,7 +869,7 @@ func (s *SqlThreadStore) MaintainMembership(userID, postID string, opts store.Th
|
||||
}
|
||||
|
||||
func (s *SqlThreadStore) MaintainMultipleFromImport(memberships []*model.ThreadMembership) (_ []*model.ThreadMembership, err error) {
|
||||
trx, err := s.GetMasterX().Beginx()
|
||||
trx, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -1039,7 +1039,7 @@ func (s *SqlThreadStore) DeleteOrphanedRows(limit int) (deleted int64, err error
|
||||
) AS A
|
||||
)`
|
||||
|
||||
result, err := s.GetMasterX().Exec(threadMembershipsQuery, limit)
|
||||
result, err := s.GetMaster().Exec(threadMembershipsQuery, limit)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -1062,7 +1062,7 @@ func (s *SqlThreadStore) GetThreadUnreadReplyCount(threadMembership *model.Threa
|
||||
})
|
||||
|
||||
var unreadReplies int64
|
||||
err := s.GetReplicaX().GetBuilder(&unreadReplies, query)
|
||||
err := s.GetReplica().GetBuilder(&unreadReplies, query)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "failed to count unread reply count for post id=%s", threadMembership.PostId)
|
||||
}
|
||||
@@ -1090,7 +1090,7 @@ func (s *SqlThreadStore) SaveMultipleMemberships(memberships []*model.ThreadMemb
|
||||
query = query.Values(member.PostId, member.UserId, member.Following, member.LastViewed, member.LastUpdated, member.UnreadMentions)
|
||||
}
|
||||
|
||||
tx, err := s.GetMasterX().Beginx()
|
||||
tx, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
|
||||
@@ -35,14 +35,14 @@ func (s SqlTokenStore) Save(token *model.Token) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "token_tosql")
|
||||
}
|
||||
if _, err := s.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(query, args...); err != nil {
|
||||
return errors.Wrap(err, "failed to save Token")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlTokenStore) Delete(token string) error {
|
||||
if _, err := s.GetMasterX().Exec("DELETE FROM Tokens WHERE Token = ?", token); err != nil {
|
||||
if _, err := s.GetMaster().Exec("DELETE FROM Tokens WHERE Token = ?", token); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete Token with value %s", token)
|
||||
}
|
||||
return nil
|
||||
@@ -51,7 +51,7 @@ func (s SqlTokenStore) Delete(token string) error {
|
||||
func (s SqlTokenStore) GetByToken(tokenString string) (*model.Token, error) {
|
||||
var token model.Token
|
||||
|
||||
if err := s.GetReplicaX().Get(&token, "SELECT * FROM Tokens WHERE Token = ?", tokenString); err != nil {
|
||||
if err := s.GetReplica().Get(&token, "SELECT * FROM Tokens WHERE Token = ?", tokenString); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("Token", fmt.Sprintf("Token=%s", tokenString))
|
||||
}
|
||||
@@ -63,7 +63,7 @@ func (s SqlTokenStore) GetByToken(tokenString string) (*model.Token, error) {
|
||||
}
|
||||
|
||||
func (s SqlTokenStore) Cleanup(expiryTime int64) {
|
||||
if _, err := s.GetMasterX().Exec("DELETE FROM Tokens WHERE CreateAt < ?", expiryTime); err != nil {
|
||||
if _, err := s.GetMaster().Exec("DELETE FROM Tokens WHERE CreateAt < ?", expiryTime); err != nil {
|
||||
mlog.Error("Unable to cleanup token store.")
|
||||
}
|
||||
}
|
||||
@@ -79,14 +79,14 @@ func (s SqlTokenStore) GetAllTokensByType(tokenType string) ([]*model.Token, err
|
||||
return nil, errors.Wrap(err, "could not build sql query to get all tokens by type")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Select(&tokens, query, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&tokens, query, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get all tokens of Type=%s", tokenType)
|
||||
}
|
||||
return tokens, nil
|
||||
}
|
||||
|
||||
func (s SqlTokenStore) RemoveAllTokensByType(tokenType string) error {
|
||||
if _, err := s.GetMasterX().Exec("DELETE FROM Tokens WHERE Type = ?", tokenType); err != nil {
|
||||
if _, err := s.GetMaster().Exec("DELETE FROM Tokens WHERE Type = ?", tokenType); err != nil {
|
||||
return errors.Wrapf(err, "failed to remove all Tokens with Type=%s", tokenType)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -40,7 +40,7 @@ func (us SqlUploadSessionStore) Save(session *model.UploadSession) (*model.Uploa
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SqlUploadSessionStore.Save: failed to build query")
|
||||
}
|
||||
if _, err := us.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err := us.GetMaster().Exec(query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "SqlUploadSessionStore.Save: failed to insert")
|
||||
}
|
||||
return session, nil
|
||||
@@ -70,7 +70,7 @@ func (us SqlUploadSessionStore) Update(session *model.UploadSession) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "SqlUploadSessionStore.Update: failed to build query")
|
||||
}
|
||||
if _, err := us.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err := us.GetMaster().Exec(query, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return store.NewErrNotFound("UploadSession", session.Id)
|
||||
}
|
||||
@@ -112,7 +112,7 @@ func (us SqlUploadSessionStore) GetForUser(userId string) ([]*model.UploadSessio
|
||||
return nil, errors.Wrap(err, "SqlUploadSessionStore.GetForUser: failed to build query")
|
||||
}
|
||||
sessions := []*model.UploadSession{}
|
||||
if err := us.GetReplicaX().Select(&sessions, query, args...); err != nil {
|
||||
if err := us.GetReplica().Select(&sessions, query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "SqlUploadSessionStore.GetForUser: failed to select")
|
||||
}
|
||||
return sessions, nil
|
||||
@@ -131,7 +131,7 @@ func (us SqlUploadSessionStore) Delete(id string) error {
|
||||
return errors.Wrap(err, "SqlUploadSessionStore.Delete: failed to build query")
|
||||
}
|
||||
|
||||
if _, err := us.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err := us.GetMaster().Exec(query, args...); err != nil {
|
||||
return errors.Wrap(err, "SqlUploadSessionStore.Delete: failed to delete")
|
||||
}
|
||||
|
||||
|
||||
@@ -35,14 +35,14 @@ func (s SqlUserAccessTokenStore) Save(token *model.UserAccessToken) (*model.User
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "UserAccessToken_tosql")
|
||||
}
|
||||
if _, err := s.GetMasterX().Exec(query, args...); err != nil {
|
||||
if _, err := s.GetMaster().Exec(query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to save UserAccessToken")
|
||||
}
|
||||
return token, nil
|
||||
}
|
||||
|
||||
func (s SqlUserAccessTokenStore) Delete(tokenId string) (err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -83,7 +83,7 @@ func (s SqlUserAccessTokenStore) deleteTokensById(transaction *sqlxTxWrapper, to
|
||||
}
|
||||
|
||||
func (s SqlUserAccessTokenStore) DeleteAllForUser(userId string) (err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -125,7 +125,7 @@ func (s SqlUserAccessTokenStore) deleteTokensByUser(transaction *sqlxTxWrapper,
|
||||
func (s SqlUserAccessTokenStore) Get(tokenId string) (*model.UserAccessToken, error) {
|
||||
var token model.UserAccessToken
|
||||
|
||||
if err := s.GetReplicaX().Get(&token, "SELECT * FROM UserAccessTokens WHERE Id = ?", tokenId); err != nil {
|
||||
if err := s.GetReplica().Get(&token, "SELECT * FROM UserAccessTokens WHERE Id = ?", tokenId); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("UserAccessToken", tokenId)
|
||||
}
|
||||
@@ -138,7 +138,7 @@ func (s SqlUserAccessTokenStore) Get(tokenId string) (*model.UserAccessToken, er
|
||||
func (s SqlUserAccessTokenStore) GetAll(offset, limit int) ([]*model.UserAccessToken, error) {
|
||||
tokens := []*model.UserAccessToken{}
|
||||
|
||||
if err := s.GetReplicaX().Select(&tokens, "SELECT * FROM UserAccessTokens LIMIT ? OFFSET ?", limit, offset); err != nil {
|
||||
if err := s.GetReplica().Select(&tokens, "SELECT * FROM UserAccessTokens LIMIT ? OFFSET ?", limit, offset); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find UserAccessTokens")
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ func (s SqlUserAccessTokenStore) GetAll(offset, limit int) ([]*model.UserAccessT
|
||||
func (s SqlUserAccessTokenStore) GetByToken(tokenString string) (*model.UserAccessToken, error) {
|
||||
var token model.UserAccessToken
|
||||
|
||||
if err := s.GetReplicaX().Get(&token, "SELECT * FROM UserAccessTokens WHERE Token = ?", tokenString); err != nil {
|
||||
if err := s.GetReplica().Get(&token, "SELECT * FROM UserAccessTokens WHERE Token = ?", tokenString); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("UserAccessToken", fmt.Sprintf("token=%s", tokenString))
|
||||
}
|
||||
@@ -161,7 +161,7 @@ func (s SqlUserAccessTokenStore) GetByToken(tokenString string) (*model.UserAcce
|
||||
func (s SqlUserAccessTokenStore) GetByUser(userId string, offset, limit int) ([]*model.UserAccessToken, error) {
|
||||
tokens := []*model.UserAccessToken{}
|
||||
|
||||
if err := s.GetReplicaX().Select(&tokens, "SELECT * FROM UserAccessTokens WHERE UserId = ? LIMIT ? OFFSET ?", userId, limit, offset); err != nil {
|
||||
if err := s.GetReplica().Select(&tokens, "SELECT * FROM UserAccessTokens WHERE UserId = ? LIMIT ? OFFSET ?", userId, limit, offset); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find UserAccessTokens with userId=%s", userId)
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ func (s SqlUserAccessTokenStore) Search(term string) ([]*model.UserAccessToken,
|
||||
ON uat.UserId = u.Id
|
||||
WHERE uat.Id LIKE ? OR uat.UserId LIKE ? OR u.Username LIKE ?`
|
||||
|
||||
if err := s.GetReplicaX().Select(&tokens, query, params...); err != nil {
|
||||
if err := s.GetReplica().Select(&tokens, query, params...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find UserAccessTokens by term with value '%s'", term)
|
||||
}
|
||||
|
||||
@@ -188,14 +188,14 @@ func (s SqlUserAccessTokenStore) Search(term string) ([]*model.UserAccessToken,
|
||||
}
|
||||
|
||||
func (s SqlUserAccessTokenStore) UpdateTokenEnable(tokenId string) error {
|
||||
if _, err := s.GetMasterX().Exec("UPDATE UserAccessTokens SET IsActive = TRUE WHERE Id = ?", tokenId); err != nil {
|
||||
if _, err := s.GetMaster().Exec("UPDATE UserAccessTokens SET IsActive = TRUE WHERE Id = ?", tokenId); err != nil {
|
||||
return errors.Wrapf(err, "failed to update UserAccessTokens with id=%s", tokenId)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlUserAccessTokenStore) UpdateTokenDisable(tokenId string) (err error) {
|
||||
transaction, err := s.GetMasterX().Beginx()
|
||||
transaction, err := s.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ func (us SqlUserStore) insert(user *model.User) (sql.Result, error) {
|
||||
:Locale, :Timezone, :MfaActive, :MfaSecret, :RemoteId, :MfaUsedTimestamps)`
|
||||
|
||||
user.Props = wrapBinaryParamStringMap(us.IsBinaryParamEnabled(), user.Props)
|
||||
return us.GetMasterX().NamedExec(query, user)
|
||||
return us.GetMaster().NamedExec(query, user)
|
||||
}
|
||||
|
||||
func (us SqlUserStore) InsertUsers(users []*model.User) error {
|
||||
@@ -141,7 +141,7 @@ func (us SqlUserStore) DeactivateGuests() ([]string, error) {
|
||||
Where(sq.Eq{"Roles": "system_guest"}).
|
||||
Where(sq.Eq{"DeleteAt": 0})
|
||||
|
||||
_, err := us.GetMasterX().ExecBuilder(updateQuery)
|
||||
_, err := us.GetMaster().ExecBuilder(updateQuery)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to update Users with roles=system_guest")
|
||||
}
|
||||
@@ -152,7 +152,7 @@ func (us SqlUserStore) DeactivateGuests() ([]string, error) {
|
||||
Where(sq.Eq{"DeleteAt": curTime})
|
||||
|
||||
userIds := []string{}
|
||||
err = us.GetMasterX().SelectBuilder(&userIds, selectQuery)
|
||||
err = us.GetMaster().SelectBuilder(&userIds, selectQuery)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Users")
|
||||
}
|
||||
@@ -172,7 +172,7 @@ func (us SqlUserStore) Update(rctx request.CTX, user *model.User, trustedUpdateD
|
||||
}
|
||||
|
||||
oldUser := model.User{}
|
||||
err := us.GetMasterX().Get(&oldUser, "SELECT * FROM Users WHERE Id=?", user.Id)
|
||||
err := us.GetMaster().Get(&oldUser, "SELECT * FROM Users WHERE Id=?", user.Id)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get User with userId=%s", user.Id)
|
||||
}
|
||||
@@ -226,7 +226,7 @@ func (us SqlUserStore) Update(rctx request.CTX, user *model.User, trustedUpdateD
|
||||
WHERE Id=:Id`
|
||||
|
||||
user.Props = wrapBinaryParamStringMap(us.IsBinaryParamEnabled(), user.Props)
|
||||
res, err := us.GetMasterX().NamedExec(query, user)
|
||||
res, err := us.GetMaster().NamedExec(query, user)
|
||||
if err != nil {
|
||||
if IsUniqueConstraintError(err, []string{"Email", "users_email_key", "idx_users_email_unique"}) {
|
||||
return nil, store.NewErrConflict("Email", err, user.Email)
|
||||
@@ -263,7 +263,7 @@ func (us SqlUserStore) UpdateNotifyProps(userID string, props map[string]string)
|
||||
buf = AppendBinaryFlag(buf)
|
||||
}
|
||||
|
||||
if _, err := us.GetMasterX().Exec(`UPDATE Users
|
||||
if _, err := us.GetMaster().Exec(`UPDATE Users
|
||||
SET NotifyProps = ?
|
||||
WHERE Id = ?`, buf, userID); err != nil {
|
||||
return errors.Wrapf(err, "failed to update User with userId=%s", userID)
|
||||
@@ -275,7 +275,7 @@ func (us SqlUserStore) UpdateNotifyProps(userID string, props map[string]string)
|
||||
func (us SqlUserStore) UpdateLastPictureUpdate(userId string) error {
|
||||
curTime := model.GetMillis()
|
||||
|
||||
if _, err := us.GetMasterX().Exec("UPDATE Users SET LastPictureUpdate = ?, UpdateAt = ? WHERE Id = ?", curTime, curTime, userId); err != nil {
|
||||
if _, err := us.GetMaster().Exec("UPDATE Users SET LastPictureUpdate = ?, UpdateAt = ? WHERE Id = ?", curTime, curTime, userId); err != nil {
|
||||
return errors.Wrapf(err, "failed to update User with userId=%s", userId)
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ func (us SqlUserStore) UpdateLastPictureUpdate(userId string) error {
|
||||
func (us SqlUserStore) ResetLastPictureUpdate(userId string) error {
|
||||
curTime := model.GetMillis()
|
||||
|
||||
if _, err := us.GetMasterX().Exec("UPDATE Users SET LastPictureUpdate = ?, UpdateAt = ? WHERE Id = ?", -curTime, curTime, userId); err != nil {
|
||||
if _, err := us.GetMaster().Exec("UPDATE Users SET LastPictureUpdate = ?, UpdateAt = ? WHERE Id = ?", -curTime, curTime, userId); err != nil {
|
||||
return errors.Wrapf(err, "failed to update User with userId=%s", userId)
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ func (us SqlUserStore) ResetLastPictureUpdate(userId string) error {
|
||||
func (us SqlUserStore) UpdateUpdateAt(userId string) (int64, error) {
|
||||
curTime := model.GetMillis()
|
||||
|
||||
if _, err := us.GetMasterX().Exec("UPDATE Users SET UpdateAt = ? WHERE Id = ?", curTime, userId); err != nil {
|
||||
if _, err := us.GetMaster().Exec("UPDATE Users SET UpdateAt = ? WHERE Id = ?", curTime, userId); err != nil {
|
||||
return curTime, errors.Wrapf(err, "failed to update User with userId=%s", userId)
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ func (us SqlUserStore) UpdateUpdateAt(userId string) (int64, error) {
|
||||
func (us SqlUserStore) UpdatePassword(userId, hashedPassword string) error {
|
||||
updateAt := model.GetMillis()
|
||||
|
||||
if _, err := us.GetMasterX().Exec("UPDATE Users SET Password = ?, LastPasswordUpdate = ?, UpdateAt = ?, AuthData = NULL, AuthService = '', FailedAttempts = 0 WHERE Id = ?", hashedPassword, updateAt, updateAt, userId); err != nil {
|
||||
if _, err := us.GetMaster().Exec("UPDATE Users SET Password = ?, LastPasswordUpdate = ?, UpdateAt = ?, AuthData = NULL, AuthService = '', FailedAttempts = 0 WHERE Id = ?", hashedPassword, updateAt, updateAt, userId); err != nil {
|
||||
return errors.Wrapf(err, "failed to update User with userId=%s", userId)
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ func (us SqlUserStore) UpdatePassword(userId, hashedPassword string) error {
|
||||
}
|
||||
|
||||
func (us SqlUserStore) UpdateFailedPasswordAttempts(userId string, attempts int) error {
|
||||
if _, err := us.GetMasterX().Exec("UPDATE Users SET FailedAttempts = ? WHERE Id = ?", attempts, userId); err != nil {
|
||||
if _, err := us.GetMaster().Exec("UPDATE Users SET FailedAttempts = ? WHERE Id = ?", attempts, userId); err != nil {
|
||||
return errors.Wrapf(err, "failed to update User with userId=%s", userId)
|
||||
}
|
||||
|
||||
@@ -342,7 +342,7 @@ func (us SqlUserStore) UpdateAuthData(userId string, service string, authData *s
|
||||
Set("MfaUsedTimestamps", model.StringArray{})
|
||||
}
|
||||
|
||||
if _, err := us.GetMasterX().ExecBuilder(updateQuery); err != nil {
|
||||
if _, err := us.GetMaster().ExecBuilder(updateQuery); err != nil {
|
||||
if IsUniqueConstraintError(err, []string{"Email", "users_email_key", "idx_users_email_unique", "AuthData", "users_authdata_key"}) {
|
||||
return "", store.NewErrInvalidInput("User", "id", userId)
|
||||
}
|
||||
@@ -358,7 +358,7 @@ func (us SqlUserStore) UpdateLastLogin(userId string, lastLogin int64) error {
|
||||
Set("UpdateAt", model.GetMillis()).
|
||||
Where(sq.Eq{"Id": userId})
|
||||
|
||||
if _, err := us.GetMasterX().ExecBuilder(updateQuery); err != nil {
|
||||
if _, err := us.GetMaster().ExecBuilder(updateQuery); err != nil {
|
||||
return errors.Wrapf(err, "failed to update User with userId=%s", userId)
|
||||
}
|
||||
|
||||
@@ -385,14 +385,14 @@ func (us SqlUserStore) ResetAuthDataToEmailForUsers(service string, userIDs []st
|
||||
From("Users").
|
||||
Where(whereEquals)
|
||||
var numAffected int
|
||||
err := us.GetReplicaX().GetBuilder(&numAffected, builder)
|
||||
err := us.GetReplica().GetBuilder(&numAffected, builder)
|
||||
return numAffected, err
|
||||
}
|
||||
builder := us.getQueryBuilder().
|
||||
Update("Users").
|
||||
Set("AuthData", sq.Expr("Email")).
|
||||
Where(whereEquals)
|
||||
result, err := us.GetMasterX().ExecBuilder(builder)
|
||||
result, err := us.GetMaster().ExecBuilder(builder)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to update users' AuthData")
|
||||
}
|
||||
@@ -403,7 +403,7 @@ func (us SqlUserStore) ResetAuthDataToEmailForUsers(service string, userIDs []st
|
||||
func (us SqlUserStore) UpdateMfaSecret(userId, secret string) error {
|
||||
updateAt := model.GetMillis()
|
||||
|
||||
if _, err := us.GetMasterX().Exec("UPDATE Users SET MfaSecret = ?, MfaUsedTimestamps = ?, UpdateAt = ? WHERE Id = ?", secret, model.StringArray{}, updateAt, userId); err != nil {
|
||||
if _, err := us.GetMaster().Exec("UPDATE Users SET MfaSecret = ?, MfaUsedTimestamps = ?, UpdateAt = ? WHERE Id = ?", secret, model.StringArray{}, updateAt, userId); err != nil {
|
||||
return errors.Wrapf(err, "failed to update User with userId=%s", userId)
|
||||
}
|
||||
|
||||
@@ -413,7 +413,7 @@ func (us SqlUserStore) UpdateMfaSecret(userId, secret string) error {
|
||||
func (us SqlUserStore) UpdateMfaActive(userId string, active bool) error {
|
||||
updateAt := model.GetMillis()
|
||||
|
||||
if _, err := us.GetMasterX().Exec("UPDATE Users SET MfaActive = ?, UpdateAt = ? WHERE Id = ?", active, updateAt, userId); err != nil {
|
||||
if _, err := us.GetMaster().Exec("UPDATE Users SET MfaActive = ?, UpdateAt = ? WHERE Id = ?", active, updateAt, userId); err != nil {
|
||||
return errors.Wrapf(err, "failed to update User with userId=%s", userId)
|
||||
}
|
||||
|
||||
@@ -427,7 +427,7 @@ func (us SqlUserStore) StoreMfaUsedTimestamps(userId string, ts []int) error {
|
||||
}
|
||||
|
||||
updateAt := model.GetMillis()
|
||||
if _, err := us.GetMasterX().Exec("UPDATE Users SET MfaUsedTimestamps = ?, UpdateAt = ? WHERE Id = ?", tSStrArray, updateAt, userId); err != nil {
|
||||
if _, err := us.GetMaster().Exec("UPDATE Users SET MfaUsedTimestamps = ?, UpdateAt = ? WHERE Id = ?", tSStrArray, updateAt, userId); err != nil {
|
||||
return errors.Wrapf(err, "failed to update User with userId=%s", userId)
|
||||
}
|
||||
return nil
|
||||
@@ -435,7 +435,7 @@ func (us SqlUserStore) StoreMfaUsedTimestamps(userId string, ts []int) error {
|
||||
|
||||
func (us SqlUserStore) GetMfaUsedTimestamps(userId string) ([]int, error) {
|
||||
tsStrArray := model.StringArray{}
|
||||
err := us.GetReplicaX().Get(&tsStrArray, "SELECT MfaUsedTimestamps FROM Users WHERE Id = ?", userId)
|
||||
err := us.GetReplica().Get(&tsStrArray, "SELECT MfaUsedTimestamps FROM Users WHERE Id = ?", userId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get MFA used timestamps for user with ID %s", userId)
|
||||
}
|
||||
@@ -506,7 +506,7 @@ func (us SqlUserStore) GetAll() ([]*model.User, error) {
|
||||
}
|
||||
|
||||
data := []*model.User{}
|
||||
if err := us.GetReplicaX().Select(&data, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Select(&data, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Users")
|
||||
}
|
||||
return data, nil
|
||||
@@ -519,7 +519,7 @@ func (us SqlUserStore) GetAllAfter(limit int, afterId string) ([]*model.User, er
|
||||
Limit(uint64(limit))
|
||||
|
||||
users := []*model.User{}
|
||||
if err := us.GetReplicaX().SelectBuilder(&users, query); err != nil {
|
||||
if err := us.GetReplica().SelectBuilder(&users, query); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Users")
|
||||
}
|
||||
|
||||
@@ -528,7 +528,7 @@ func (us SqlUserStore) GetAllAfter(limit int, afterId string) ([]*model.User, er
|
||||
|
||||
func (us SqlUserStore) GetEtagForAllProfiles() string {
|
||||
var updateAt int64
|
||||
err := us.GetReplicaX().Get(&updateAt, "SELECT UpdateAt FROM Users ORDER BY UpdateAt DESC LIMIT 1")
|
||||
err := us.GetReplica().Get(&updateAt, "SELECT UpdateAt FROM Users ORDER BY UpdateAt DESC LIMIT 1")
|
||||
if err != nil {
|
||||
return fmt.Sprintf("%v.%v", model.CurrentVersion, model.GetMillis())
|
||||
}
|
||||
@@ -553,7 +553,7 @@ func (us SqlUserStore) GetAllProfiles(options *model.UserGetOptions) ([]*model.U
|
||||
}
|
||||
|
||||
users := []*model.User{}
|
||||
if err := us.GetReplicaX().SelectBuilder(&users, query); err != nil {
|
||||
if err := us.GetReplica().SelectBuilder(&users, query); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get User profiles")
|
||||
}
|
||||
|
||||
@@ -698,7 +698,7 @@ func applyTeamGroupConstrainedFilter(query sq.SelectBuilder, teamId string) sq.S
|
||||
|
||||
func (us SqlUserStore) GetEtagForProfiles(teamId string) string {
|
||||
var updateAt int64
|
||||
err := us.GetReplicaX().Get(&updateAt, "SELECT UpdateAt FROM Users, TeamMembers WHERE TeamMembers.TeamId = ? AND Users.Id = TeamMembers.UserId ORDER BY UpdateAt DESC LIMIT 1", teamId)
|
||||
err := us.GetReplica().Get(&updateAt, "SELECT UpdateAt FROM Users, TeamMembers WHERE TeamMembers.TeamId = ? AND Users.Id = TeamMembers.UserId ORDER BY UpdateAt DESC LIMIT 1", teamId)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("%v.%v", model.CurrentVersion, model.GetMillis())
|
||||
}
|
||||
@@ -725,7 +725,7 @@ func (us SqlUserStore) GetProfiles(options *model.UserGetOptions) ([]*model.User
|
||||
}
|
||||
|
||||
users := []*model.User{}
|
||||
if err := us.GetReplicaX().SelectBuilder(&users, query); err != nil {
|
||||
if err := us.GetReplica().SelectBuilder(&users, query); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Users")
|
||||
}
|
||||
|
||||
@@ -756,7 +756,7 @@ func (us SqlUserStore) GetProfilesInChannel(options *model.UserGetOptions) ([]*m
|
||||
query = applyMultiRoleFilters(query, options.Roles, options.TeamRoles, options.ChannelRoles, us.DriverName() == model.DatabaseDriverPostgres)
|
||||
|
||||
users := []*model.User{}
|
||||
if err := us.GetReplicaX().SelectBuilder(&users, query); err != nil {
|
||||
if err := us.GetReplica().SelectBuilder(&users, query); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Users")
|
||||
}
|
||||
|
||||
@@ -790,7 +790,7 @@ func (us SqlUserStore) GetProfilesInChannelByStatus(options *model.UserGetOption
|
||||
}
|
||||
|
||||
users := []*model.User{}
|
||||
if err := us.GetReplicaX().SelectBuilder(&users, query); err != nil {
|
||||
if err := us.GetReplica().SelectBuilder(&users, query); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Users")
|
||||
}
|
||||
|
||||
@@ -821,7 +821,7 @@ func (us SqlUserStore) GetProfilesInChannelByAdmin(options *model.UserGetOptions
|
||||
}
|
||||
|
||||
users := []*model.User{}
|
||||
if err := us.GetReplicaX().Select(&users, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Select(&users, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Users")
|
||||
}
|
||||
|
||||
@@ -903,7 +903,7 @@ func (us SqlUserStore) GetProfilesNotInChannel(teamId string, channelId string,
|
||||
}
|
||||
|
||||
users := []*model.User{}
|
||||
if err := us.GetReplicaX().Select(&users, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Select(&users, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Users")
|
||||
}
|
||||
|
||||
@@ -945,7 +945,7 @@ func (us SqlUserStore) GetProfilesWithoutTeam(options *model.UserGetOptions) ([]
|
||||
}
|
||||
|
||||
users := []*model.User{}
|
||||
if err := us.GetReplicaX().Select(&users, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Select(&users, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Users")
|
||||
}
|
||||
|
||||
@@ -973,7 +973,7 @@ func (us SqlUserStore) GetProfilesByUsernames(usernames []string, viewRestrictio
|
||||
}
|
||||
|
||||
users := []*model.User{}
|
||||
if err := us.GetReplicaX().Select(&users, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Select(&users, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Users")
|
||||
}
|
||||
|
||||
@@ -1002,7 +1002,7 @@ func (us SqlUserStore) GetRecentlyActiveUsersForTeam(teamId string, offset, limi
|
||||
}
|
||||
|
||||
users := []*UserWithLastActivityAt{}
|
||||
if err := us.GetReplicaX().Select(&users, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Select(&users, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Users")
|
||||
}
|
||||
|
||||
@@ -1033,7 +1033,7 @@ func (us SqlUserStore) GetNewUsersForTeam(teamId string, offset, limit int, view
|
||||
}
|
||||
|
||||
users := []*model.User{}
|
||||
if err := us.GetReplicaX().Select(&users, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Select(&users, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Users")
|
||||
}
|
||||
|
||||
@@ -1114,7 +1114,7 @@ func (us SqlUserStore) GetProfileByGroupChannelIdsForUser(userId string, channel
|
||||
}
|
||||
|
||||
usersWithChannel := []*UserWithChannel{}
|
||||
if err := us.GetReplicaX().Select(&usersWithChannel, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Select(&usersWithChannel, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Users")
|
||||
}
|
||||
|
||||
@@ -1141,7 +1141,7 @@ func (us SqlUserStore) GetSystemAdminProfiles() (map[string]*model.User, error)
|
||||
}
|
||||
|
||||
users := []*model.User{}
|
||||
if err := us.GetReplicaX().Select(&users, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Select(&users, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Users")
|
||||
}
|
||||
|
||||
@@ -1164,7 +1164,7 @@ func (us SqlUserStore) GetByEmail(email string) (*model.User, error) {
|
||||
}
|
||||
|
||||
user := model.User{}
|
||||
if err := us.GetReplicaX().Get(&user, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Get(&user, queryString, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, errors.Wrap(store.NewErrNotFound("User", fmt.Sprintf("email=%s", email)), "failed to find User")
|
||||
}
|
||||
@@ -1184,7 +1184,7 @@ func (us SqlUserStore) GetByRemoteID(remoteID string) (*model.User, error) {
|
||||
}
|
||||
|
||||
user := model.User{}
|
||||
if err := us.GetReplicaX().Get(&user, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Get(&user, queryString, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, errors.Wrap(store.NewErrNotFound("User", fmt.Sprintf("remoteid=%s", remoteID)), "failed to find User")
|
||||
}
|
||||
@@ -1210,7 +1210,7 @@ func (us SqlUserStore) GetByAuth(authData *string, authService string) (*model.U
|
||||
}
|
||||
|
||||
user := model.User{}
|
||||
if err := us.GetReplicaX().Get(&user, queryString, args...); err == sql.ErrNoRows {
|
||||
if err := us.GetReplica().Get(&user, queryString, args...); err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("User", fmt.Sprintf("authData=%s, authService=%s", *authData, authService))
|
||||
} else if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find User with authData=%s and authService=%s", *authData, authService)
|
||||
@@ -1229,7 +1229,7 @@ func (us SqlUserStore) GetAllUsingAuthService(authService string) ([]*model.User
|
||||
}
|
||||
|
||||
users := []*model.User{}
|
||||
if err := us.GetReplicaX().Select(&users, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Select(&users, queryString, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Users with authService=%s", authService)
|
||||
}
|
||||
|
||||
@@ -1247,7 +1247,7 @@ func (us SqlUserStore) GetAllNotInAuthService(authServices []string) ([]*model.U
|
||||
}
|
||||
|
||||
users := []*model.User{}
|
||||
if err := us.GetReplicaX().Select(&users, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Select(&users, queryString, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Users with authServices in %v", authServices)
|
||||
}
|
||||
|
||||
@@ -1263,7 +1263,7 @@ func (us SqlUserStore) GetByUsername(username string) (*model.User, error) {
|
||||
}
|
||||
|
||||
user := model.User{}
|
||||
if err := us.GetReplicaX().Get(&user, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Get(&user, queryString, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, errors.Wrap(store.NewErrNotFound("User", fmt.Sprintf("username=%s", username)), "failed to find User")
|
||||
}
|
||||
@@ -1292,7 +1292,7 @@ func (us SqlUserStore) GetForLogin(loginId string, allowSignInWithUsername, allo
|
||||
}
|
||||
|
||||
users := []*model.User{}
|
||||
if err := us.GetReplicaX().Select(&users, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Select(&users, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Users")
|
||||
}
|
||||
|
||||
@@ -1309,7 +1309,7 @@ func (us SqlUserStore) GetForLogin(loginId string, allowSignInWithUsername, allo
|
||||
|
||||
func (us SqlUserStore) VerifyEmail(userId, email string) (string, error) {
|
||||
curTime := model.GetMillis()
|
||||
if _, err := us.GetMasterX().Exec("UPDATE Users SET Email = lower(?), EmailVerified = true, UpdateAt = ? WHERE Id = ?", email, curTime, userId); err != nil {
|
||||
if _, err := us.GetMaster().Exec("UPDATE Users SET Email = lower(?), EmailVerified = true, UpdateAt = ? WHERE Id = ?", email, curTime, userId); err != nil {
|
||||
return "", errors.Wrapf(err, "failed to update Users with userId=%s and email=%s", userId, email)
|
||||
}
|
||||
|
||||
@@ -1317,7 +1317,7 @@ func (us SqlUserStore) VerifyEmail(userId, email string) (string, error) {
|
||||
}
|
||||
|
||||
func (us SqlUserStore) PermanentDelete(rctx request.CTX, userId string) error {
|
||||
if _, err := us.GetMasterX().Exec("DELETE FROM Users WHERE Id = ?", userId); err != nil {
|
||||
if _, err := us.GetMaster().Exec("DELETE FROM Users WHERE Id = ?", userId); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete User with userId=%s", userId)
|
||||
}
|
||||
return nil
|
||||
@@ -1370,7 +1370,7 @@ func (us SqlUserStore) Count(options model.UserCountOptions) (int64, error) {
|
||||
}
|
||||
|
||||
var count int64
|
||||
err = us.GetReplicaX().Get(&count, queryString, args...)
|
||||
err = us.GetReplica().Get(&count, queryString, args...)
|
||||
if err != nil {
|
||||
return int64(0), errors.Wrap(err, "failed to count Users")
|
||||
}
|
||||
@@ -1407,7 +1407,7 @@ func (us SqlUserStore) AnalyticsActiveCount(timePeriod int64, options model.User
|
||||
}
|
||||
|
||||
var v int64
|
||||
err = us.GetReplicaX().Get(&v, queryStr, args...)
|
||||
err = us.GetReplica().Get(&v, queryStr, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count Users")
|
||||
}
|
||||
@@ -1443,7 +1443,7 @@ func (us SqlUserStore) AnalyticsActiveCountForPeriod(startTime int64, endTime in
|
||||
}
|
||||
|
||||
var v int64
|
||||
err = us.GetReplicaX().Get(&v, queryStr, args...)
|
||||
err = us.GetReplica().Get(&v, queryStr, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "Unable to get the active users during the requested period.")
|
||||
}
|
||||
@@ -1466,7 +1466,7 @@ func (us SqlUserStore) GetUnreadCount(userId string, isCRTEnabled bool) (int64,
|
||||
`
|
||||
|
||||
var count int64
|
||||
err := us.GetReplicaX().Get(&count, query, userId)
|
||||
err := us.GetReplica().Get(&count, query, userId)
|
||||
if err != nil {
|
||||
return count, errors.Wrapf(err, "failed to count unread Channels for userId=%s", userId)
|
||||
}
|
||||
@@ -1476,7 +1476,7 @@ func (us SqlUserStore) GetUnreadCount(userId string, isCRTEnabled bool) (int64,
|
||||
|
||||
func (us SqlUserStore) GetUnreadCountForChannel(userId string, channelId string) (int64, error) {
|
||||
var count int64
|
||||
err := us.GetReplicaX().Get(&count, "SELECT SUM(CASE WHEN c.Type = ? THEN (c.TotalMsgCount - cm.MsgCount) ELSE cm.MentionCount END) FROM Channels c INNER JOIN ChannelMembers cm ON c.Id = cm.ChannelId AND cm.ChannelId = ? AND cm.UserId = ?", model.ChannelTypeDirect, channelId, userId)
|
||||
err := us.GetReplica().Get(&count, "SELECT SUM(CASE WHEN c.Type = ? THEN (c.TotalMsgCount - cm.MsgCount) ELSE cm.MentionCount END) FROM Channels c INNER JOIN ChannelMembers cm ON c.Id = cm.ChannelId AND cm.ChannelId = ? AND cm.UserId = ?", model.ChannelTypeDirect, channelId, userId)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "failed to get unread count for channelId=%s and userId=%s", channelId, userId)
|
||||
}
|
||||
@@ -1485,7 +1485,7 @@ func (us SqlUserStore) GetUnreadCountForChannel(userId string, channelId string)
|
||||
|
||||
func (us SqlUserStore) GetAnyUnreadPostCountForChannel(userId string, channelId string) (int64, error) {
|
||||
var count int64
|
||||
err := us.GetReplicaX().Get(&count, "SELECT SUM(c.TotalMsgCount - cm.MsgCount) FROM Channels c INNER JOIN ChannelMembers cm ON c.Id = cm.ChannelId AND cm.ChannelId = ? AND cm.UserId = ?", channelId, userId)
|
||||
err := us.GetReplica().Get(&count, "SELECT SUM(c.TotalMsgCount - cm.MsgCount) FROM Channels c INNER JOIN ChannelMembers cm ON c.Id = cm.ChannelId AND cm.ChannelId = ? AND cm.UserId = ?", channelId, userId)
|
||||
if err != nil {
|
||||
return count, errors.Wrapf(err, "failed to get any unread count for channelId=%s and userId=%s", channelId, userId)
|
||||
}
|
||||
@@ -1639,7 +1639,7 @@ func (us SqlUserStore) performSearch(query sq.SelectBuilder, term string, option
|
||||
}
|
||||
|
||||
users := []*model.User{}
|
||||
if err := us.GetReplicaX().Select(&users, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Select(&users, queryString, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Users with term=%s and searchType=%v", term, searchType)
|
||||
}
|
||||
for _, u := range users {
|
||||
@@ -1670,7 +1670,7 @@ func (us SqlUserStore) AnalyticsGetInactiveUsersCount() (int64, error) {
|
||||
if err != nil {
|
||||
return int64(0), errors.Wrap(err, "failed to create a SQL query to count inactive users")
|
||||
}
|
||||
err = us.GetReplicaX().Get(&count, queryStr, args...)
|
||||
err = us.GetReplica().Get(&count, queryStr, args...)
|
||||
|
||||
if err != nil {
|
||||
return int64(0), errors.Wrap(err, "failed to count inactive Users")
|
||||
@@ -1680,7 +1680,7 @@ func (us SqlUserStore) AnalyticsGetInactiveUsersCount() (int64, error) {
|
||||
|
||||
func (us SqlUserStore) AnalyticsGetExternalUsers(hostDomain string) (bool, error) {
|
||||
var count int64
|
||||
err := us.GetReplicaX().Get(&count, "SELECT COUNT(Id) FROM Users WHERE LOWER(Email) NOT LIKE ?", "%@"+strings.ToLower(hostDomain))
|
||||
err := us.GetReplica().Get(&count, "SELECT COUNT(Id) FROM Users WHERE LOWER(Email) NOT LIKE ?", "%@"+strings.ToLower(hostDomain))
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "failed to count inactive Users")
|
||||
}
|
||||
@@ -1689,7 +1689,7 @@ func (us SqlUserStore) AnalyticsGetExternalUsers(hostDomain string) (bool, error
|
||||
|
||||
func (us SqlUserStore) AnalyticsGetGuestCount() (int64, error) {
|
||||
var count int64
|
||||
err := us.GetReplicaX().Get(&count, "SELECT count(*) FROM Users WHERE Roles LIKE ? and DeleteAt = 0", "%system_guest%")
|
||||
err := us.GetReplica().Get(&count, "SELECT count(*) FROM Users WHERE Roles LIKE ? and DeleteAt = 0", "%system_guest%")
|
||||
if err != nil {
|
||||
return int64(0), errors.Wrap(err, "failed to count guest Users")
|
||||
}
|
||||
@@ -1698,7 +1698,7 @@ func (us SqlUserStore) AnalyticsGetGuestCount() (int64, error) {
|
||||
|
||||
func (us SqlUserStore) AnalyticsGetSystemAdminCount() (int64, error) {
|
||||
var count int64
|
||||
err := us.GetReplicaX().Get(&count, "SELECT count(*) FROM Users WHERE Roles LIKE ? and DeleteAt = 0", "%system_admin%")
|
||||
err := us.GetReplica().Get(&count, "SELECT count(*) FROM Users WHERE Roles LIKE ? and DeleteAt = 0", "%system_admin%")
|
||||
if err != nil {
|
||||
return int64(0), errors.Wrap(err, "failed to count system admin Users")
|
||||
}
|
||||
@@ -1724,7 +1724,7 @@ func (us SqlUserStore) GetProfilesNotInTeam(teamId string, groupConstrained bool
|
||||
return nil, errors.Wrap(err, "get_profiles_not_in_team_tosql")
|
||||
}
|
||||
|
||||
if err := us.GetReplicaX().Select(&users, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Select(&users, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Users")
|
||||
}
|
||||
|
||||
@@ -1748,7 +1748,7 @@ func (us SqlUserStore) GetEtagForProfilesNotInTeam(teamId string) string {
|
||||
tm.UserId IS NULL
|
||||
`
|
||||
var etag string
|
||||
err := us.GetReplicaX().Get(&etag, querystr, teamId)
|
||||
err := us.GetReplica().Get(&etag, querystr, teamId)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("%v.%v", model.CurrentVersion, model.GetMillis())
|
||||
}
|
||||
@@ -1764,7 +1764,7 @@ func (us SqlUserStore) ClearAllCustomRoleAssignments() (err error) {
|
||||
var transaction *sqlxTxWrapper
|
||||
var err error
|
||||
|
||||
if transaction, err = us.GetMasterX().Beginx(); err != nil {
|
||||
if transaction, err = us.GetMaster().Beginx(); err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
defer finalizeTransactionX(transaction, &err)
|
||||
@@ -1810,7 +1810,7 @@ func (us SqlUserStore) ClearAllCustomRoleAssignments() (err error) {
|
||||
|
||||
func (us SqlUserStore) InferSystemInstallDate() (int64, error) {
|
||||
var createAt int64
|
||||
err := us.GetReplicaX().Get(&createAt, "SELECT CreateAt FROM Users WHERE CreateAt IS NOT NULL ORDER BY CreateAt ASC LIMIT 1")
|
||||
err := us.GetReplica().Get(&createAt, "SELECT CreateAt FROM Users WHERE CreateAt IS NOT NULL ORDER BY CreateAt ASC LIMIT 1")
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to infer system install date")
|
||||
}
|
||||
@@ -1945,7 +1945,7 @@ func (us SqlUserStore) GetTeamGroupUsers(teamID string) ([]*model.User, error) {
|
||||
}
|
||||
|
||||
users := []*model.User{}
|
||||
if err := us.GetReplicaX().Select(&users, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Select(&users, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Users")
|
||||
}
|
||||
|
||||
@@ -1965,7 +1965,7 @@ func (us SqlUserStore) GetChannelGroupUsers(channelID string) ([]*model.User, er
|
||||
}
|
||||
|
||||
users := []*model.User{}
|
||||
if err := us.GetReplicaX().Select(&users, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Select(&users, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Users")
|
||||
}
|
||||
|
||||
@@ -2010,7 +2010,7 @@ func applyViewRestrictionsFilter(query sq.SelectBuilder, restrictions *model.Vie
|
||||
}
|
||||
|
||||
func (us SqlUserStore) PromoteGuestToUser(userId string) (err error) {
|
||||
transaction, err := us.GetMasterX().Beginx()
|
||||
transaction, err := us.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -2079,7 +2079,7 @@ func (us SqlUserStore) PromoteGuestToUser(userId string) (err error) {
|
||||
}
|
||||
|
||||
func (us SqlUserStore) DemoteUserToGuest(userID string) (_ *model.User, err error) {
|
||||
transaction, err := us.GetMasterX().Beginx()
|
||||
transaction, err := us.GetMaster().Beginx()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
@@ -2216,7 +2216,7 @@ func (us SqlUserStore) IsEmpty(excludeBots bool) (bool, error) {
|
||||
return false, errors.Wrapf(err, "users_is_empty_to_sql")
|
||||
}
|
||||
|
||||
if err = us.GetReplicaX().Get(&hasRows, query, args...); err != nil {
|
||||
if err = us.GetReplica().Get(&hasRows, query, args...); err != nil {
|
||||
return false, errors.Wrap(err, "failed to check if table is empty")
|
||||
}
|
||||
return !hasRows, nil
|
||||
@@ -2246,7 +2246,7 @@ func (us SqlUserStore) GetUsersWithInvalidEmails(page int, perPage int, restrict
|
||||
}
|
||||
|
||||
users := []*model.User{}
|
||||
if err := us.GetReplicaX().Select(&users, queryString, args...); err != nil {
|
||||
if err := us.GetReplica().Select(&users, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "users_get_many_select")
|
||||
}
|
||||
|
||||
@@ -2259,7 +2259,7 @@ func (us SqlUserStore) GetUsersWithInvalidEmails(page int, perPage int, restrict
|
||||
|
||||
func (us SqlUserStore) RefreshPostStatsForUsers() error {
|
||||
if us.DriverName() == model.DatabaseDriverPostgres {
|
||||
if _, err := us.GetMasterX().Exec("REFRESH MATERIALIZED VIEW poststats"); err != nil {
|
||||
if _, err := us.GetMaster().Exec("REFRESH MATERIALIZED VIEW poststats"); err != nil {
|
||||
return errors.Wrap(err, "users_refresh_post_stats_exec")
|
||||
}
|
||||
} else {
|
||||
@@ -2309,7 +2309,7 @@ func (us SqlUserStore) GetUserCountForReport(filter *model.UserReportOptions) (i
|
||||
return 0, errors.Wrap(err, "user_count_report_tosql")
|
||||
}
|
||||
var v int64
|
||||
err = us.GetReplicaX().Get(&v, queryStr, args...)
|
||||
err = us.GetReplica().Get(&v, queryStr, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count Users for report")
|
||||
}
|
||||
@@ -2409,7 +2409,7 @@ func (us SqlUserStore) GetUserReport(filter *model.UserReportOptions) ([]*model.
|
||||
}
|
||||
|
||||
userResults := []*model.UserReportQuery{}
|
||||
err := us.GetReplicaX().SelectBuilder(&userResults, parentQuery)
|
||||
err := us.GetReplica().SelectBuilder(&userResults, parentQuery)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get users for reporting")
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ func (s SqlUserTermsOfServiceStore) GetByUser(userId string) (*model.UserTermsOf
|
||||
FROM UserTermsOfService
|
||||
WHERE UserId = ?
|
||||
`
|
||||
if err := s.GetReplicaX().Get(&userTermsOfService, query, userId); err != nil {
|
||||
if err := s.GetReplica().Get(&userTermsOfService, query, userId); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("UserTermsOfService", "userId="+userId)
|
||||
}
|
||||
@@ -49,7 +49,7 @@ func (s SqlUserTermsOfServiceStore) Save(userTermsOfService *model.UserTermsOfSe
|
||||
SET UserId = :UserId, TermsOfServiceId = :TermsOfServiceId, CreateAt = :CreateAt
|
||||
WHERE UserId = :UserId
|
||||
`
|
||||
result, err := s.GetMasterX().NamedExec(query, userTermsOfService)
|
||||
result, err := s.GetMaster().NamedExec(query, userTermsOfService)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to update UserTermsOfService with userId=%s and termsOfServiceId=%s", userTermsOfService.UserId, userTermsOfService.TermsOfServiceId)
|
||||
}
|
||||
@@ -65,7 +65,7 @@ func (s SqlUserTermsOfServiceStore) Save(userTermsOfService *model.UserTermsOfSe
|
||||
VALUES
|
||||
(:UserId, :TermsOfServiceId, :CreateAt)
|
||||
`
|
||||
if _, err := s.GetMasterX().NamedExec(query, userTermsOfService); err != nil {
|
||||
if _, err := s.GetMaster().NamedExec(query, userTermsOfService); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to save UserTermsOfService with userId=%s and termsOfServiceId=%s", userTermsOfService.UserId, userTermsOfService.TermsOfServiceId)
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func (s SqlUserTermsOfServiceStore) Delete(userId, termsOfServiceId string) erro
|
||||
FROM UserTermsOfService
|
||||
WHERE UserId = ? AND TermsOfServiceId = ?
|
||||
`
|
||||
if _, err := s.GetMasterX().Exec(query, userId, termsOfServiceId); err != nil {
|
||||
if _, err := s.GetMaster().Exec(query, userId, termsOfServiceId); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete UserTermsOfService with userId=%s and termsOfServiceId=%s", userId, termsOfServiceId)
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ func (s SqlWebhookStore) SaveIncoming(webhook *model.IncomingWebhook) (*model.In
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().NamedExec(`INSERT INTO IncomingWebhooks
|
||||
if _, err := s.GetMaster().NamedExec(`INSERT INTO IncomingWebhooks
|
||||
(Id, CreateAt, UpdateAt, DeleteAt, UserId, ChannelId, TeamId, DisplayName, Description, Username, IconURL, ChannelLocked)
|
||||
VALUES
|
||||
(:Id, :CreateAt, :UpdateAt, :DeleteAt, :UserId, :ChannelId, :TeamId, :DisplayName, :Description, :Username, :IconURL, :ChannelLocked)`, webhook); err != nil {
|
||||
@@ -55,7 +55,7 @@ func (s SqlWebhookStore) SaveIncoming(webhook *model.IncomingWebhook) (*model.In
|
||||
func (s SqlWebhookStore) UpdateIncoming(hook *model.IncomingWebhook) (*model.IncomingWebhook, error) {
|
||||
hook.UpdateAt = model.GetMillis()
|
||||
|
||||
_, err := s.GetMasterX().NamedExec(`UPDATE IncomingWebhooks SET
|
||||
_, err := s.GetMaster().NamedExec(`UPDATE IncomingWebhooks SET
|
||||
CreateAt=:CreateAt, UpdateAt=:UpdateAt, DeleteAt=:DeleteAt, ChannelId=:ChannelId, TeamId=:TeamId, DisplayName=:DisplayName,
|
||||
Description=:Description, Username=:Username, IconURL=:IconURL, ChannelLocked=:ChannelLocked
|
||||
WHERE Id=:Id`, hook)
|
||||
@@ -68,7 +68,7 @@ func (s SqlWebhookStore) UpdateIncoming(hook *model.IncomingWebhook) (*model.Inc
|
||||
|
||||
func (s SqlWebhookStore) GetIncoming(id string, allowFromCache bool) (*model.IncomingWebhook, error) {
|
||||
var webhook model.IncomingWebhook
|
||||
if err := s.GetReplicaX().Get(&webhook, "SELECT * FROM IncomingWebhooks WHERE Id = ? AND DeleteAt = 0", id); err != nil {
|
||||
if err := s.GetReplica().Get(&webhook, "SELECT * FROM IncomingWebhooks WHERE Id = ? AND DeleteAt = 0", id); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("IncomingWebhook", id)
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func (s SqlWebhookStore) GetIncoming(id string, allowFromCache bool) (*model.Inc
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) DeleteIncoming(webhookId string, time int64) error {
|
||||
_, err := s.GetMasterX().Exec("UPDATE IncomingWebhooks SET DeleteAt = ?, UpdateAt = ? WHERE Id = ?", time, time, webhookId)
|
||||
_, err := s.GetMaster().Exec("UPDATE IncomingWebhooks SET DeleteAt = ?, UpdateAt = ? WHERE Id = ?", time, time, webhookId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to update IncomingWebhook with id=%s", webhookId)
|
||||
}
|
||||
@@ -88,7 +88,7 @@ func (s SqlWebhookStore) DeleteIncoming(webhookId string, time int64) error {
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) PermanentDeleteIncomingByUser(userId string) error {
|
||||
_, err := s.GetMasterX().Exec("DELETE FROM IncomingWebhooks WHERE UserId = ?", userId)
|
||||
_, err := s.GetMaster().Exec("DELETE FROM IncomingWebhooks WHERE UserId = ?", userId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete IncomingWebhook with userId=%s", userId)
|
||||
}
|
||||
@@ -97,7 +97,7 @@ func (s SqlWebhookStore) PermanentDeleteIncomingByUser(userId string) error {
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) PermanentDeleteIncomingByChannel(channelId string) error {
|
||||
_, err := s.GetMasterX().Exec("DELETE FROM IncomingWebhooks WHERE ChannelId = ?", channelId)
|
||||
_, err := s.GetMaster().Exec("DELETE FROM IncomingWebhooks WHERE ChannelId = ?", channelId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete IncomingWebhook with channelId=%s", channelId)
|
||||
}
|
||||
@@ -126,7 +126,7 @@ func (s SqlWebhookStore) GetIncomingListByUser(userId string, offset, limit int)
|
||||
return nil, errors.Wrap(err, "incoming_webhook_tosql")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Select(&webhooks, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&webhooks, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find IncomingWebhooks")
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ func (s SqlWebhookStore) GetIncomingByTeamByUser(teamId string, userId string, o
|
||||
return nil, errors.Wrap(err, "incoming_webhook_tosql")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Select(&webhooks, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&webhooks, queryString, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find IncomingWebhook with teamId=%s", teamId)
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ func (s SqlWebhookStore) GetIncomingByTeam(teamId string, offset, limit int) ([]
|
||||
func (s SqlWebhookStore) GetIncomingByChannel(channelId string) ([]*model.IncomingWebhook, error) {
|
||||
webhooks := []*model.IncomingWebhook{}
|
||||
|
||||
if err := s.GetReplicaX().Select(&webhooks, "SELECT * FROM IncomingWebhooks WHERE ChannelId = ? AND DeleteAt = 0", channelId); err != nil {
|
||||
if err := s.GetReplica().Select(&webhooks, "SELECT * FROM IncomingWebhooks WHERE ChannelId = ? AND DeleteAt = 0", channelId); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find IncomingWebhooks with channelId=%s", channelId)
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ func (s SqlWebhookStore) SaveOutgoing(webhook *model.OutgoingWebhook) (*model.Ou
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := s.GetMasterX().NamedExec(`INSERT INTO OutgoingWebhooks
|
||||
if _, err := s.GetMaster().NamedExec(`INSERT INTO OutgoingWebhooks
|
||||
(Id, Token, CreateAt, UpdateAt, DeleteAt, CreatorId, ChannelId, TeamId, TriggerWords, TriggerWhen,
|
||||
CallbackURLs, DisplayName, Description, ContentType, Username, IconURL)
|
||||
VALUES
|
||||
@@ -199,7 +199,7 @@ func (s SqlWebhookStore) SaveOutgoing(webhook *model.OutgoingWebhook) (*model.Ou
|
||||
func (s SqlWebhookStore) GetOutgoing(id string) (*model.OutgoingWebhook, error) {
|
||||
var webhook model.OutgoingWebhook
|
||||
|
||||
if err := s.GetReplicaX().Get(&webhook, "SELECT * FROM OutgoingWebhooks WHERE Id = ? AND DeleteAt = 0", id); err != nil {
|
||||
if err := s.GetReplica().Get(&webhook, "SELECT * FROM OutgoingWebhooks WHERE Id = ? AND DeleteAt = 0", id); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("OutgoingWebhook", id)
|
||||
}
|
||||
@@ -229,7 +229,7 @@ func (s SqlWebhookStore) GetOutgoingListByUser(userId string, offset, limit int)
|
||||
return nil, errors.Wrap(err, "outgoing_webhook_tosql")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Select(&webhooks, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&webhooks, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find OutgoingWebhooks")
|
||||
}
|
||||
|
||||
@@ -263,7 +263,7 @@ func (s SqlWebhookStore) GetOutgoingByChannelByUser(channelId string, userId str
|
||||
return nil, errors.Wrap(err, "outgoing_webhook_tosql")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Select(&webhooks, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&webhooks, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find OutgoingWebhooks")
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ func (s SqlWebhookStore) GetOutgoingByTeamByUser(teamId string, userId string, o
|
||||
return nil, errors.Wrap(err, "outgoing_webhook_tosql")
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Select(&webhooks, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Select(&webhooks, queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find OutgoingWebhooks")
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ func (s SqlWebhookStore) GetOutgoingByTeam(teamId string, offset, limit int) ([]
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) DeleteOutgoing(webhookId string, time int64) error {
|
||||
_, err := s.GetMasterX().Exec("Update OutgoingWebhooks SET DeleteAt = ?, UpdateAt = ? WHERE Id = ?", time, time, webhookId)
|
||||
_, err := s.GetMaster().Exec("Update OutgoingWebhooks SET DeleteAt = ?, UpdateAt = ? WHERE Id = ?", time, time, webhookId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to update OutgoingWebhook with id=%s", webhookId)
|
||||
}
|
||||
@@ -318,7 +318,7 @@ func (s SqlWebhookStore) DeleteOutgoing(webhookId string, time int64) error {
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) PermanentDeleteOutgoingByUser(userId string) error {
|
||||
_, err := s.GetMasterX().Exec("DELETE FROM OutgoingWebhooks WHERE CreatorId = ?", userId)
|
||||
_, err := s.GetMaster().Exec("DELETE FROM OutgoingWebhooks WHERE CreatorId = ?", userId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete OutgoingWebhook with creatorId=%s", userId)
|
||||
}
|
||||
@@ -327,7 +327,7 @@ func (s SqlWebhookStore) PermanentDeleteOutgoingByUser(userId string) error {
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) PermanentDeleteOutgoingByChannel(channelId string) error {
|
||||
_, err := s.GetMasterX().Exec("DELETE FROM OutgoingWebhooks WHERE ChannelId = ?", channelId)
|
||||
_, err := s.GetMaster().Exec("DELETE FROM OutgoingWebhooks WHERE ChannelId = ?", channelId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to delete OutgoingWebhook with channelId=%s", channelId)
|
||||
}
|
||||
@@ -340,7 +340,7 @@ func (s SqlWebhookStore) PermanentDeleteOutgoingByChannel(channelId string) erro
|
||||
func (s SqlWebhookStore) UpdateOutgoing(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, error) {
|
||||
hook.UpdateAt = model.GetMillis()
|
||||
|
||||
_, err := s.GetMasterX().NamedExec(`UPDATE OutgoingWebhooks SET
|
||||
_, err := s.GetMaster().NamedExec(`UPDATE OutgoingWebhooks SET
|
||||
CreateAt = :CreateAt, UpdateAt = :UpdateAt, DeleteAt = :DeleteAt, Token = :Token, CreatorId = :CreatorId,
|
||||
ChannelId = :ChannelId, TeamId = :TeamId, TriggerWords = :TriggerWords, TriggerWhen = :TriggerWhen,
|
||||
CallbackURLs = :CallbackURLs, DisplayName = :DisplayName, Description = :Description,
|
||||
@@ -373,7 +373,7 @@ func (s SqlWebhookStore) AnalyticsIncomingCount(teamID string, userID string) (i
|
||||
}
|
||||
|
||||
var count int64
|
||||
if err := s.GetReplicaX().Get(&count, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&count, queryString, args...); err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count IncomingWebhooks")
|
||||
}
|
||||
return count, nil
|
||||
@@ -396,7 +396,7 @@ func (s SqlWebhookStore) AnalyticsOutgoingCount(teamId string) (int64, error) {
|
||||
}
|
||||
|
||||
var count int64
|
||||
if err := s.GetReplicaX().Get(&count, queryString, args...); err != nil {
|
||||
if err := s.GetReplica().Get(&count, queryString, args...); err != nil {
|
||||
return 0, errors.Wrap(err, "failed to count OutgoingWebhooks")
|
||||
}
|
||||
return count, nil
|
||||
|
||||
@@ -79,7 +79,7 @@ func testBotStoreGet(t *testing.T, rctx request.CTX, ss store.Store, s SqlStore)
|
||||
defer func() { require.NoError(t, ss.User().PermanentDelete(rctx, b2.UserId)) }()
|
||||
|
||||
// Artificially set b2.LastIconUpdate to NULL to verify handling of same.
|
||||
_, sqlErr := s.GetMasterX().Exec("UPDATE Bots SET LastIconUpdate = NULL WHERE UserId = '" + b2.UserId + "'")
|
||||
_, sqlErr := s.GetMaster().Exec("UPDATE Bots SET LastIconUpdate = NULL WHERE UserId = '" + b2.UserId + "'")
|
||||
require.NoError(t, sqlErr)
|
||||
|
||||
t.Run("get non-existent bot", func(t *testing.T) {
|
||||
@@ -167,7 +167,7 @@ func testBotStoreGetAll(t *testing.T, rctx request.CTX, ss store.Store, s SqlSto
|
||||
defer func() { require.NoError(t, ss.User().PermanentDelete(rctx, b2.UserId)) }()
|
||||
|
||||
// Artificially set b2.LastIconUpdate to NULL to verify handling of same.
|
||||
_, sqlErr := s.GetMasterX().Exec("UPDATE Bots SET LastIconUpdate = NULL WHERE UserId = '" + b2.UserId + "'")
|
||||
_, sqlErr := s.GetMaster().Exec("UPDATE Bots SET LastIconUpdate = NULL WHERE UserId = '" + b2.UserId + "'")
|
||||
require.NoError(t, sqlErr)
|
||||
|
||||
t.Run("get original bots", func(t *testing.T) {
|
||||
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
type SqlStore interface {
|
||||
GetMasterX() SqlXExecutor
|
||||
GetMaster() SqlXExecutor
|
||||
DriverName() string
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ func testChannelStoreSaveDirectChannel(t *testing.T, rctx request.CTX, ss store.
|
||||
require.ElementsMatch(t, []string{u1.Id}, userIDs)
|
||||
|
||||
// Manually truncate Channels table until testlib can handle cleanups
|
||||
s.GetMasterX().Exec("TRUNCATE Channels")
|
||||
s.GetMaster().Exec("TRUNCATE Channels")
|
||||
}
|
||||
|
||||
func testChannelStoreCreateDirectChannel(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
@@ -493,7 +493,7 @@ func testChannelStoreGet(t *testing.T, rctx request.CTX, ss store.Store, s SqlSt
|
||||
require.True(t, errors.As(err, &nfErr))
|
||||
|
||||
// Manually truncate Channels table until testlib can handle cleanups
|
||||
s.GetMasterX().Exec("TRUNCATE Channels")
|
||||
s.GetMaster().Exec("TRUNCATE Channels")
|
||||
}
|
||||
|
||||
func testChannelStoreGetMany(t *testing.T, rctx request.CTX, ss store.Store, s SqlStore) {
|
||||
@@ -527,7 +527,7 @@ func testChannelStoreGetMany(t *testing.T, rctx request.CTX, ss store.Store, s S
|
||||
require.True(t, errors.As(err, &nfErr))
|
||||
|
||||
// Manually truncate Channels table until testlib can handle cleanups
|
||||
s.GetMasterX().Exec("TRUNCATE Channels")
|
||||
s.GetMaster().Exec("TRUNCATE Channels")
|
||||
}
|
||||
|
||||
func testChannelStoreGetChannelsByIds(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
@@ -4006,7 +4006,7 @@ func testChannelStoreGetAllChannels(t *testing.T, rctx request.CTX, ss store.Sto
|
||||
assert.Equal(t, *list[0].PolicyID, policy.ID)
|
||||
|
||||
// Manually truncate Channels table until testlib can handle cleanups
|
||||
s.GetMasterX().Exec("TRUNCATE Channels")
|
||||
s.GetMaster().Exec("TRUNCATE Channels")
|
||||
}
|
||||
|
||||
func testChannelStoreGetMoreChannels(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
@@ -5774,8 +5774,8 @@ func testChannelStoreSearchArchivedInTeam(t *testing.T, rctx request.CTX, ss sto
|
||||
|
||||
t.Run("error", func(t *testing.T) {
|
||||
// trigger a SQL error
|
||||
s.GetMasterX().Exec("ALTER TABLE Channels RENAME TO Channels_renamed")
|
||||
defer s.GetMasterX().Exec("ALTER TABLE Channels_renamed RENAME TO Channels")
|
||||
s.GetMaster().Exec("ALTER TABLE Channels RENAME TO Channels_renamed")
|
||||
defer s.GetMaster().Exec("ALTER TABLE Channels_renamed RENAME TO Channels")
|
||||
|
||||
list, err := ss.Channel().SearchArchivedInTeam(teamID, "term", userID)
|
||||
require.Error(t, err)
|
||||
@@ -6219,7 +6219,7 @@ func testAutocomplete(t *testing.T, rctx request.CTX, ss store.Store, s SqlStore
|
||||
})
|
||||
|
||||
// Manually truncate Channels table until testlib can handle cleanups
|
||||
s.GetMasterX().Exec("TRUNCATE Channels")
|
||||
s.GetMaster().Exec("TRUNCATE Channels")
|
||||
}
|
||||
|
||||
func testChannelStoreSearchForUserInTeam(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
@@ -7484,7 +7484,7 @@ func testMaterializedPublicChannels(t *testing.T, rctx request.CTX, ss store.Sto
|
||||
Type: model.ChannelTypeOpen,
|
||||
}
|
||||
|
||||
_, execerr := s.GetMasterX().NamedExec(`
|
||||
_, execerr := s.GetMaster().NamedExec(`
|
||||
INSERT INTO
|
||||
PublicChannels(Id, DeleteAt, TeamId, DisplayName, Name, Header, Purpose)
|
||||
VALUES
|
||||
@@ -7502,7 +7502,7 @@ func testMaterializedPublicChannels(t *testing.T, rctx request.CTX, ss store.Sto
|
||||
|
||||
o3.DisplayName = "Open Channel 3 - Modified"
|
||||
|
||||
_, execerr = s.GetMasterX().NamedExec(`
|
||||
_, execerr = s.GetMaster().NamedExec(`
|
||||
INSERT INTO
|
||||
Channels(Id, CreateAt, UpdateAt, DeleteAt, TeamId, Type, DisplayName, Name, Header, Purpose, LastPostAt, LastRootPostAt, TotalMsgCount, ExtraUpdateAt, CreatorId, TotalMsgCountRoot)
|
||||
VALUES
|
||||
@@ -7543,7 +7543,7 @@ func testMaterializedPublicChannels(t *testing.T, rctx request.CTX, ss store.Sto
|
||||
_, nErr = ss.Channel().Save(rctx, &o4, -1)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
_, execerr = s.GetMasterX().Exec(`
|
||||
_, execerr = s.GetMaster().Exec(`
|
||||
DELETE FROM
|
||||
PublicChannels
|
||||
WHERE
|
||||
@@ -7738,7 +7738,7 @@ func testChannelStoreRemoveAllDeactivatedMembers(t *testing.T, rctx request.CTX,
|
||||
require.ElementsMatch(t, []string{u3.Id}, userIDs)
|
||||
|
||||
// Manually truncate Channels table until testlib can handle cleanups
|
||||
s.GetMasterX().Exec("TRUNCATE Channels")
|
||||
s.GetMaster().Exec("TRUNCATE Channels")
|
||||
}
|
||||
|
||||
func testChannelStoreExportAllDirectChannels(t *testing.T, rctx request.CTX, ss store.Store, s SqlStore) {
|
||||
@@ -7795,7 +7795,7 @@ func testChannelStoreExportAllDirectChannels(t *testing.T, rctx request.CTX, ss
|
||||
assert.ElementsMatch(t, []string{o1.DisplayName, o2.DisplayName}, []string{d1[0].DisplayName, d1[1].DisplayName})
|
||||
|
||||
// Manually truncate Channels table until testlib can handle cleanups
|
||||
s.GetMasterX().Exec("TRUNCATE Channels")
|
||||
s.GetMaster().Exec("TRUNCATE Channels")
|
||||
}
|
||||
|
||||
func testChannelStoreExportAllDirectChannelsExcludePrivateAndPublic(t *testing.T, rctx request.CTX, ss store.Store, s SqlStore) {
|
||||
@@ -7857,7 +7857,7 @@ func testChannelStoreExportAllDirectChannelsExcludePrivateAndPublic(t *testing.T
|
||||
assert.Equal(t, o1.DisplayName, d1[0].DisplayName)
|
||||
|
||||
// Manually truncate Channels table until testlib can handle cleanups
|
||||
s.GetMasterX().Exec("TRUNCATE Channels")
|
||||
s.GetMaster().Exec("TRUNCATE Channels")
|
||||
}
|
||||
|
||||
func testChannelStoreExportAllDirectChannelsDeletedChannel(t *testing.T, rctx request.CTX, ss store.Store, s SqlStore) {
|
||||
@@ -7912,7 +7912,7 @@ func testChannelStoreExportAllDirectChannelsDeletedChannel(t *testing.T, rctx re
|
||||
assert.Len(t, d1[0].Members, 2)
|
||||
|
||||
// Manually truncate Channels table until testlib can handle cleanups
|
||||
s.GetMasterX().Exec("TRUNCATE Channels")
|
||||
s.GetMaster().Exec("TRUNCATE Channels")
|
||||
}
|
||||
|
||||
func testChannelStoreGetChannelsBatchForIndexing(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
|
||||
@@ -751,7 +751,7 @@ func testGetSidebarCategory(t *testing.T, rctx request.CTX, ss store.Store, s Sq
|
||||
|
||||
// Confirm that they're not in the Channels category in the DB
|
||||
var count int64
|
||||
countErr := s.GetMasterX().Get(&count, `
|
||||
countErr := s.GetMaster().Get(&count, `
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
@@ -2021,11 +2021,11 @@ func testClearSidebarOnTeamLeave(t *testing.T, rctx request.CTX, ss store.Store,
|
||||
|
||||
// Confirm that we start with the right number of categories and SidebarChannels entries
|
||||
var count int64
|
||||
err = s.GetMasterX().Get(&count, "SELECT COUNT(*) FROM SidebarCategories WHERE UserId = ?", userID)
|
||||
err = s.GetMaster().Get(&count, "SELECT COUNT(*) FROM SidebarCategories WHERE UserId = ?", userID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(4), count)
|
||||
|
||||
err = s.GetMasterX().Get(&count, "SELECT COUNT(*) FROM SidebarChannels WHERE UserId = ?", userID)
|
||||
err = s.GetMaster().Get(&count, "SELECT COUNT(*) FROM SidebarChannels WHERE UserId = ?", userID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(2), count)
|
||||
|
||||
@@ -2034,11 +2034,11 @@ func testClearSidebarOnTeamLeave(t *testing.T, rctx request.CTX, ss store.Store,
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Confirm that all the categories and SidebarChannel entries have been deleted
|
||||
err = s.GetMasterX().Get(&count, "SELECT COUNT(*) FROM SidebarCategories WHERE UserId = ?", userID)
|
||||
err = s.GetMaster().Get(&count, "SELECT COUNT(*) FROM SidebarCategories WHERE UserId = ?", userID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(0), count)
|
||||
|
||||
err = s.GetMasterX().Get(&count, "SELECT COUNT(*) FROM SidebarChannels WHERE UserId = ?", userID)
|
||||
err = s.GetMaster().Get(&count, "SELECT COUNT(*) FROM SidebarChannels WHERE UserId = ?", userID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(0), count)
|
||||
})
|
||||
@@ -2070,11 +2070,11 @@ func testClearSidebarOnTeamLeave(t *testing.T, rctx request.CTX, ss store.Store,
|
||||
|
||||
// Confirm that we start with the right number of categories and SidebarChannels entries
|
||||
var count int64
|
||||
err = s.GetMasterX().Get(&count, "SELECT COUNT(*) FROM SidebarCategories WHERE UserId = ?", userID)
|
||||
err = s.GetMaster().Get(&count, "SELECT COUNT(*) FROM SidebarCategories WHERE UserId = ?", userID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(4), count)
|
||||
|
||||
err = s.GetMasterX().Get(&count, "SELECT COUNT(*) FROM SidebarChannels WHERE UserId = ?", userID)
|
||||
err = s.GetMaster().Get(&count, "SELECT COUNT(*) FROM SidebarChannels WHERE UserId = ?", userID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(2), count)
|
||||
|
||||
@@ -2083,11 +2083,11 @@ func testClearSidebarOnTeamLeave(t *testing.T, rctx request.CTX, ss store.Store,
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Confirm that nothing has been deleted
|
||||
err = s.GetMasterX().Get(&count, "SELECT COUNT(*) FROM SidebarCategories WHERE UserId = ?", userID)
|
||||
err = s.GetMaster().Get(&count, "SELECT COUNT(*) FROM SidebarCategories WHERE UserId = ?", userID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(4), count)
|
||||
|
||||
err = s.GetMasterX().Get(&count, "SELECT COUNT(*) FROM SidebarChannels WHERE UserId = ?", userID)
|
||||
err = s.GetMaster().Get(&count, "SELECT COUNT(*) FROM SidebarChannels WHERE UserId = ?", userID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(2), count)
|
||||
})
|
||||
@@ -2148,11 +2148,11 @@ func testClearSidebarOnTeamLeave(t *testing.T, rctx request.CTX, ss store.Store,
|
||||
|
||||
// Confirm that we start with the right number of categories and SidebarChannels entries
|
||||
var count int64
|
||||
err = s.GetMasterX().Get(&count, "SELECT COUNT(*) FROM SidebarCategories WHERE UserId = ?", userID)
|
||||
err = s.GetMaster().Get(&count, "SELECT COUNT(*) FROM SidebarCategories WHERE UserId = ?", userID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(8), count)
|
||||
|
||||
err = s.GetMasterX().Get(&count, "SELECT COUNT(*) FROM SidebarChannels WHERE UserId = ?", userID)
|
||||
err = s.GetMaster().Get(&count, "SELECT COUNT(*) FROM SidebarChannels WHERE UserId = ?", userID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(4), count)
|
||||
|
||||
@@ -2161,11 +2161,11 @@ func testClearSidebarOnTeamLeave(t *testing.T, rctx request.CTX, ss store.Store,
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Confirm that we have the correct number of categories and SidebarChannels entries left over
|
||||
err = s.GetMasterX().Get(&count, "SELECT COUNT(*) FROM SidebarCategories WHERE UserId = ?", userID)
|
||||
err = s.GetMaster().Get(&count, "SELECT COUNT(*) FROM SidebarCategories WHERE UserId = ?", userID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(4), count)
|
||||
|
||||
err = s.GetMasterX().Get(&count, "SELECT COUNT(*) FROM SidebarChannels WHERE UserId = ?", userID)
|
||||
err = s.GetMaster().Get(&count, "SELECT COUNT(*) FROM SidebarChannels WHERE UserId = ?", userID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(2), count)
|
||||
|
||||
@@ -2259,7 +2259,7 @@ func testDeleteSidebarCategory(t *testing.T, rctx request.CTX, ss store.Store, s
|
||||
|
||||
// ...and that the corresponding SidebarChannel entries were deleted
|
||||
var count int64
|
||||
countErr := s.GetMasterX().Get(&count, `
|
||||
countErr := s.GetMaster().Get(&count, `
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
|
||||
func TestFileInfoStore(t *testing.T, rctx request.CTX, ss store.Store, s SqlStore) {
|
||||
t.Cleanup(func() {
|
||||
s.GetMasterX().Exec("TRUNCATE FileInfo")
|
||||
s.GetMaster().Exec("TRUNCATE FileInfo")
|
||||
})
|
||||
t.Run("FileInfoSaveGet", func(t *testing.T) { testFileInfoSaveGet(t, rctx, ss) })
|
||||
t.Run("FileInfoSaveGetByPath", func(t *testing.T) { testFileInfoSaveGetByPath(t, rctx, ss) })
|
||||
|
||||
@@ -3279,7 +3279,7 @@ func testPostStoreGetFlaggedPostsForTeam(t *testing.T, rctx request.CTX, ss stor
|
||||
require.Len(t, r4.Order, 3, "should have 3 posts")
|
||||
|
||||
// Manually truncate Channels table until testlib can handle cleanups
|
||||
s.GetMasterX().Exec("TRUNCATE Channels")
|
||||
s.GetMaster().Exec("TRUNCATE Channels")
|
||||
}
|
||||
|
||||
func testPostStoreGetFlaggedPosts(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
@@ -4550,7 +4550,7 @@ func testPostStoreGetDirectPostParentsForExportAfter(t *testing.T, rctx request.
|
||||
assert.Equal(t, p1.Message, r1[0].Message)
|
||||
|
||||
// Manually truncate Channels table until testlib can handle cleanups
|
||||
s.GetMasterX().Exec("TRUNCATE Channels")
|
||||
s.GetMaster().Exec("TRUNCATE Channels")
|
||||
}
|
||||
|
||||
func testPostStoreGetDirectPostParentsForExportAfterDeleted(t *testing.T, rctx request.CTX, ss store.Store, s SqlStore) {
|
||||
@@ -4613,7 +4613,7 @@ func testPostStoreGetDirectPostParentsForExportAfterDeleted(t *testing.T, rctx r
|
||||
assert.Equal(t, 1, len(r1))
|
||||
|
||||
// Manually truncate Channels table until testlib can handle cleanups
|
||||
s.GetMasterX().Exec("TRUNCATE Channels")
|
||||
s.GetMaster().Exec("TRUNCATE Channels")
|
||||
}
|
||||
|
||||
func testPostStoreGetDirectPostParentsForExportAfterBatched(t *testing.T, rctx request.CTX, ss store.Store, s SqlStore) {
|
||||
@@ -4689,7 +4689,7 @@ func testPostStoreGetDirectPostParentsForExportAfterBatched(t *testing.T, rctx r
|
||||
assert.ElementsMatch(t, postIds[:100], exportedPostIds)
|
||||
|
||||
// Manually truncate Channels table until testlib can handle cleanups
|
||||
s.GetMasterX().Exec("TRUNCATE Channels")
|
||||
s.GetMaster().Exec("TRUNCATE Channels")
|
||||
}
|
||||
|
||||
func testHasAutoResponsePostByUserSince(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
@@ -4827,7 +4827,7 @@ func testGetPostsSinceUpdateForSync(t *testing.T, rctx request.CTX, ss store.Sto
|
||||
|
||||
t.Run("UpdateAt collisions", func(t *testing.T) {
|
||||
// this test requires all the UpdateAt timestamps to be the same.
|
||||
result, err := s.GetMasterX().Exec("UPDATE Posts SET UpdateAt = ?", model.GetMillis())
|
||||
result, err := s.GetMaster().Exec("UPDATE Posts SET UpdateAt = ?", model.GetMillis())
|
||||
require.NoError(t, err)
|
||||
rows, err := result.RowsAffected()
|
||||
require.NoError(t, err)
|
||||
@@ -4934,7 +4934,7 @@ func testGetPostsSinceCreateForSync(t *testing.T, rctx request.CTX, ss store.Sto
|
||||
|
||||
t.Run("CreateAt collisions", func(t *testing.T) {
|
||||
// this test requires all the CreateAt timestamps to be the same.
|
||||
result, err := s.GetMasterX().Exec("UPDATE Posts SET CreateAt = ?", model.GetMillis())
|
||||
result, err := s.GetMaster().Exec("UPDATE Posts SET CreateAt = ?", model.GetMillis())
|
||||
require.NoError(t, err)
|
||||
rows, err := result.RowsAffected()
|
||||
require.NoError(t, err)
|
||||
@@ -4978,7 +4978,7 @@ func testSetPostReminder(t *testing.T, rctx request.CTX, ss store.Store, s SqlSt
|
||||
require.NoError(t, ss.Post().SetPostReminder(reminder))
|
||||
|
||||
out := model.PostReminder{}
|
||||
require.NoError(t, s.GetMasterX().Get(&out, `SELECT PostId, UserId, TargetTime FROM PostReminders WHERE PostId=? AND UserId=?`, reminder.PostId, reminder.UserId))
|
||||
require.NoError(t, s.GetMaster().Get(&out, `SELECT PostId, UserId, TargetTime FROM PostReminders WHERE PostId=? AND UserId=?`, reminder.PostId, reminder.UserId))
|
||||
assert.Equal(t, reminder, &out)
|
||||
|
||||
reminder.PostId = "notfound"
|
||||
@@ -4994,7 +4994,7 @@ func testSetPostReminder(t *testing.T, rctx request.CTX, ss store.Store, s SqlSt
|
||||
}
|
||||
|
||||
require.NoError(t, ss.Post().SetPostReminder(reminder))
|
||||
require.NoError(t, s.GetMasterX().Get(&out, `SELECT PostId, UserId, TargetTime FROM PostReminders WHERE PostId=? AND UserId=?`, reminder.PostId, reminder.UserId))
|
||||
require.NoError(t, s.GetMaster().Get(&out, `SELECT PostId, UserId, TargetTime FROM PostReminders WHERE PostId=? AND UserId=?`, reminder.PostId, reminder.UserId))
|
||||
assert.Equal(t, reminder, &out)
|
||||
}
|
||||
|
||||
|
||||
@@ -458,7 +458,7 @@ func testDeleteInvalidVisibleDmsGms(t *testing.T, rctx request.CTX, ss store.Sto
|
||||
}
|
||||
|
||||
// Can't insert with Save methods because the values are invalid
|
||||
_, execerr := s.GetMasterX().NamedExec(`
|
||||
_, execerr := s.GetMaster().NamedExec(`
|
||||
INSERT INTO
|
||||
Preferences(UserId, Category, Name, Value)
|
||||
VALUES
|
||||
|
||||
@@ -441,7 +441,7 @@ func forceUpdateAt(reaction *model.Reaction, updateAt int64, s SqlStore) error {
|
||||
"updateat": updateAt,
|
||||
}
|
||||
|
||||
sqlResult, err := s.GetMasterX().NamedExec(`
|
||||
sqlResult, err := s.GetMaster().NamedExec(`
|
||||
UPDATE
|
||||
Reactions
|
||||
SET
|
||||
@@ -468,10 +468,10 @@ func forceUpdateAt(reaction *model.Reaction, updateAt int64, s SqlStore) error {
|
||||
}
|
||||
|
||||
func forceNULL(reaction *model.Reaction, s SqlStore) error {
|
||||
if _, err := s.GetMasterX().Exec(`UPDATE Reactions SET UpdateAt = NULL WHERE UpdateAt = 0`); err != nil {
|
||||
if _, err := s.GetMaster().Exec(`UPDATE Reactions SET UpdateAt = NULL WHERE UpdateAt = 0`); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := s.GetMasterX().Exec(`UPDATE Reactions SET DeleteAt = NULL WHERE DeleteAt = 0`); err != nil {
|
||||
if _, err := s.GetMaster().Exec(`UPDATE Reactions SET DeleteAt = NULL WHERE DeleteAt = 0`); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -151,7 +151,7 @@ func cleanupRetentionPolicyTest(s SqlStore) {
|
||||
// Manually clear tables until testlib can handle cleanups
|
||||
tables := []string{"RetentionPolicies", "RetentionPoliciesChannels", "RetentionPoliciesTeams"}
|
||||
for _, table := range tables {
|
||||
if _, err := s.GetMasterX().Exec("DELETE FROM " + table); err != nil {
|
||||
if _, err := s.GetMaster().Exec("DELETE FROM " + table); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -581,7 +581,7 @@ func testRoleStoreChannelHigherScopedPermissionsBlankTeamSchemeChannelGuest(t *t
|
||||
require.NoError(t, err)
|
||||
|
||||
// blank-out the guest role to simulate an old team scheme, ensure it's blank
|
||||
result, sqlErr := s.GetMasterX().Exec(fmt.Sprintf("UPDATE Schemes SET DefaultChannelGuestRole = '' WHERE Id = '%s'", teamScheme.Id))
|
||||
result, sqlErr := s.GetMaster().Exec(fmt.Sprintf("UPDATE Schemes SET DefaultChannelGuestRole = '' WHERE Id = '%s'", teamScheme.Id))
|
||||
require.NoError(t, sqlErr)
|
||||
rows, serr := result.RowsAffected()
|
||||
require.NoError(t, serr)
|
||||
|
||||
@@ -654,7 +654,7 @@ func testThreadStorePermanentDeleteBatchThreadMembershipsForRetentionPolicies(t
|
||||
// Delete team policy and thread
|
||||
err = ss.RetentionPolicy().Delete(teamPolicy.ID)
|
||||
require.NoError(t, err)
|
||||
_, err = s.GetMasterX().Exec("DELETE FROM Threads WHERE PostId='" + post.Id + "'")
|
||||
_, err = s.GetMaster().Exec("DELETE FROM Threads WHERE PostId='" + post.Id + "'")
|
||||
require.NoError(t, err)
|
||||
|
||||
deleted, err := ss.Thread().DeleteOrphanedRows(1000)
|
||||
|
||||
@@ -28,7 +28,7 @@ const (
|
||||
)
|
||||
|
||||
func cleanupStatusStore(t *testing.T, s SqlStore) {
|
||||
_, execerr := s.GetMasterX().Exec(`DELETE FROM Status`)
|
||||
_, execerr := s.GetMaster().Exec(`DELETE FROM Status`)
|
||||
require.NoError(t, execerr)
|
||||
}
|
||||
|
||||
|
||||
@@ -222,7 +222,7 @@ func (h *MainHelper) PreloadMigrations() {
|
||||
panic(fmt.Errorf("cannot read file: %v", err))
|
||||
}
|
||||
}
|
||||
handle := h.SQLStore.GetMasterX()
|
||||
handle := h.SQLStore.GetMaster()
|
||||
_, err = handle.Exec(string(buf))
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "Error preloading migrations. Check if you have &multiStatements=true in your DSN if you are using MySQL. Or perhaps the schema changed? If yes, then update the warmup files accordingly"))
|
||||
|
||||
@@ -39,7 +39,7 @@ func setupConfigDatabase(t *testing.T, cfg *model.Config, files map[string][]byt
|
||||
|
||||
ds := &DatabaseStore{
|
||||
driverName: *mainHelper.GetSQLSettings().DriverName,
|
||||
db: mainHelper.GetSQLStore().GetMasterX().DB,
|
||||
db: mainHelper.GetSQLStore().GetMaster().DB,
|
||||
dataSourceName: *mainHelper.Settings.DataSource,
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ func getActualDatabaseConfig(t *testing.T) (string, *model.Config) {
|
||||
ID string `db:"id"`
|
||||
Value []byte `db:"value"`
|
||||
}
|
||||
err := mainHelper.GetSQLStore().GetMasterX().Get(&actual, "SELECT Id, Value FROM Configurations WHERE Active")
|
||||
err := mainHelper.GetSQLStore().GetMaster().Get(&actual, "SELECT Id, Value FROM Configurations WHERE Active")
|
||||
require.NoError(t, err)
|
||||
|
||||
var actualCfg *model.Config
|
||||
@@ -92,7 +92,7 @@ func getActualDatabaseConfig(t *testing.T) (string, *model.Config) {
|
||||
ID string `db:"Id"`
|
||||
Value []byte `db:"Value"`
|
||||
}
|
||||
err := mainHelper.GetSQLStore().GetMasterX().Get(&actual, "SELECT Id, Value FROM Configurations WHERE Active")
|
||||
err := mainHelper.GetSQLStore().GetMaster().Get(&actual, "SELECT Id, Value FROM Configurations WHERE Active")
|
||||
require.NoError(t, err)
|
||||
|
||||
var actualCfg *model.Config
|
||||
@@ -548,7 +548,7 @@ func TestDatabaseStoreSet(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
defer ds.Close()
|
||||
|
||||
_, err = mainHelper.GetSQLStore().GetMasterX().Exec("DROP TABLE Configurations")
|
||||
_, err = mainHelper.GetSQLStore().GetMaster().Exec("DROP TABLE Configurations")
|
||||
require.NoError(t, err)
|
||||
|
||||
newCfg := minimalConfig
|
||||
@@ -829,7 +829,7 @@ func TestDatabaseStoreLoad(t *testing.T) {
|
||||
|
||||
truncateTables(t)
|
||||
id := model.NewId()
|
||||
_, err = mainHelper.GetSQLStore().GetMasterX().NamedExec("INSERT INTO Configurations (Id, Value, CreateAt, Active) VALUES(:id, :value, :createat, TRUE)", map[string]any{
|
||||
_, err = mainHelper.GetSQLStore().GetMaster().NamedExec("INSERT INTO Configurations (Id, Value, CreateAt, Active) VALUES(:id, :value, :createat, TRUE)", map[string]any{
|
||||
"id": id,
|
||||
"value": cfgData,
|
||||
"createat": model.GetMillis(),
|
||||
|
||||
@@ -36,7 +36,7 @@ func truncateTable(t *testing.T, table string) {
|
||||
|
||||
switch *sqlSetting.DriverName {
|
||||
case model.DatabaseDriverMysql:
|
||||
_, err := sqlStore.GetMasterX().Exec(fmt.Sprintf("TRUNCATE TABLE %s", table))
|
||||
_, err := sqlStore.GetMaster().Exec(fmt.Sprintf("TRUNCATE TABLE %s", table))
|
||||
if err != nil {
|
||||
if driverErr, ok := err.(*mysql.MySQLError); ok {
|
||||
// Ignore if the Configurations table does not exist.
|
||||
@@ -48,7 +48,7 @@ func truncateTable(t *testing.T, table string) {
|
||||
require.NoError(t, err)
|
||||
|
||||
case model.DatabaseDriverPostgres:
|
||||
_, err := sqlStore.GetMasterX().Exec(fmt.Sprintf("TRUNCATE TABLE %s", table))
|
||||
_, err := sqlStore.GetMaster().Exec(fmt.Sprintf("TRUNCATE TABLE %s", table))
|
||||
if err != nil {
|
||||
if driverErr, ok := err.(*pq.Error); ok {
|
||||
// Ignore if the Configurations table does not exist.
|
||||
|
||||
Ссылка в новой задаче
Block a user