@sol-x/couchdb-migration-store
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -15,3 +15,4 @@ "use strict"; | ||
} | ||
this.couchDbWaitTime = parseInt(process.env.COUCHDB_WAIT_TIME || "0") || 10 * 1000; | ||
this.couchDbWaitTime = | ||
parseInt(process.env.COUCHDB_WAIT_TIME || "0") || 10 * 1000; | ||
this.couchDbUrl = couchDbUrl; | ||
@@ -24,6 +25,20 @@ } | ||
}); | ||
const nano = nano_1.default(this.couchDbUrl); | ||
const allDbs = await nano.db.list(); | ||
if (!allDbs.includes(MIGRATION_DB_NAME)) { | ||
await nano.db.create(MIGRATION_DB_NAME); | ||
} | ||
return nano.use(MIGRATION_DB_NAME); | ||
} | ||
async getMigrationDocument(db, docId) { | ||
try { | ||
return await db.get(docId, { revs_info: true }); | ||
} | ||
catch (e) { | ||
return; | ||
} | ||
} | ||
async save(migrationData, callback) { | ||
const { lastRun } = migrationData; | ||
const migrations = migrationData.migrations.map(migration => ({ | ||
const migrations = migrationData.migrations.map((migration) => ({ | ||
title: migration.title, | ||
@@ -34,23 +49,14 @@ timestamp: migration.timestamp, | ||
try { | ||
await this.waitForCouchdb(); | ||
} | ||
catch (err) { | ||
callback(err); | ||
return; | ||
} | ||
const nano = nano_1.default(this.couchDbUrl); | ||
try { | ||
await nano.db.destroy(MIGRATION_DB_NAME); | ||
} | ||
catch (_a) { | ||
} | ||
finally { | ||
await nano.db.create(MIGRATION_DB_NAME); | ||
} | ||
try { | ||
const db = nano.use(MIGRATION_DB_NAME); | ||
await db.insert(dataToStore); | ||
const db = await this.waitForCouchdb(); | ||
const dataInStore = await this.getMigrationDocument(db, "1"); | ||
if (dataInStore && dataInStore._rev) { | ||
await db.insert({ ...dataToStore, _rev: dataInStore._rev }); | ||
} | ||
else { | ||
await db.insert(dataToStore); | ||
} | ||
callback(undefined); | ||
} | ||
catch (e) { | ||
console.error(`Encounter error when running migration ${lastRun}`); | ||
callback(e); | ||
@@ -61,11 +67,3 @@ } | ||
try { | ||
await this.waitForCouchdb(); | ||
} | ||
catch (err) { | ||
callback(err); | ||
return; | ||
} | ||
const nano = nano_1.default(this.couchDbUrl); | ||
try { | ||
const db = nano.use(MIGRATION_DB_NAME); | ||
const db = await this.waitForCouchdb(); | ||
const data = await db.find({ limit: 1, selector: {} }); | ||
@@ -81,3 +79,3 @@ const { docs } = data; | ||
catch (e) { | ||
callback(undefined, {}); | ||
callback(e, {}); | ||
} | ||
@@ -84,0 +82,0 @@ } |
{ | ||
"name": "@sol-x/couchdb-migration-store", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "couchdb migration store for node-migrate", | ||
"main": "dist/index.js", | ||
"files": [ | ||
"dist/**/*" | ||
], | ||
"scripts": { | ||
@@ -27,3 +30,3 @@ "build": "tsc", | ||
"dependencies": { | ||
"nano": "git://github.com/sol-x/couchdb-nano.git#8.1.3", | ||
"nano": "^8.2.3", | ||
"wait-on": "^3.3.0" | ||
@@ -30,0 +33,0 @@ }, |
Sorry, the diff of this file is not supported yet
Git dependency
Supply chain riskContains a dependency which resolves to a remote git URL. Dependencies fetched from git URLs are not immutable and can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
1
4
0
6172
4
79
+ Added@types/caseless@0.12.5(transitive)
+ Added@types/node@22.13.1(transitive)
+ Added@types/request@2.48.12(transitive)
+ Added@types/tough-cookie@4.0.5(transitive)
+ Addedbrowser-request@0.3.3(transitive)
+ Addedcloudant-follow@0.18.2(transitive)
+ Addeddebug@4.4.0(transitive)
+ Addederrs@0.3.2(transitive)
+ Addedform-data@2.5.2(transitive)
+ Addedms@2.1.3(transitive)
+ Addednano@8.2.3(transitive)
+ Addedundici-types@6.20.0(transitive)
Updatednano@^8.2.3