Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(vcs): if a later commit changes file in previous commit, keep the ADDED type (#2786)

Yilong Li57ee3e092423
diff --git a/server/webhook.go b/server/webhook.go
index 3550cdb9a7..d883879366 100644
--- a/server/webhook.go
+++ b/server/webhook.go
@@ -405,6 +405,10 @@ func dedupMigrationFilesFromCommitList(commitList []vcs.Commit) []distinctFileIt
// For the migration file with the same name, keep the one from the latest commit
if item.fileName == file.fileName {
if file.createdTs < commit.CreatedTs {
+ // A file can be added and then modified in a later commit. We should consider the item as added.
+ if file.itemType == fileItemTypeAdded {
+ item.itemType = fileItemTypeAdded
+ }
distinctFileList[i] = item
}
return
diff --git a/server/webhook_test.go b/server/webhook_test.go
index 1a6c57c393..00ce8bf8f9 100644
--- a/server/webhook_test.go
+++ b/server/webhook_test.go
@@ -163,6 +163,51 @@ func TestDedupMigrationFiles(t *testing.T) {
},
},
},
+ {
+ name: "Multi commits, single file, direct push",
+ commitList: []vcs.Commit{
+ {
+ ID: "1",
+ Title: "Commit 1",
+ Message: "Update 1",
+ CreatedTs: ts1,
+ URL: "example.com",
+ AuthorName: "bob",
+ AddedList: []string{
+ "v1.sql",
+ },
+ },
+ {
+ ID: "2",
+ Title: "Commit 2",
+ Message: "Update 2",
+ CreatedTs: ts2,
+ URL: "example.com",
+ AuthorName: "bob",
+ ModifiedList: []string{
+ "v1.sql",
+ },
+ },
+ },
+ want: []distinctFileItem{
+ {
+ createdTs: ts2,
+ commit: vcs.Commit{
+ ID: "2",
+ Title: "Commit 2",
+ Message: "Update 2",
+ CreatedTs: ts2,
+ URL: "example.com",
+ AuthorName: "bob",
+ ModifiedList: []string{
+ "v1.sql",
+ },
+ },
+ fileName: "v1.sql",
+ itemType: fileItemTypeAdded,
+ },
+ },
+ },
{
name: "Multi commits, multi files",
commitList: []vcs.Commit{