package database import ( "crypto/sha256" "fmt" "io/ioutil" "time" "github.com/asdine/storm" "github.com/rs/zerolog" ) type DB struct { *storm.DB *zerolog.Logger } // GVCInfo stores the basic information about when the repo was init'd and some basic information type GVCInfo struct { GVCVersion string `storm:"id"` InitTime string RepoName string } // Commit stores all the necessary information for a commit type Commit struct { CommitHash []byte `storm:"index,unique"` // The hash of the commit (generated by hashing commit author name, time, the previous commit, and more? TODO: Not sure what else) TrackedFiles []File // All of the tracked files for this commit Date string Version string //User can tag a commit with a version number Branch string //Branch this commit belongs to Number int // The commit number } // CommitMeta stores the meta information about the commit type CommitMeta struct { Tag string Flavour string PersistLogs bool Production bool Virtual bool } // File represents a tracked file type File struct { ID int `storm:"id,increment"` Path string `storm:"index"` Name string //BkpLocation string //TODO: Needed? CurrentBase string Hash []byte `storm:"index,unique"` // with []byte can't use sha256.sum256 since that is [32]byte, so everything done manually. CreatedAt time.Time Unique string Version float64 NoCompress bool // Whether or not to compress this file } // CalculateHash creates a hash for the file func (f *File) CalculateHash() error { fileContents, err := ioutil.ReadFile(f.Path) if err != nil { return fmt.Errorf("unable to read contents of file: %s err: %s", f.Path, err) } hash := sha256.New() hash.Write(fileContents) f.Hash = hash.Sum(nil) return nil } type FileIndex struct { ID int `storm:"id,increment"` FileID int `storm:"index"` FileHash [32]byte `storm:"index,unique"` Index []byte Length int64 } // DiffObject store the information for each diff that is made type DiffObject struct { ID int `storm:"id,increment"` Target string `storm:"index"` DiffObject string `storm:"index"` TargetHash []byte `storm:"index"` DiffObjectHash []byte `storm:"index"` //Watching string //name of the file being watched DiffPath string //path of the diff/patch //path would be .gvc/hashofcommit/ //Label string //store a comment if the user wants to (user written) //Screenshot string //path to the screen shot when the diff was made //Fs bool //whether it was written to the directly //Description string //record of forward or backward (just a quick helper) E error //a record of the error when it was created. Maybe able to optimize out later Diff *[]byte //the diff itself (incase we want to store in memory) DiffSize int64 //the size of the diff in bytes StartTime time.Time //when was the diff created (can take a while to create) Message string //any message we want to store against the diff while its created }