Feat: add POSIX DB projection
This commit is contained in:
52
Backend/cmd/posix/main.go
Normal file
52
Backend/cmd/posix/main.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"moku-backend/internal/config"
|
||||
"moku-backend/internal/database"
|
||||
"moku-backend/internal/posixproj"
|
||||
)
|
||||
|
||||
func main() {
|
||||
command := "rebuild"
|
||||
if len(os.Args) > 1 {
|
||||
command = os.Args[1]
|
||||
}
|
||||
|
||||
switch command {
|
||||
case "rebuild":
|
||||
if err := rebuildProjection(context.Background()); err != nil {
|
||||
log.Fatalf("rebuild POSIX projection: %v", err)
|
||||
}
|
||||
default:
|
||||
log.Fatalf("unsupported posix command %q (supported: rebuild)", command)
|
||||
}
|
||||
}
|
||||
|
||||
func rebuildProjection(ctx context.Context) error {
|
||||
cfg := config.Load()
|
||||
|
||||
db, err := database.NewPostgres(cfg.PostgresURL)
|
||||
if err != nil {
|
||||
return fmt.Errorf("connect database: %w", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
summary, err := posixproj.NewProjector(db, cfg.POSIXRoot).RebuildWithSummary(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf(
|
||||
"POSIX projection rebuilt from %s\n total nodes: %d\n directories: %d\n files: %d\n",
|
||||
cfg.POSIXRoot,
|
||||
summary.TotalNodes,
|
||||
summary.DirectoryCount,
|
||||
summary.FileCount,
|
||||
)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user