diff --git a/CHANGELOG.md b/CHANGELOG.md index 0520971..38fdb0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/couchdb/rolling-database.ts b/src/couchdb/rolling-database.ts index f285543..9a44131 100644 --- a/src/couchdb/rolling-database.ts +++ b/src/couchdb/rolling-database.ts @@ -17,6 +17,7 @@ import nano, { import { asCouchDoc, + connectCouch, CouchDoc, CouchPool, DatabaseSetup, @@ -447,12 +448,12 @@ export function makeRollingDatabase( } 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, @@ -462,6 +463,14 @@ export function makeRollingDatabase( 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`, @@ -471,12 +480,6 @@ export function makeRollingDatabase( } } 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) /** @@ -545,7 +548,7 @@ export function makeRollingDatabase( } const { exists } = clusterHasDatabase( replicatorSetup?.doc, - currentCluster, + pool.defaultName, setup ) if (exists) {