PLT-3105 Files table migration (#4068)

* Implemented initial changes for files table

* Removed *_benchmark_test.go files

* Re-implemented GetPublicFile and added support for old path

* Localization for files table

* Moved file system code into utils package

* Finished server-side changes and added initial upgrade script

* Added getPostFiles api

* Re-add Extension and HasPreviewImage fields to FileInfo

* Removed unused translation

* Fixed merge conflicts left over after permissions changes

* Forced FileInfo.extension to be lower case

* Changed FileUploadResponse to contain the FileInfos instead of FileIds

* Fixed permissions on getFile* calls

* Fixed notifications for file uploads

* Added initial version of client code for files changes

* Permanently added FileIds field to Post object and removed Post.HasFiles

* Updated PostStore.Update to be usable in more circumstances

* Re-added Filenames field and switched file migration to be entirely lazy-loaded

* Increased max listener count for FileStore

* Removed unused fileInfoCache

* Moved file system code back into api

* Removed duplicate test case

* Fixed unit test running on ports other than 8065

* Renamed HasPermissionToPostContext to HasPermissionToChannelByPostContext

* Refactored handleImages to make it more easily understandable

* Renamed getPostFiles to getFileInfosForPost

* Re-added pre-FileIds posts to analytics

* Changed files to be saved as their ids as opposed to id/filename.ext

* Renamed FileInfo.UserId to FileInfo.CreatorId

* Fixed detection of language in CodePreview

* Fixed switching between threads in the RHS not loading new files

* Add serverside protection against a rare bug where the client sends the same file twice for a single post

* Refactored the important parts of uploadFile api call into a function that can be called without a web context
Этот коммит содержится в:
Harrison Healey
2016-09-30 11:06:30 -04:00
коммит произвёл GitHub
родитель a2deeed597
Коммит 8a0e649f98
60 изменённых файлов: 3454 добавлений и 2062 удалений

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

@@ -596,6 +596,36 @@ func (s SqlChannelStore) GetMember(channelId string, userId string) StoreChannel
return storeChannel
}
func (s SqlChannelStore) GetMemberForPost(postId string, userId string) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
result := StoreResult{}
member := &model.ChannelMember{}
if err := s.GetReplica().SelectOne(
member,
`SELECT
ChannelMembers.*
FROM
ChannelMembers,
Posts
WHERE
ChannelMembers.ChannelId = Posts.ChannelId
AND ChannelMembers.UserId = :UserId
AND Posts.Id = :PostId`, map[string]interface{}{"UserId": userId, "PostId": postId}); err != nil {
result.Err = model.NewLocAppError("SqlChannelStore.GetMemberForPost", "store.sql_channel.get_member_for_post.app_error", nil, "postId="+postId+", err="+err.Error())
} else {
result.Data = member
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
func (s SqlChannelStore) GetMemberCount(channelId string) StoreChannel {
storeChannel := make(StoreChannel, 1)
@@ -878,6 +908,35 @@ func (s SqlChannelStore) GetAll(teamId string) StoreChannel {
return storeChannel
}
func (s SqlChannelStore) GetForPost(postId string) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
result := StoreResult{}
channel := &model.Channel{}
if err := s.GetReplica().SelectOne(
channel,
`SELECT
Channels.*
FROM
Channels,
Posts
WHERE
Channels.Id = Posts.ChannelId
AND Posts.Id = :PostId`, map[string]interface{}{"PostId": postId}); err != nil {
result.Err = model.NewLocAppError("SqlChannelStore.GetForPost", "store.sql_channel.get_for_post.app_error", nil, "postId="+postId+", err="+err.Error())
} else {
result.Data = channel
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
func (s SqlChannelStore) AnalyticsTypeCount(teamId string, channelType string) StoreChannel {
storeChannel := make(StoreChannel, 1)

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

@@ -197,6 +197,29 @@ func TestChannelStoreGet(t *testing.T) {
}
}
func TestChannelStoreGetForPost(t *testing.T) {
Setup()
o1 := Must(store.Channel().Save(&model.Channel{
TeamId: model.NewId(),
DisplayName: "Name",
Name: "a" + model.NewId() + "b",
Type: model.CHANNEL_OPEN,
})).(*model.Channel)
p1 := Must(store.Post().Save(&model.Post{
UserId: model.NewId(),
ChannelId: o1.Id,
Message: "test",
})).(*model.Post)
if r1 := <-store.Channel().GetForPost(p1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else if r1.Data.(*model.Channel).Id != o1.Id {
t.Fatal("incorrect channel returned")
}
}
func TestChannelStoreDelete(t *testing.T) {
Setup()
@@ -745,6 +768,39 @@ func TestGetMember(t *testing.T) {
}
}
func TestChannelStoreGetMemberForPost(t *testing.T) {
Setup()
o1 := Must(store.Channel().Save(&model.Channel{
TeamId: model.NewId(),
DisplayName: "Name",
Name: "a" + model.NewId() + "b",
Type: model.CHANNEL_OPEN,
})).(*model.Channel)
m1 := Must(store.Channel().SaveMember(&model.ChannelMember{
ChannelId: o1.Id,
UserId: model.NewId(),
NotifyProps: model.GetDefaultChannelNotifyProps(),
})).(*model.ChannelMember)
p1 := Must(store.Post().Save(&model.Post{
UserId: model.NewId(),
ChannelId: o1.Id,
Message: "test",
})).(*model.Post)
if r1 := <-store.Channel().GetMemberForPost(p1.Id, m1.UserId); r1.Err != nil {
t.Fatal(r1.Err)
} else if r1.Data.(*model.ChannelMember).ToJson() != m1.ToJson() {
t.Fatal("invalid returned channel member")
}
if r2 := <-store.Channel().GetMemberForPost(p1.Id, model.NewId()); r2.Err == nil {
t.Fatal("shouldn't have returned a member")
}
}
func TestGetMemberCount(t *testing.T) {
Setup()

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

@@ -199,7 +199,7 @@ func (s SqlComplianceStore) ComplianceExport(job *model.Compliance) StoreChannel
Posts.Type AS PostType,
Posts.Props AS PostProps,
Posts.Hashtags AS PostHashtags,
Posts.Filenames AS PostFilenames
Posts.FileIds AS PostFileIds
FROM
Teams,
Channels,

197
store/sql_file_info_store.go Обычный файл
Просмотреть файл

@@ -0,0 +1,197 @@
// See License.txt for license information.
package store
import (
"github.com/mattermost/platform/model"
)
type SqlFileInfoStore struct {
*SqlStore
}
func NewSqlFileInfoStore(sqlStore *SqlStore) FileInfoStore {
s := &SqlFileInfoStore{sqlStore}
for _, db := range sqlStore.GetAllConns() {
table := db.AddTableWithName(model.FileInfo{}, "FileInfo").SetKeys(false, "Id")
table.ColMap("Id").SetMaxSize(26)
table.ColMap("CreatorId").SetMaxSize(26)
table.ColMap("PostId").SetMaxSize(26)
table.ColMap("Path").SetMaxSize(512)
table.ColMap("ThumbnailPath").SetMaxSize(512)
table.ColMap("PreviewPath").SetMaxSize(512)
table.ColMap("Name").SetMaxSize(256)
table.ColMap("Extension").SetMaxSize(64)
table.ColMap("MimeType").SetMaxSize(256)
}
return s
}
func (fs SqlFileInfoStore) CreateIndexesIfNotExists() {
}
func (fs SqlFileInfoStore) Save(info *model.FileInfo) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
result := StoreResult{}
info.PreSave()
if result.Err = info.IsValid(); result.Err != nil {
storeChannel <- result
close(storeChannel)
return
}
if err := fs.GetMaster().Insert(info); err != nil {
result.Err = model.NewLocAppError("SqlFileInfoStore.Save", "store.sql_file_info.save.app_error", nil, err.Error())
} else {
result.Data = info
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
func (fs SqlFileInfoStore) Get(id string) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
result := StoreResult{}
info := &model.FileInfo{}
if err := fs.GetReplica().SelectOne(info,
`SELECT
*
FROM
FileInfo
WHERE
Id = :Id
AND DeleteAt = 0`, map[string]interface{}{"Id": id}); err != nil {
result.Err = model.NewLocAppError("SqlFileInfoStore.Get", "store.sql_file_info.get.app_error", nil, "id="+id+", "+err.Error())
} else {
result.Data = info
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
func (fs SqlFileInfoStore) GetByPath(path string) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
result := StoreResult{}
info := &model.FileInfo{}
if err := fs.GetReplica().SelectOne(info,
`SELECT
*
FROM
FileInfo
WHERE
Path = :Path
AND DeleteAt = 0`, map[string]interface{}{"Path": path}); err != nil {
result.Err = model.NewLocAppError("SqlFileInfoStore.GetByPath", "store.sql_file_info.get_by_path.app_error", nil, "path="+path+", "+err.Error())
} else {
result.Data = info
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
func (fs SqlFileInfoStore) GetForPost(postId string) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
result := StoreResult{}
var infos []*model.FileInfo
if _, err := fs.GetReplica().Select(&infos,
`SELECT
*
FROM
FileInfo
WHERE
PostId = :PostId
AND DeleteAt = 0
ORDER BY
CreateAt`, map[string]interface{}{"PostId": postId}); err != nil {
result.Err = model.NewLocAppError("SqlFileInfoStore.GetForPost",
"store.sql_file_info.get_for_post.app_error", nil, "post_id="+postId+", "+err.Error())
} else {
result.Data = infos
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
func (fs SqlFileInfoStore) AttachToPost(fileId, postId string) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
result := StoreResult{}
if _, err := fs.GetMaster().Exec(
`UPDATE
FileInfo
SET
PostId = :PostId
WHERE
Id = :Id
AND PostId = ''`, map[string]interface{}{"PostId": postId, "Id": fileId}); err != nil {
result.Err = model.NewLocAppError("SqlFileInfoStore.AttachToPost",
"store.sql_file_info.attach_to_post.app_error", nil, "post_id="+postId+", file_id="+fileId+", err="+err.Error())
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
func (fs SqlFileInfoStore) DeleteForPost(postId string) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
result := StoreResult{}
if _, err := fs.GetMaster().Exec(
`UPDATE
FileInfo
SET
DeleteAt = :DeleteAt
WHERE
PostId = :PostId`, map[string]interface{}{"DeleteAt": model.GetMillis(), "PostId": postId}); err != nil {
result.Err = model.NewLocAppError("SqlFileInfoStore.DeleteForPost",
"store.sql_file_info.delete_for_post.app_error", nil, "post_id="+postId+", err="+err.Error())
} else {
result.Data = postId
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}

208
store/sql_file_info_store_test.go Обычный файл
Просмотреть файл

@@ -0,0 +1,208 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package store
import (
"fmt"
"testing"
"github.com/mattermost/platform/model"
)
func TestFileInfoSaveGet(t *testing.T) {
Setup()
info := &model.FileInfo{
CreatorId: model.NewId(),
Path: "file.txt",
}
if result := <-store.FileInfo().Save(info); result.Err != nil {
t.Fatal(result.Err)
} else if returned := result.Data.(*model.FileInfo); len(returned.Id) == 0 {
t.Fatal("should've assigned an id to FileInfo")
} else {
info = returned
}
if result := <-store.FileInfo().Get(info.Id); result.Err != nil {
t.Fatal(result.Err)
} else if returned := result.Data.(*model.FileInfo); returned.Id != info.Id {
t.Log(info)
t.Log(returned)
t.Fatal("should've returned correct FileInfo")
}
info2 := Must(store.FileInfo().Save(&model.FileInfo{
CreatorId: model.NewId(),
Path: "file.txt",
DeleteAt: 123,
})).(*model.FileInfo)
if result := <-store.FileInfo().Get(info2.Id); result.Err == nil {
t.Fatal("shouldn't have gotten deleted file")
}
}
func TestFileInfoSaveGetByPath(t *testing.T) {
Setup()
info := &model.FileInfo{
CreatorId: model.NewId(),
Path: fmt.Sprintf("%v/file.txt", model.NewId()),
}
if result := <-store.FileInfo().Save(info); result.Err != nil {
t.Fatal(result.Err)
} else if returned := result.Data.(*model.FileInfo); len(returned.Id) == 0 {
t.Fatal("should've assigned an id to FileInfo")
} else {
info = returned
}
if result := <-store.FileInfo().GetByPath(info.Path); result.Err != nil {
t.Fatal(result.Err)
} else if returned := result.Data.(*model.FileInfo); returned.Id != info.Id {
t.Log(info)
t.Log(returned)
t.Fatal("should've returned correct FileInfo")
}
info2 := Must(store.FileInfo().Save(&model.FileInfo{
CreatorId: model.NewId(),
Path: "file.txt",
DeleteAt: 123,
})).(*model.FileInfo)
if result := <-store.FileInfo().GetByPath(info2.Id); result.Err == nil {
t.Fatal("shouldn't have gotten deleted file")
}
}
func TestFileInfoGetForPost(t *testing.T) {
Setup()
userId := model.NewId()
postId := model.NewId()
infos := []*model.FileInfo{
{
PostId: postId,
CreatorId: userId,
Path: "file.txt",
},
{
PostId: postId,
CreatorId: userId,
Path: "file.txt",
},
{
PostId: postId,
CreatorId: userId,
Path: "file.txt",
DeleteAt: 123,
},
{
PostId: model.NewId(),
CreatorId: userId,
Path: "file.txt",
},
}
for i, info := range infos {
infos[i] = Must(store.FileInfo().Save(info)).(*model.FileInfo)
}
if result := <-store.FileInfo().GetForPost(postId); result.Err != nil {
t.Fatal(result.Err)
} else if returned := result.Data.([]*model.FileInfo); len(returned) != 2 {
t.Fatal("should've returned exactly 2 file infos")
}
}
func TestFileInfoAttachToPost(t *testing.T) {
Setup()
userId := model.NewId()
postId := model.NewId()
info1 := Must(store.FileInfo().Save(&model.FileInfo{
CreatorId: userId,
Path: "file.txt",
})).(*model.FileInfo)
if len(info1.PostId) != 0 {
t.Fatal("file shouldn't have a PostId")
}
if result := <-store.FileInfo().AttachToPost(info1.Id, postId); result.Err != nil {
t.Fatal(result.Err)
} else {
info1 = Must(store.FileInfo().Get(info1.Id)).(*model.FileInfo)
}
if len(info1.PostId) == 0 {
t.Fatal("file should now have a PostId")
}
info2 := Must(store.FileInfo().Save(&model.FileInfo{
CreatorId: userId,
Path: "file.txt",
})).(*model.FileInfo)
if result := <-store.FileInfo().AttachToPost(info2.Id, postId); result.Err != nil {
t.Fatal(result.Err)
} else {
info2 = Must(store.FileInfo().Get(info2.Id)).(*model.FileInfo)
}
if result := <-store.FileInfo().GetForPost(postId); result.Err != nil {
t.Fatal(result.Err)
} else if infos := result.Data.([]*model.FileInfo); len(infos) != 2 {
t.Fatal("should've returned exactly 2 file infos")
}
}
func TestFileInfoDeleteForPost(t *testing.T) {
Setup()
userId := model.NewId()
postId := model.NewId()
infos := []*model.FileInfo{
{
PostId: postId,
CreatorId: userId,
Path: "file.txt",
},
{
PostId: postId,
CreatorId: userId,
Path: "file.txt",
},
{
PostId: postId,
CreatorId: userId,
Path: "file.txt",
DeleteAt: 123,
},
{
PostId: model.NewId(),
CreatorId: userId,
Path: "file.txt",
},
}
for i, info := range infos {
infos[i] = Must(store.FileInfo().Save(info)).(*model.FileInfo)
}
if result := <-store.FileInfo().DeleteForPost(postId); result.Err != nil {
t.Fatal(result.Err)
}
if infos := Must(store.FileInfo().GetForPost(postId)).([]*model.FileInfo); len(infos) != 0 {
t.Fatal("shouldn't have returned any file infos")
}
}

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

@@ -32,6 +32,7 @@ func NewSqlPostStore(sqlStore *SqlStore) PostStore {
table.ColMap("Hashtags").SetMaxSize(1000)
table.ColMap("Props").SetMaxSize(8000)
table.ColMap("Filenames").SetMaxSize(4000)
table.ColMap("FileIds").SetMaxSize(150)
}
return s
@@ -94,42 +95,39 @@ func (s SqlPostStore) Save(post *model.Post) StoreChannel {
return storeChannel
}
func (s SqlPostStore) Update(oldPost *model.Post, newMessage string, newHashtags string) StoreChannel {
func (s SqlPostStore) Update(newPost *model.Post, oldPost *model.Post) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
result := StoreResult{}
editPost := *oldPost
editPost.Message = newMessage
editPost.UpdateAt = model.GetMillis()
editPost.Hashtags = newHashtags
newPost.UpdateAt = model.GetMillis()
oldPost.DeleteAt = editPost.UpdateAt
oldPost.UpdateAt = editPost.UpdateAt
oldPost.DeleteAt = newPost.UpdateAt
oldPost.UpdateAt = newPost.UpdateAt
oldPost.OriginalId = oldPost.Id
oldPost.Id = model.NewId()
if result.Err = editPost.IsValid(); result.Err != nil {
if result.Err = newPost.IsValid(); result.Err != nil {
storeChannel <- result
close(storeChannel)
return
}
if _, err := s.GetMaster().Update(&editPost); err != nil {
result.Err = model.NewLocAppError("SqlPostStore.Update", "store.sql_post.update.app_error", nil, "id="+editPost.Id+", "+err.Error())
if _, err := s.GetMaster().Update(newPost); err != nil {
result.Err = model.NewLocAppError("SqlPostStore.Update", "store.sql_post.update.app_error", nil, "id="+newPost.Id+", "+err.Error())
} else {
time := model.GetMillis()
s.GetMaster().Exec("UPDATE Channels SET LastPostAt = :LastPostAt WHERE Id = :ChannelId", map[string]interface{}{"LastPostAt": time, "ChannelId": editPost.ChannelId})
s.GetMaster().Exec("UPDATE Channels SET LastPostAt = :LastPostAt WHERE Id = :ChannelId", map[string]interface{}{"LastPostAt": time, "ChannelId": newPost.ChannelId})
if len(editPost.RootId) > 0 {
s.GetMaster().Exec("UPDATE Posts SET UpdateAt = :UpdateAt WHERE Id = :RootId", map[string]interface{}{"UpdateAt": time, "RootId": editPost.RootId})
if len(newPost.RootId) > 0 {
s.GetMaster().Exec("UPDATE Posts SET UpdateAt = :UpdateAt WHERE Id = :RootId", map[string]interface{}{"UpdateAt": time, "RootId": newPost.RootId})
}
// mark the old post as deleted
s.GetMaster().Insert(oldPost)
result.Data = &editPost
result.Data = newPost
}
storeChannel <- result
@@ -972,7 +970,7 @@ func (s SqlPostStore) AnalyticsPostCount(teamId string, mustHaveFile bool, mustH
}
if mustHaveFile {
query += " AND Posts.Filenames != '[]'"
query += " AND (Posts.FileIds != '[]' OR Posts.Filenames != '[]')"
}
if mustHaveHashtag {

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

@@ -87,45 +87,73 @@ func TestPostStoreUpdate(t *testing.T) {
ro1 := (<-store.Post().Get(o1.Id)).Data.(*model.PostList).Posts[o1.Id]
ro2 := (<-store.Post().Get(o1.Id)).Data.(*model.PostList).Posts[o2.Id]
ro6 := (<-store.Post().Get(o3.Id)).Data.(*model.PostList).Posts[o3.Id]
ro3 := (<-store.Post().Get(o3.Id)).Data.(*model.PostList).Posts[o3.Id]
if ro1.Message != o1.Message {
t.Fatal("Failed to save/get")
}
msg := o1.Message + "BBBBBBBBBB"
if result := <-store.Post().Update(ro1, msg, ""); result.Err != nil {
o1a := &model.Post{}
*o1a = *ro1
o1a.Message = ro1.Message + "BBBBBBBBBB"
if result := <-store.Post().Update(o1a, ro1); result.Err != nil {
t.Fatal(result.Err)
}
msg2 := o2.Message + "DDDDDDD"
if result := <-store.Post().Update(ro2, msg2, ""); result.Err != nil {
ro1a := (<-store.Post().Get(o1.Id)).Data.(*model.PostList).Posts[o1.Id]
if ro1a.Message != o1a.Message {
t.Fatal("Failed to update/get")
}
o2a := &model.Post{}
*o2a = *ro2
o2a.Message = ro2.Message + "DDDDDDD"
if result := <-store.Post().Update(o2a, ro2); result.Err != nil {
t.Fatal(result.Err)
}
msg3 := o3.Message + "WWWWWWW"
if result := <-store.Post().Update(ro6, msg3, "#hashtag"); result.Err != nil {
ro2a := (<-store.Post().Get(o1.Id)).Data.(*model.PostList).Posts[o2.Id]
if ro2a.Message != o2a.Message {
t.Fatal("Failed to update/get")
}
o3a := &model.Post{}
*o3a = *ro3
o3a.Message = ro3.Message + "WWWWWWW"
if result := <-store.Post().Update(o3a, ro3); result.Err != nil {
t.Fatal(result.Err)
}
ro3 := (<-store.Post().Get(o1.Id)).Data.(*model.PostList).Posts[o1.Id]
ro3a := (<-store.Post().Get(o3.Id)).Data.(*model.PostList).Posts[o3.Id]
if ro3.Message != msg {
if ro3a.Message != o3a.Message && ro3a.Hashtags != o3a.Hashtags {
t.Fatal("Failed to update/get")
}
ro4 := (<-store.Post().Get(o1.Id)).Data.(*model.PostList).Posts[o2.Id]
o4 := Must(store.Post().Save(&model.Post{
ChannelId: model.NewId(),
UserId: model.NewId(),
Message: model.NewId(),
Filenames: []string{"test"},
})).(*model.Post)
if ro4.Message != msg2 {
t.Fatal("Failed to update/get")
ro4 := (<-store.Post().Get(o4.Id)).Data.(*model.PostList).Posts[o4.Id]
o4a := &model.Post{}
*o4a = *ro4
o4a.Filenames = []string{}
o4a.FileIds = []string{model.NewId()}
if result := <-store.Post().Update(o4a, ro4); result.Err != nil {
t.Fatal(result.Err)
}
ro5 := (<-store.Post().Get(o3.Id)).Data.(*model.PostList).Posts[o3.Id]
if ro5.Message != msg3 && ro5.Hashtags != "#hashtag" {
t.Fatal("Failed to update/get")
if ro4a := Must(store.Post().Get(o4.Id)).(*model.PostList).Posts[o4.Id]; len(ro4a.Filenames) != 0 {
t.Fatal("Failed to clear Filenames")
} else if len(ro4a.FileIds) != 1 {
t.Fatal("Failed to set FileIds")
}
}
func TestPostStoreDelete(t *testing.T) {

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

@@ -81,6 +81,7 @@ type SqlStore struct {
recovery PasswordRecoveryStore
emoji EmojiStore
status StatusStore
fileInfo FileInfoStore
SchemaVersion string
}
@@ -129,6 +130,7 @@ func NewSqlStore() Store {
sqlStore.recovery = NewSqlPasswordRecoveryStore(sqlStore)
sqlStore.emoji = NewSqlEmojiStore(sqlStore)
sqlStore.status = NewSqlStatusStore(sqlStore)
sqlStore.fileInfo = NewSqlFileInfoStore(sqlStore)
err := sqlStore.master.CreateTablesIfNotExists()
if err != nil {
@@ -155,6 +157,7 @@ func NewSqlStore() Store {
sqlStore.recovery.(*SqlPasswordRecoveryStore).CreateIndexesIfNotExists()
sqlStore.emoji.(*SqlEmojiStore).CreateIndexesIfNotExists()
sqlStore.status.(*SqlStatusStore).CreateIndexesIfNotExists()
sqlStore.fileInfo.(*SqlFileInfoStore).CreateIndexesIfNotExists()
sqlStore.preference.(*SqlPreferenceStore).DeleteUnusedFeatures()
@@ -643,6 +646,10 @@ func (ss SqlStore) Status() StatusStore {
return ss.status
}
func (ss SqlStore) FileInfo() FileInfoStore {
return ss.fileInfo
}
func (ss SqlStore) DropAllTables() {
ss.master.TruncateTables()
}

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

@@ -181,7 +181,6 @@ func UpgradeDatabaseToVersion33(sqlStore *SqlStore) {
func UpgradeDatabaseToVersion34(sqlStore *SqlStore) {
if shouldPerformUpgrade(sqlStore, VERSION_3_3_0, VERSION_3_4_0) {
sqlStore.CreateColumnIfNotExists("Status", "Manual", "BOOLEAN", "BOOLEAN", "0")
sqlStore.CreateColumnIfNotExists("Status", "ActiveChannel", "varchar(26)", "varchar(26)", "")
@@ -199,6 +198,9 @@ func UpgradeDatabaseToVersion35(sqlStore *SqlStore) {
sqlStore.GetMaster().Exec("UPDATE ChannelMembers SET Roles = 'channel_user' WHERE Roles = ''")
sqlStore.GetMaster().Exec("UPDATE ChannelMembers SET Roles = 'channel_user channel_admin' WHERE Roles = 'admin'")
// The rest of the migration from Filenames -> FileIds is done lazily in api.GetFileInfosForPost
sqlStore.CreateColumnIfNotExists("Posts", "FileIds", "varchar(150)", "varchar(150)", "[]")
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// UNCOMMENT WHEN WE DO RELEASE
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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

@@ -45,6 +45,7 @@ type Store interface {
PasswordRecovery() PasswordRecoveryStore
Emoji() EmojiStore
Status() StatusStore
FileInfo() FileInfoStore
MarkSystemRanUnitTests()
Close()
DropAllTables()
@@ -86,11 +87,13 @@ type ChannelStore interface {
GetMoreChannels(teamId string, userId string) StoreChannel
GetChannelCounts(teamId string, userId string) StoreChannel
GetAll(teamId string) StoreChannel
GetForPost(postId string) StoreChannel
SaveMember(member *model.ChannelMember) StoreChannel
UpdateMember(member *model.ChannelMember) StoreChannel
GetMembers(channelId string) StoreChannel
GetMember(channelId string, userId string) StoreChannel
GetMemberForPost(postId string, userId string) StoreChannel
GetMemberCount(channelId string) StoreChannel
RemoveMember(channelId string, userId string) StoreChannel
PermanentDeleteMembersByUser(userId string) StoreChannel
@@ -104,7 +107,7 @@ type ChannelStore interface {
type PostStore interface {
Save(post *model.Post) StoreChannel
Update(post *model.Post, newMessage string, newHashtags string) StoreChannel
Update(newPost *model.Post, oldPost *model.Post) StoreChannel
Get(id string) StoreChannel
Delete(postId string, time int64) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel
@@ -277,3 +280,12 @@ type StatusStore interface {
GetTotalActiveUsersCount() StoreChannel
UpdateLastActivityAt(userId string, lastActivityAt int64) StoreChannel
}
type FileInfoStore interface {
Save(info *model.FileInfo) StoreChannel
Get(id string) StoreChannel
GetByPath(path string) StoreChannel
GetForPost(postId string) StoreChannel
AttachToPost(fileId string, postId string) StoreChannel
DeleteForPost(postId string) StoreChannel
}