-
Notifications
You must be signed in to change notification settings - Fork 373
Legacy data migration
Here's some scripts to migrate legacy data. If you don't know how to use the scripts below, please join our slack and send a DM to me(@rokt33r)
Boost Note Slack https://join.slack.com/t/boostnote-group/shared_invite/zt-cun7pas3-WwkaezxHBB1lCbUHrwQLXw
Run the script below from console of the dev tools after modifying $EXTRACT_DESTINATION_DIR
.
extract('$EXTRACT_DESTINATION_DIR')
function extract(destination) {
const fs = require('fs')
const path = require('path')
tryCreateFolder(destination)
JSON.parse(localStorage.getItem('note.boostio.co:storageDataList')).map(
async (storage) => {
if (storage.type === 'fs') {
return
}
const db = await promisify(indexedDB.open(`_pouch_${storage.id}`))
const docs = await promisify(
db.transaction('document-store').objectStore('document-store').getAll()
)
const revs = await promisify(
db.transaction('by-sequence').objectStore('by-sequence').getAll()
)
const revMap = revs.reduce((map, rev) => {
map.set(rev._doc_id_rev, rev)
return map
}, new Map())
const noteDocs = docs
.filter((doc) => {
return /^note:/.test(doc.id)
})
.map((pouchDoc) => {
return {
_id: pouchDoc.id,
...revMap.get(pouchDoc.id + '::' + pouchDoc.winningRev),
}
})
const storageDumpDestination = path.join(
destination,
`${storage.name}-${storage.id}`
)
tryCreateFolder(storageDumpDestination)
tryCreateFolder(path.join(storageDumpDestination, 'notes'))
for (const noteDoc of noteDocs) {
const fileName = `${noteDoc._id.slice('note:'.length)}.json`
fs.writeFileSync(
path.join(storageDumpDestination, 'notes', fileName),
JSON.stringify(noteDoc)
)
}
}
)
function promisify(req) {
return new Promise((res, rej) => {
req.onsuccess = (event) => {
res(event.target.result)
}
})
}
function tryCreateFolder(pathname) {
try {
fs.mkdirSync(pathname)
} catch (error) {
if (error.code === 'EEXIST') {
return
}
throw error
}
}
}
Then all docs from the legacy cloud storage will be extracted and converted to file system based storage format like the below.
You can load each of them by creating a storage via the local app(BoostNote.next-local). You should choose $STORAGE_NAME-$STORAGE_ID
directories instead of $STORAGE_NAME-$STORAGE_ID/notes
directories or you need to wipe the extracted data and run the extract script again.
$DESTINATION_DIR
|-- $STORAGE_NAME-$STORAGE_ID
|-- notes
|-- $NOTE_ID.json
|-- $NOTE_ID.json
|-- ...
|-- $STORAGE_NAME-$STORAGE_ID
|-- notes
|-- $NOTE_ID.json
|-- $NOTE_ID.json
|-- ...
|-- ...
Local app data -> Cloud Space(https://boostnote.io)
To be announced....