From 04057aa94ad7b015306a3763c7e7e7e62130cdd6 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 29 Jan 2018 15:17:55 -0700 Subject: [PATCH] migrate from v1.2 --- lib/store.json.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/store.json.js b/lib/store.json.js index 5c33496..7c532f3 100644 --- a/lib/store.json.js +++ b/lib/store.json.js @@ -11,11 +11,21 @@ module.exports.create = function (opts) { var db = require(opts.filepath); var stat = require('fs').statSync(opts.filepath); var crypto = require('crypto'); - db.primaryNameservers.forEach(function (ns) { + // + // Manual Migration + // + db.primaryNameservers.forEach(function (ns, i, arr) { + if ('string' === typeof ns) { + arr[i] = { name: ns }; + } if (!ns.id) { ns.id = crypto.randomBytes(16).toString('hex'); } }); + db.zones = db.zones || []; + if (db.domains) { + db.zones = db.zones.concat(db.domains); + } db.zones.forEach(function (zone) { if (!zone.name) { zone.name = zone.id; @@ -32,6 +42,11 @@ module.exports.create = function (opts) { record.id = crypto.randomBytes(16).toString('hex'); } }); + require('fs').writeFileSync(opts.filepath, JSON.stringify(db, null, 2)); + // + // End Migration + // + db.save = function (cb) { if (db.save._saving) { console.log('make pending'); @@ -55,7 +70,6 @@ module.exports.create = function (opts) { }); }; db.save._pending = []; - require('fs').writeFileSync(opts.filepath, JSON.stringify(db, null, 2)); engine.primaryNameservers = db.primaryNameservers; engine.zoneToSoa = function (domain) {