|
@ -1,16 +1,12 @@ |
|
|
// @flow
|
|
|
// @flow
|
|
|
|
|
|
|
|
|
import fs from 'fs' |
|
|
|
|
|
import path from 'path' |
|
|
import path from 'path' |
|
|
|
|
|
|
|
|
import { promisify } from 'helpers/promise' |
|
|
import { fsReadFile, fsUnlink } from 'helpers/fs' |
|
|
import db from 'helpers/db' |
|
|
import db from 'helpers/db' |
|
|
|
|
|
|
|
|
import type { Migration } from './types' |
|
|
import type { Migration } from './types' |
|
|
|
|
|
|
|
|
const fsReadfile = promisify(fs.readFile) |
|
|
|
|
|
const fsUnlink = promisify(fs.unlink) |
|
|
|
|
|
|
|
|
|
|
|
const migrations: Migration[] = [ |
|
|
const migrations: Migration[] = [ |
|
|
{ |
|
|
{ |
|
|
doc: 'merging multiple db files into one app file', |
|
|
doc: 'merging multiple db files into one app file', |
|
@ -54,13 +50,13 @@ async function getFileData(dbPath, fileName) { |
|
|
const filePath = path.join(dbPath, `${fileName}.json`) |
|
|
const filePath = path.join(dbPath, `${fileName}.json`) |
|
|
let finalData |
|
|
let finalData |
|
|
try { |
|
|
try { |
|
|
const fileContent = await fsReadfile(filePath, 'utf-8') |
|
|
const fileContent = await fsReadFile(filePath, 'utf-8') |
|
|
const { data } = JSON.parse(fileContent) |
|
|
const { data } = JSON.parse(fileContent) |
|
|
finalData = data |
|
|
finalData = data |
|
|
} catch (err) { |
|
|
} catch (err) { |
|
|
// we assume we are in that case because file is encrypted
|
|
|
// we assume we are in that case because file is encrypted
|
|
|
if (err instanceof SyntaxError) { |
|
|
if (err instanceof SyntaxError) { |
|
|
const buf = await fsReadfile(filePath) |
|
|
const buf = await fsReadFile(filePath) |
|
|
return buf.toString('base64') |
|
|
return buf.toString('base64') |
|
|
} |
|
|
} |
|
|
// will be stripped down by JSON.stringify
|
|
|
// will be stripped down by JSON.stringify
|
|
|