mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-09 07:25:21 +02:00
add migration
This commit is contained in:
parent
79e4c755a9
commit
d9dc2bf96b
1 changed files with 21 additions and 4 deletions
|
@ -4,14 +4,31 @@ const config = require('../../../config');
|
||||||
const db = new Datastore({filename: `./${config.database}/pagesOrder.db`, autoload: true});
|
const db = new Datastore({filename: `./${config.database}/pagesOrder.db`, autoload: true});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Current DataStore preparation
|
||||||
* Add initial row for RootPage
|
* Add initial row for RootPage
|
||||||
*/
|
*/
|
||||||
(async function() {
|
(async function() {
|
||||||
const initialData = {
|
const parentIdOfRootPages = '0';
|
||||||
page: '0',
|
const cbk = (resolve, reject) => (err, doc) => {
|
||||||
order: []
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(doc);
|
||||||
};
|
};
|
||||||
await db.insert(initialData);
|
|
||||||
|
const order = await new Promise((resolve, reject) => {
|
||||||
|
db.findOne({page: parentIdOfRootPages}, cbk(resolve, reject));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!order) {
|
||||||
|
const initialData = {
|
||||||
|
page: '0',
|
||||||
|
order: []
|
||||||
|
};
|
||||||
|
await db.insert(initialData);
|
||||||
|
}
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|
||||||
module.exports = db;
|
module.exports = db;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue