Added database.change_batch_retention, deleting old change batches

Each save that records a batch also deletes, in the same
transaction, the batches older than database.change_batch_retention
(30 days by default; 0 or less keeps them for ever), with their
records of opportunities. A client still holding a deleted batch
gets 410 Gone from ?changed_after= and reloads the whole list, as
for any unknown batch.
This commit is contained in:
bwilliams committed 2026-10-16 16:10:32 +01:00
1 parent 1988d07a29
commit 65e5bc6b26
10 files changed
+153 -19

No files matched your search

+13 -1
View File
@@ -3,13 +3,15 @@ package store
import (
"database/sql"
"fmt"
"time"
)
// Option configures Open.
type Option func(*options)
type options struct {
autoMigrate bool
autoMigrate bool
changeBatchRetention time.Duration
}
// OpenDB opens the SQLite database at path with the store's connection
@@ -29,6 +31,16 @@ func WithAutoMigrate() Option {
}
}
// WithChangeBatchRetention makes the store delete change batches older than
// retention whenever it records a new one, so a client can catch up from a
// batch for that long (see ListChangedOpportunities). Without it, or with 0
// or less, batches are kept for ever.
func WithChangeBatchRetention(retention time.Duration) Option {
return func(opts *options) {
opts.changeBatchRetention = retention
}
}
// dsn builds the mattn/go-sqlite3 connection string.
//
// - _foreign_keys: SQLite ignores REFERENCES clauses unless this is on.