Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit e289ee4

Browse files
committed
common: Add stub implementation of database diff function
This adds a stub implementation of database diffing. Currently this function is not doing anything useful but it can be extended later.
1 parent 587cdb4 commit e289ee4

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

common/diff.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package common
2+
3+
import (
4+
"fmt"
5+
"log"
6+
)
7+
8+
type Diffs struct {
9+
Dummy string `json:"dummy"` // TODO: This is only used for debugging purposes and needs to be removed later
10+
}
11+
12+
// Diff
13+
func Diff(ownerA string, folderA string, nameA string, commitA string, ownerB string, folderB string, nameB string, commitB string, loggedInUser string) (Diffs, error) {
14+
// Check if the user has access to the requested databases
15+
bucketA, idA, _, err := MinioLocation(ownerA, folderA, nameA, commitA, loggedInUser)
16+
if err != nil {
17+
return Diffs{}, err
18+
}
19+
bucketB, idB, _, err := MinioLocation(ownerB, folderB, nameB, commitB, loggedInUser)
20+
if err != nil {
21+
return Diffs{}, err
22+
}
23+
24+
// Sanity check
25+
if idA == "" {
26+
// The requested database wasn't found, or the user doesn't have permission to access it
27+
err = fmt.Errorf("Requested database not found")
28+
log.Printf("Requested database not found: '%s%s%s'", ownerA, folderA, nameA)
29+
return Diffs{}, err
30+
}
31+
if idB == "" {
32+
// The requested database wasn't found, or the user doesn't have permission to access it
33+
err = fmt.Errorf("Requested database not found")
34+
log.Printf("Requested database not found: '%s%s%s'", ownerB, folderB, nameB)
35+
return Diffs{}, err
36+
}
37+
38+
// Retrieve database files from Minio, using locally cached version if it's already there
39+
dbA, err := RetrieveDatabaseFile(bucketA, idA)
40+
if err != nil {
41+
return Diffs{}, err
42+
}
43+
dbB, err := RetrieveDatabaseFile(bucketB, idB)
44+
if err != nil {
45+
return Diffs{}, err
46+
}
47+
48+
// Call dbDiff which does the actual diffing of the database files
49+
return dbDiff(dbA, dbB)
50+
}
51+
52+
// dbDiff
53+
func dbDiff(dbA string, dbB string) (Diffs, error) {
54+
var diff Diffs
55+
56+
// Check if this is the same database and exit early
57+
if dbA == dbB {
58+
diff.Dummy = "same dbs"
59+
return diff, nil
60+
}
61+
62+
// TODO
63+
diff.Dummy = "different dbs"
64+
65+
// Return
66+
return diff, nil
67+
}

0 commit comments

Comments
 (0)