Ship live alerts, pool status, AI monitor, remote agent commands, build manager, and uninstall flow; wire Calibrate settings (WS ping, pool traffic log, retention limits) at runtime and exclude server/data from git.
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
package db
|
|
|
|
import (
|
|
"time"
|
|
|
|
"crypto-miner-server/internal/models"
|
|
)
|
|
|
|
// PurgeHashrateSamplesBefore deletes samples older than cutoff.
|
|
func (d *Database) PurgeHashrateSamplesBefore(cutoff time.Time) (int64, error) {
|
|
res, err := d.Exec("DELETE FROM hashrate_samples WHERE timestamp < ?", cutoff)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return res.RowsAffected()
|
|
}
|
|
|
|
// ListBuildsOlderThan returns build records created before cutoff.
|
|
func (d *Database) ListBuildsOlderThan(cutoff time.Time) ([]*models.BuildRecord, error) {
|
|
rows, err := d.Query(`SELECT id, worker_name, server_url, wallet, threads, file_size, file_path, created_at, pool_host, pool_port, pool_tls, pool_pass FROM builds WHERE created_at < ?`, cutoff)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var out []*models.BuildRecord
|
|
for rows.Next() {
|
|
b := &models.BuildRecord{}
|
|
if err := rows.Scan(&b.ID, &b.WorkerName, &b.ServerURL, &b.Wallet, &b.Threads, &b.FileSize, &b.FilePath, &b.CreatedAt,
|
|
&b.PoolHost, &b.PoolPort, &b.PoolTLS, &b.PoolPass); err != nil {
|
|
return nil, err
|
|
}
|
|
out = append(out, b)
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// DeleteBuild removes a build record by id.
|
|
func (d *Database) DeleteBuild(id string) error {
|
|
_, err := d.Exec("DELETE FROM builds WHERE id = ?", id)
|
|
return err
|
|
}
|