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: Correctly ignore archived rolling databases.

## 0.2.21 (2025-05-12)

- added: A new `CouchPool` class that can be passed to `setupDatabase`. This will create databases across multiple clusters.
Expand Down
21 changes: 12 additions & 9 deletions src/couchdb/rolling-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import nano, {

import {
asCouchDoc,
connectCouch,
CouchDoc,
CouchPool,
DatabaseSetup,
Expand Down Expand Up @@ -447,12 +448,12 @@ export function makeRollingDatabase<T>(
}

async function setup(
pool: CouchPool | ServerScope,
poolOrConnection: CouchPool | ServerScope,
opts: SetupDatabaseOptions = {}
): Promise<() => void> {
let cleanups: Array<() => void> = []
const {
currentCluster,
currentCluster = 'default',
disableWatching = false,
log = console.log,
watchCluster,
Expand All @@ -462,6 +463,14 @@ export function makeRollingDatabase<T>(
replicatorSetup = setupInfo.replicatorSetup
} = opts

// Backwards-compatibility glue:
const pool =
'relax' in poolOrConnection
? connectCouch(currentCluster, { [currentCluster]: poolOrConnection })
: poolOrConnection
const connection =
watchCluster == null ? pool.default : pool.connect(watchCluster)

// Ensure we have a list database:
const listDbSetup: DatabaseSetup = {
name: `${name}-list`,
Expand All @@ -471,12 +480,6 @@ export function makeRollingDatabase<T>(
}
}
const listDbCleanup = await setupDatabase(pool, listDbSetup, opts)
const connection =
'relax' in pool
? pool
: watchCluster == null
? pool.default
: pool.connect(watchCluster)
const listDb = connection.use(listDbSetup.name)

/**
Expand Down Expand Up @@ -545,7 +548,7 @@ export function makeRollingDatabase<T>(
}
const { exists } = clusterHasDatabase(
replicatorSetup?.doc,
currentCluster,
pool.defaultName,
setup
)
if (exists) {
Expand Down
Loading