pubkey / rxdb

A fast, local first, reactive Database for JavaScript Applications https://rxdb.info/
https://rxdb.info/
Apache License 2.0
21k stars 1.02k forks source link

autoMigrate cause infinite loop in electron app #212

Closed jonymei closed 7 years ago

jonymei commented 7 years ago

old schema(without title filed):

const notesSchema = {
    version: 0,
    title: 'naotes schema',
    description: 'descript a note',
    type: 'object',
    properties: {
        id : {
            type: 'string',
            primary: true
        },
        content: {
            type: 'string'
        }
    },
    required: ['content']
}

new schema:

const notesSchema = {
    version: 1,
    title: 'naotes schema',
    description: 'descript a note',
    type: 'object',
    properties: {
        id : {
            type: 'string',
            primary: true
        },
        content: {
            type: 'string'
        },
        title: {
            type: 'string'
        }
    },
    required: ['content']
}

create collection:

db.collection({
    name: 'notes',
    schema: notesSchema,
    migrationStrategies: {
        1: (oldDoc) => {
            console.log('migrate from 0 to 1...' + oldDoc.id)
            oldDoc.title = 'test title'
            return oldDoc
        }
    }
})

run app and log will be print all the time.

pubkey commented 7 years ago

Hi @ahumeijun I tried to reproduce this but couldnt. Can you fork this repo and reproduce the problem in the electron-example?

jonymei commented 7 years ago

thanks for your reply. I had reproduced this bug on my repo. But I got an error Uncaught Error: Cannot find module 'babel-runtime/helpers/typeof' when I run the eletron app use command npm start. So I use rxdb module instead of source code. Is this the cause of the bug? my repo: rxdb

pubkey commented 7 years ago

@ahumeijun thank you for sharing your repo. This helped a lot. The problem was that the primary-key was not translated back, when the migrated document got deleted from the old pouchdb-instance.