about summary refs log tree commit diff stats
path: root/import
diff options
context:
space:
mode:
authorAlan Pearce2024-05-09 18:39:45 +0200
committerAlan Pearce2024-05-09 19:27:57 +0200
commit778e1d774f574f45c179d0fecf0c1da9cc359b80 (patch)
tree51d7a2c1fa6c29dc3782c10c7df40545ef694710 /import
parent99d5507b223baa6c780707d32c7bbbb8611034f0 (diff)
downloadsearchix-778e1d774f574f45c179d0fecf0c1da9cc359b80.tar.lz
searchix-778e1d774f574f45c179d0fecf0c1da9cc359b80.tar.zst
searchix-778e1d774f574f45c179d0fecf0c1da9cc359b80.zip
feat(importer): add --replace flag to overwrite existing index
Diffstat (limited to 'import')
-rw-r--r--import/main.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/import/main.go b/import/main.go
index 87f8e4d..52b4515 100644
--- a/import/main.go
+++ b/import/main.go
@@ -22,6 +22,7 @@ const timeout = 30 * time.Minute
 type Config struct {
 	ConfigFile string     `conf:"short:c"`
 	LogLevel   slog.Level `conf:"default:INFO"`
+	Replace    bool       `conf:"default:false,help:whether to remove existing database, if exists"`
 }
 
 func main() {
@@ -50,7 +51,7 @@ func main() {
 		return
 	}
 
-	indexer, err := search.NewIndexer(cfg.DataPath)
+	indexer, err := search.NewIndexer(cfg.DataPath, runtimeConfig.Replace)
 	if err != nil {
 		log.Fatalf("Failed to create indexer: %v", err)
 	}
@@ -93,7 +94,7 @@ func main() {
 		}
 		logger.Info("importer fetch succeeded", "updated", updated)
 
-		if updated {
+		if updated || runtimeConfig.Replace {
 			hadWarnings, err := imp.Import(ctx, indexer)
 
 			if err != nil {