Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- fixed: Do not create rolling-database list entries on `syncOnly` processes, so a sync-only process can no longer register a period database it will not physically create.

## 0.2.24 (2026-03-18)

- added: `syncedDocument` accepts an optional `SyncedDocumentOptions` object with `cleanFailStrategy` (`'preserve'` to keep the last good value, `'reset'` to revert to defaults) and `onCleanFail` callback for notification when the cleaner rejects a document.
Expand Down
46 changes: 29 additions & 17 deletions src/couchdb/rolling-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ export function makeRollingDatabase<T>(
currentCluster = 'default',
disableWatching = false,
log = console.log,
syncOnly = false,
watchCluster,
onError = error => {
log(`Error while maintaining "${name}" databases: ${String(error)}`)
Expand Down Expand Up @@ -514,27 +515,38 @@ export function makeRollingDatabase<T>(
list = [{ archived, name, startDate }, ...list]
}

// Create past databases if the list is empty:
if (list.length === 0) {
if (archiveStart == null) {
const [date, suffix] = pickPeriodicMonth(now, period, false)
await addDb(`${name}-${suffix}`, date)
} else {
for (
let [date, suffix] = pickPeriodicMonth(archiveStart, 'year', false);
date.valueOf() < now.valueOf();
[date, suffix] = pickPeriodicMonth(date, 'year', true)
) {
// Only the authoritative (non-syncOnly) process may mutate the list.
// A syncOnly process reads the list and targets queries, but must never
// append a doc it cannot back with a physical database:
if (!syncOnly) {
// Create past databases if the list is empty:
if (list.length === 0) {
if (archiveStart == null) {
const [date, suffix] = pickPeriodicMonth(now, period, false)
await addDb(`${name}-${suffix}`, date)
} else {
for (
let [date, suffix] = pickPeriodicMonth(
archiveStart,
'year',
false
);
date.valueOf() < now.valueOf();
[date, suffix] = pickPeriodicMonth(date, 'year', true)
) {
await addDb(`${name}-${suffix}`, date)
}
}
}
}

// Always keep one spare database in the future:
const lastStart = list[0].startDate
if (lastStart.valueOf() < now.valueOf()) {
const [date, suffix] = pickPeriodicMonth(now, period, true)
await addDb(`${name}-${suffix}`, date)
// Always keep one spare database in the future:
if (list.length > 0) {
const lastStart = list[0].startDate
if (lastStart.valueOf() < now.valueOf()) {
const [date, suffix] = pickPeriodicMonth(now, period, true)
await addDb(`${name}-${suffix}`, date)
}
}
}

// Reset the cleanup list:
Expand Down
Loading