Implement local SQLite index database with repositories

- Add SQLite database connection management with proper error handling
- Implement schema for files, chunks, blobs, and snapshots tables
- Create repository pattern for each database table
- Add transaction support with proper rollback handling
- Integrate database module with fx dependency injection
- Make index path configurable via VAULTIK_INDEX_PATH env var
- Add fatal error handling for database integrity issues
- Update DESIGN.md to clarify file_chunks vs chunk_files distinction
- Remove FinalHash from BlobInfo (blobs are content-addressable)
- Add file metadata support (mtime, ctime, mode, uid, gid, symlinks)
This commit is contained in:
2025-07-20 10:26:15 +02:00
parent 9de439a0a4
commit b2e85d9e76
31 changed files with 1229 additions and 83 deletions

View File

@@ -27,8 +27,7 @@ type ChunkRef struct {
// BlobInfo represents an encrypted blob containing multiple chunks
type BlobInfo struct {
Hash string // Hash of encrypted blob
FinalHash string // Hash after compression and encryption
Hash string // SHA256 hash of the blob content (content-addressable)
CreatedAt time.Time
Size int64
ChunkCount int
@@ -36,7 +35,7 @@ type BlobInfo struct {
// Snapshot represents a backup snapshot
type Snapshot struct {
ID string // ISO8601 timestamp
ID string // ISO8601 timestamp
Hostname string
Version string
CreatedAt time.Time
@@ -70,4 +69,4 @@ type DirtyPath struct {
Path string
MarkedAt time.Time
EventType string // "create", "modify", "delete"
}
}

View File

@@ -9,7 +9,7 @@ import (
func TestModelsCompilation(t *testing.T) {
// This test primarily serves as a compilation test
// to ensure all types are properly defined
// Test FileInfo
fi := &FileInfo{
Path: "/test/file.txt",
@@ -19,7 +19,7 @@ func TestModelsCompilation(t *testing.T) {
if fi.Path != "/test/file.txt" {
t.Errorf("FileInfo.Path not set correctly")
}
// Test ChunkInfo
ci := &ChunkInfo{
Hash: "abc123",
@@ -29,11 +29,10 @@ func TestModelsCompilation(t *testing.T) {
if ci.Hash != "abc123" {
t.Errorf("ChunkInfo.Hash not set correctly")
}
// Test BlobInfo
bi := &BlobInfo{
Hash: "blob123",
FinalHash: "final123",
CreatedAt: time.Now(),
Size: 1024,
ChunkCount: 2,
@@ -41,7 +40,7 @@ func TestModelsCompilation(t *testing.T) {
if bi.Hash != "blob123" {
t.Errorf("BlobInfo.Hash not set correctly")
}
// Test Snapshot
s := &Snapshot{
ID: "2024-01-01T00:00:00Z",
@@ -52,4 +51,4 @@ func TestModelsCompilation(t *testing.T) {
if s.ID != "2024-01-01T00:00:00Z" {
t.Errorf("Snapshot.ID not set correctly")
}
}
}