Migrate to postgres

This commit is contained in:
Pijus Kamandulis
2026-08-08 01:26:32 +03:00
parent b8511f5ff8
commit 4fc3a7fb0a
12 changed files with 671 additions and 240 deletions
+5 -7
View File
@@ -9,8 +9,7 @@ import (
"strings"
"time"
"github.com/ostafen/clover/v2"
"github.com/ostafen/clover/v2/document"
"github.com/jackc/pgx/v5/pgxpool"
"pool-stats/constants"
"pool-stats/database"
@@ -18,11 +17,11 @@ import (
)
type IngestSharesJob struct {
db *clover.DB
db *pgxpool.Pool
logPath string
}
func NewIngestSharesJob(db *clover.DB, path string) *IngestSharesJob {
func NewIngestSharesJob(db *pgxpool.Pool, path string) *IngestSharesJob {
return &IngestSharesJob{db: db, logPath: path}
}
@@ -67,7 +66,7 @@ func (this *IngestSharesJob) ingestClosedBlocks() {
}
}
func (this *IngestSharesJob) ingestBlockDir(db *clover.DB, dirPath string) {
func (this *IngestSharesJob) ingestBlockDir(db *pgxpool.Pool, dirPath string) {
files, err := os.ReadDir(dirPath)
if err != nil {
log.Printf("Failed to read block dir %s: %v", dirPath, err)
@@ -97,8 +96,7 @@ func (this *IngestSharesJob) ingestBlockDir(db *clover.DB, dirPath string) {
continue
}
doc := document.NewDocumentOf(&share)
if _, err := db.InsertOne(database.CollectionName, doc); err != nil {
if err := database.InsertShare(db, share); err != nil {
log.Println("DB insert error:", err)
}
}