- Add pure Go SQLite driver (modernc.org/sqlite) to avoid CGO dependency - Implement database connection management with WAL mode - Add write mutex for serializing concurrent writes - Create schema for all tables matching DESIGN.md specifications - Implement repository pattern for all database entities: - Files, FileChunks, Chunks, Blobs, BlobChunks, ChunkFiles, Snapshots - Add transaction support with proper rollback handling - Add fatal error handling for database integrity issues - Add snapshot fields for tracking file sizes and compression ratios - Make index path configurable via VAULTIK_INDEX_PATH environment variable - Add comprehensive test coverage for all repositories - Add format check to Makefile to ensure code formatting
71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package database
|
|
|
|
import "time"
|
|
|
|
// File represents a file record in the database
|
|
type File struct {
|
|
Path string
|
|
MTime time.Time
|
|
CTime time.Time
|
|
Size int64
|
|
Mode uint32
|
|
UID uint32
|
|
GID uint32
|
|
LinkTarget string // empty for regular files, target path for symlinks
|
|
}
|
|
|
|
// IsSymlink returns true if this file is a symbolic link
|
|
func (f *File) IsSymlink() bool {
|
|
return f.LinkTarget != ""
|
|
}
|
|
|
|
// FileChunk represents the mapping between files and chunks
|
|
type FileChunk struct {
|
|
Path string
|
|
Idx int
|
|
ChunkHash string
|
|
}
|
|
|
|
// Chunk represents a chunk record in the database
|
|
type Chunk struct {
|
|
ChunkHash string
|
|
SHA256 string
|
|
Size int64
|
|
}
|
|
|
|
// Blob represents a blob record in the database
|
|
type Blob struct {
|
|
BlobHash string
|
|
CreatedTS time.Time
|
|
}
|
|
|
|
// BlobChunk represents the mapping between blobs and chunks
|
|
type BlobChunk struct {
|
|
BlobHash string
|
|
ChunkHash string
|
|
Offset int64
|
|
Length int64
|
|
}
|
|
|
|
// ChunkFile represents the reverse mapping of chunks to files
|
|
type ChunkFile struct {
|
|
ChunkHash string
|
|
FilePath string
|
|
FileOffset int64
|
|
Length int64
|
|
}
|
|
|
|
// Snapshot represents a snapshot record in the database
|
|
type Snapshot struct {
|
|
ID string
|
|
Hostname string
|
|
VaultikVersion string
|
|
CreatedTS time.Time
|
|
FileCount int64
|
|
ChunkCount int64
|
|
BlobCount int64
|
|
TotalSize int64 // Total size of all referenced files
|
|
BlobSize int64 // Total size of all referenced blobs (compressed and encrypted)
|
|
CompressionRatio float64 // Compression ratio (BlobSize / TotalSize)
|
|
}
|