rxdb: Migrations do not work with LokiJS adapter

Hello!

Looks like data migrations (rxdb/plugins/migration) don’t work when I am using LokiJS adapter: migration function does run, but all the data just disappears (surprisingly it somewhat returns back after a few refreshes of the page).

I found that unit tests for migrations work only for pouchdb and I don’t know how to make them work with loki or other adapters. So I made a repository with the bug reproduction. It is nextjs project with two pages:

  1. Db is initialized here https://github.com/11bit/repro-rxdb-lokijs-migrations-bug/blob/main/db/db.ts

  2. On the index page I am wiping all the data from indexeddb and then creating a simple document with schema version 0 https://github.com/11bit/repro-rxdb-lokijs-migrations-bug/blob/main/pages/index.tsx#L11-L17

  3. On the ‘/migrate’ page I am trying to migrate the created document to schema version 1 https://github.com/11bit/repro-rxdb-lokijs-migrations-bug/blob/main/pages/migrate.tsx#L11-L19

After running ‘/migrate’ page I don’t see any documents at all. But if I refresh the page a couple of times I can see an old document without any migrations applied. However, If I switch to pouchdb adapter, everything works well.

Is it something I am doing wrong with migrations or it’s a bug?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 15 (13 by maintainers)

Most upvoted comments

This might be fixed in the latest beta release. Please try.

@pubkey We have not had this happen on past migrations but it looks like in our project when we updated our PWA we also saw some of our Loki collections attempt to push migrated documents as replications. Seems to be similar to what @11bit mentioned above, any clue why this might be happening?

We are using rxDB 12.0.8 with LokiJS and a service worker

@alex-hladun all planned changes have been implemented to version 12.0.0. I am currently also migrating an app to use 12.0.0 in production.

@11bit yes, ignoreDuplicate must be used. Migration keeps the revisions of the documents, so they should not be pushed again. But I am not sure if that is true when you migration from RxDB 11->12.