-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds a database migration to restore the fileinfos that are deleted #4815
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
server/services/store/sqlstore/migrations/000040_fix_fileinfo_soft_deletes.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SELECT 1; |
8 changes: 8 additions & 0 deletions
8
server/services/store/sqlstore/migrations/000040_fix_fileinfo_soft_deletes.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{{if .plugin}} | ||
UPDATE FileInfo | ||
SET DeleteAt = 0 | ||
WHERE CreatorId = 'boards' | ||
AND DeleteAt != 0; | ||
{{else}} | ||
SELECT 1; | ||
{{end}} |
9 changes: 9 additions & 0 deletions
9
server/services/store/sqlstore/migrationstests/fixtures/test40FixFileinfoSoftDeletes.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
INSERT INTO FileInfo | ||
(Id, CreatorId, CreateAt, UpdateAt, DeleteAt) | ||
VALUES | ||
('fileinfo-1', 'user-id', 1, 1, 1000), | ||
('fileinfo-2', 'user-id', 1, 1, 1000), | ||
('fileinfo-3', 'user-id', 1, 1, 0), | ||
('fileinfo-4', 'boards', 1, 1, 2000), | ||
('fileinfo-5', 'boards', 1, 1, 2000), | ||
('fileinfo-6', 'boards', 1, 1, 0); |
48 changes: 48 additions & 0 deletions
48
server/services/store/sqlstore/migrationstests/migration40_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package migrationstests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test40FixFileinfoSoftDeletes(t *testing.T) { | ||
th, tearDown := SetupPluginTestHelper(t) | ||
defer tearDown() | ||
|
||
th.f.MigrateToStep(39). | ||
ExecFile("./fixtures/test40FixFileinfoSoftDeletes.sql"). | ||
MigrateToStep(40) | ||
|
||
type FileInfo struct { | ||
Id string | ||
DeleteAt int | ||
} | ||
|
||
getFileInfo := func(t *testing.T, id string) FileInfo { | ||
t.Helper() | ||
fileInfo := FileInfo{} | ||
|
||
query := "SELECT id, deleteat FROM FileInfo WHERE id = $1" | ||
if th.IsMySQL() { | ||
query = "SELECT Id as id, DeleteAt as deleteat FROM FileInfo WHERE Id = ?" | ||
} | ||
|
||
err := th.f.DB().Get(&fileInfo, query, id) | ||
require.NoError(t, err) | ||
|
||
return fileInfo | ||
} | ||
|
||
t.Run("the file infos that don't belong to boards will not be restored", func(t *testing.T) { | ||
require.Equal(t, 1000, getFileInfo(t, "fileinfo-1").DeleteAt) | ||
require.Equal(t, 1000, getFileInfo(t, "fileinfo-2").DeleteAt) | ||
require.Empty(t, getFileInfo(t, "fileinfo-3").DeleteAt) | ||
}) | ||
|
||
t.Run("the file infos that belong to boards should correctly be restored", func(t *testing.T) { | ||
require.Empty(t, getFileInfo(t, "fileinfo-3").DeleteAt) | ||
require.Empty(t, getFileInfo(t, "fileinfo-4").DeleteAt) | ||
require.Empty(t, getFileInfo(t, "fileinfo-5").DeleteAt) | ||
}) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To confirm, does this mean we undelete everything boards has ever deleted? And that we'll figure out what /should/ be deleted in a separate PR?