Skip to content

Commit d8af5c3

Browse files
Adds a database migration to restore the fileinfos that are deleted (#4815) (#4816)
(cherry picked from commit 257cc5f) Co-authored-by: Miguel de la Cruz <[email protected]>
1 parent 691a61d commit d8af5c3

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT 1;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{{if .plugin}}
2+
UPDATE FileInfo
3+
SET DeleteAt = 0
4+
WHERE CreatorId = 'boards'
5+
AND DeleteAt != 0;
6+
{{else}}
7+
SELECT 1;
8+
{{end}}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
INSERT INTO FileInfo
2+
(Id, CreatorId, CreateAt, UpdateAt, DeleteAt)
3+
VALUES
4+
('fileinfo-1', 'user-id', 1, 1, 1000),
5+
('fileinfo-2', 'user-id', 1, 1, 1000),
6+
('fileinfo-3', 'user-id', 1, 1, 0),
7+
('fileinfo-4', 'boards', 1, 1, 2000),
8+
('fileinfo-5', 'boards', 1, 1, 2000),
9+
('fileinfo-6', 'boards', 1, 1, 0);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package migrationstests
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
func Test40FixFileinfoSoftDeletes(t *testing.T) {
10+
th, tearDown := SetupPluginTestHelper(t)
11+
defer tearDown()
12+
13+
th.f.MigrateToStep(39).
14+
ExecFile("./fixtures/test40FixFileinfoSoftDeletes.sql").
15+
MigrateToStep(40)
16+
17+
type FileInfo struct {
18+
Id string
19+
DeleteAt int
20+
}
21+
22+
getFileInfo := func(t *testing.T, id string) FileInfo {
23+
t.Helper()
24+
fileInfo := FileInfo{}
25+
26+
query := "SELECT id, deleteat FROM FileInfo WHERE id = $1"
27+
if th.IsMySQL() {
28+
query = "SELECT Id as id, DeleteAt as deleteat FROM FileInfo WHERE Id = ?"
29+
}
30+
31+
err := th.f.DB().Get(&fileInfo, query, id)
32+
require.NoError(t, err)
33+
34+
return fileInfo
35+
}
36+
37+
t.Run("the file infos that don't belong to boards will not be restored", func(t *testing.T) {
38+
require.Equal(t, 1000, getFileInfo(t, "fileinfo-1").DeleteAt)
39+
require.Equal(t, 1000, getFileInfo(t, "fileinfo-2").DeleteAt)
40+
require.Empty(t, getFileInfo(t, "fileinfo-3").DeleteAt)
41+
})
42+
43+
t.Run("the file infos that belong to boards should correctly be restored", func(t *testing.T) {
44+
require.Empty(t, getFileInfo(t, "fileinfo-3").DeleteAt)
45+
require.Empty(t, getFileInfo(t, "fileinfo-4").DeleteAt)
46+
require.Empty(t, getFileInfo(t, "fileinfo-5").DeleteAt)
47+
})
48+
}

0 commit comments

Comments
 (0)