diff --git a/src/config.js b/src/config.js index 0e3d6f5..11a46fd 100644 --- a/src/config.js +++ b/src/config.js @@ -28,17 +28,17 @@ exports.getConfig = async () => { if (!_config.storeState) { const statePath = path.join(configDir, 'exodus.state.json') _config.storeState = async (state) => { - return fs.writeFile(statePath, state, 'utf8') + return fs.writeFile(statePath, JSON.stringify(state, null, 2), 'utf8') } } if (!_config.fetchState) { _config.fetchState = async () => { const statePath = path.join(configDir, 'exodus.state.json') try { - return await fs.readFile(statePath, 'utf8') + return JSON.parse(await fs.readFile(statePath, 'utf8')) } catch (err) { if (err.code !== 'ENOENT') throw err - return '{}' + return {} } } } @@ -50,9 +50,8 @@ const defaultConfig = { // The folder to store migration scripts in. migrationsDirectory: './migrations', - // Persists the current migration state. The `state` - // argument will always be a JSON-serialized object. - // Store it to redis, disk, database, ... whatever suits you. + // Persists the current migration state. The `state` argument + // will always be an object. Store it as JSON to redis, disk, etc. // OPTIONAL: If undefined, Exodus falls back to exodus.state.json // storeState: async (state, context) => {}, diff --git a/src/index.js b/src/index.js index 8fd2885..6a7560e 100644 --- a/src/index.js +++ b/src/index.js @@ -45,7 +45,7 @@ exports.run = async () => { const files = await listDirectoryFiles(config.migrationsDirectory) // figure out which ones havent already been ran - const state = JSON.parse(await config.fetchState(context)) + const state = await config.fetchState(context) state.history = state.history || [] // create an ID for our round so we can undo latest batch later @@ -87,7 +87,7 @@ exports.run = async () => { state.history.forEach((job) => { delete job.path }) - await config.storeState(JSON.stringify(state), context) + await config.storeState(state, context) return { state, ranMigrations: pendingMigrations } } diff --git a/src/templates/config.js b/src/templates/config.js index 26cee2d..d6cb1a4 100644 --- a/src/templates/config.js +++ b/src/templates/config.js @@ -2,9 +2,8 @@ module.exports = exports = { // The folder to store migration scripts in. // migrationsDirectory: './migrations', - // Persists the current migration state. The `state` - // argument will always be a JSON-serialized object. - // Store it to redis, disk, database, ... whatever suits you. + // Persists the current migration state. The `state` argument + // will always be an object. Store it as JSON to redis, disk, etc. // OPTIONAL: If undefined, Exodus falls back to exodus.state.json // storeState: async (state, context) => {},