mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-07-19 13:19:42 +02:00
🤩MongoDB support 🤩 (#272)
* implement configuration through YAML * remove rcparser * use password from appConfig * update docker configs * fix dockerignore * implement mongodb driver * update eslint packages * fix bugs * refactor code for grouping by parent * fix yet another bug * use unique symbol to the EntityId type * fix more bugs * implement db converter * fix bug with parent selector * fix eslint * db-converter refactoring * create cli program for db-converter * add readme and gitignore * update development docs * update development docs and default config * add docs about converter * add src/test to docker ignore * move database code from utils * improve docs * eslint fix * add more docs * fix docs * remove env_file from docker-compose * implement duplicate detection in db-converter * use published version of the config-loader * fix bug * Update DEVELOPMENT.md Co-authored-by: Ilya Maroz <37909603+ilyamore88@users.noreply.github.com> * fix bugs * fix next/prev buttons * fix more bugs * fix sorting Co-authored-by: Ilya Maroz <37909603+ilyamore88@users.noreply.github.com>
This commit is contained in:
parent
13762096c4
commit
55b4b3ee61
72 changed files with 12614 additions and 665 deletions
70
bin/db-converter/index.js
Normal file
70
bin/db-converter/index.js
Normal file
|
@ -0,0 +1,70 @@
|
|||
import './program.js';
|
||||
import {ObjectId} from 'mongodb';
|
||||
import {closeConnection, getFromLocalDB, saveData} from './lib.js';
|
||||
|
||||
console.log('Start converting...');
|
||||
const [pages, aliases, files, pagesOrder] = ['pages', 'aliases', 'files', 'pagesOrder'].map(getFromLocalDB);
|
||||
|
||||
const pagesIdsMap = pages.reduce((acc, curr) => {
|
||||
const newId = new ObjectId();
|
||||
|
||||
if (acc.has(curr._id)) {
|
||||
console.log(`Duplicate id detected ${curr._id}. Skipping it`);
|
||||
}
|
||||
|
||||
acc.set(curr._id, newId);
|
||||
|
||||
return acc;
|
||||
}, new Map());
|
||||
|
||||
// Explicitly set the root page id
|
||||
pagesIdsMap.set('0', '0');
|
||||
|
||||
const newPages = [];
|
||||
|
||||
pagesIdsMap.forEach((newId, oldId) => {
|
||||
if (newId === '0') {
|
||||
return
|
||||
}
|
||||
const page = pages.find((p) => p._id === oldId);
|
||||
newPages.push({
|
||||
...page,
|
||||
_id: newId,
|
||||
parent: page.parent ? pagesIdsMap.get(page.parent) : null,
|
||||
});
|
||||
});
|
||||
|
||||
await saveData('pages', newPages);
|
||||
|
||||
const newAliases = aliases.map(alias => {
|
||||
return {
|
||||
...alias,
|
||||
_id: new ObjectId(),
|
||||
id: pagesIdsMap.get(alias.id),
|
||||
};
|
||||
});
|
||||
|
||||
await saveData('aliases', newAliases);
|
||||
|
||||
const newFiles = files.map(file => {
|
||||
return {
|
||||
...file,
|
||||
_id: new ObjectId(),
|
||||
};
|
||||
});
|
||||
|
||||
await saveData('files', newFiles);
|
||||
|
||||
const newPagesOrder = pagesOrder.map(pageOrder => {
|
||||
return {
|
||||
...pageOrder,
|
||||
_id: new ObjectId(),
|
||||
page: pagesIdsMap.get(pageOrder.page),
|
||||
order: pageOrder.order.map(page => pagesIdsMap.get(page)),
|
||||
};
|
||||
});
|
||||
|
||||
await saveData('pagesOrder', newPagesOrder);
|
||||
|
||||
await closeConnection();
|
||||
console.log('Done!');
|
Loading…
Add table
Add a link
Reference in a new issue