cozy/cozy-mobile

View on GitHub
src/app/migrations/2.0.0.coffee

Summary

Maintainability
Test Coverage
module.exports =


    migrate: (callback) ->
        config = app.init.config
        defaultConfig = config.getDefault()
        replicateDb = app.init.database.replicateDb
        newConfig = {}

        replicateDb.get defaultConfig._id, (err, doc) ->
            return callback err if err

            # remove auth
            # remove lastInitState
            # add state
            for key of defaultConfig
                if key of doc
                    newConfig[key] = doc[key]
                else
                    newConfig[key] = defaultConfig[key]

            if newConfig.state is 'syncCompleted'
                newConfig.state = 'appConfigured'

            newConfig._rev = doc._rev

            config.setConfigValue newConfig
            replicateDb.put newConfig, callback