ensure we dont collect hourly snapshot too soon after startup
Some checks failed
continuous-integration/drone/push Build was killed
Some checks failed
continuous-integration/drone/push Build was killed
This commit is contained in:
@@ -361,6 +361,38 @@ ORDER BY snapshot_time ASC, table_name ASC
|
||||
return records, rows.Err()
|
||||
}
|
||||
|
||||
func LatestSnapshotTime(ctx context.Context, database db.Database, snapshotType string) (time.Time, error) {
|
||||
dbConn := database.DB()
|
||||
driver := strings.ToLower(dbConn.DriverName())
|
||||
|
||||
var maxTime sql.NullInt64
|
||||
switch driver {
|
||||
case "sqlite":
|
||||
if err := dbConn.GetContext(ctx, &maxTime, `
|
||||
SELECT MAX(snapshot_time)
|
||||
FROM snapshot_registry
|
||||
WHERE snapshot_type = ?
|
||||
`, snapshotType); err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
case "pgx", "postgres":
|
||||
if err := dbConn.GetContext(ctx, &maxTime, `
|
||||
SELECT MAX(snapshot_time)
|
||||
FROM snapshot_registry
|
||||
WHERE snapshot_type = $1
|
||||
`, snapshotType); err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
default:
|
||||
return time.Time{}, fmt.Errorf("unsupported driver for listing snapshots: %s", driver)
|
||||
}
|
||||
|
||||
if !maxTime.Valid || maxTime.Int64 <= 0 {
|
||||
return time.Time{}, nil
|
||||
}
|
||||
return time.Unix(maxTime.Int64, 0), nil
|
||||
}
|
||||
|
||||
func FormatSnapshotLabel(snapshotType string, snapshotTime time.Time, tableName string) string {
|
||||
switch snapshotType {
|
||||
case "hourly":
|
||||
|
||||
Reference in New Issue
Block a user