Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: migrate schema with multiple connected storages #7008

Conversation

jameshclrk
Copy link
Contributor

@jameshclrk jameshclrk commented Mar 25, 2025

This PR contains:

A test case for #7009

Describe the problem you have without this PR

If a collection has multiple connected storages, for example with multiple replication handlers, there is a race condition where the underlying collection used for the migration is removed because the name is the same (see sqlite-trial error).

I haven't tried all storages, but I have seen it on memory and sqlite-trial.

error with npm run test:node:memory

     RxError (DM4):

Error message: Migration errored
Error code: DM4
Find out more about this error here: https://rxdb.info/errors.html?console=errors#DM4

--------------------
Parameters:
collection: "mycollection"
error: {
  "name": "Error",
  "message": "removed",
  "rxdb": null,
  "parameters": null,
  "extensions": null,
  "code": null,
  "url": null,
  "stack": "Error: removed \n     at ensureNotRemoved (file:///Users/jamesclark/code/rxdb/src/plugins/storage-memory/memory-helper.ts:36:15) \n     at RxStorageInstanceMemory.oldBulkWrite [as bulkWrite] (file:///Users/jamesclark/code/rxdb/src/plugins/storage-memory/rx-storage-instance-memory.ts:108:9) \n     at RxStorageInstanceMemory.bulkWrite (file:///Users/jamesclark/code/rxdb/src/plugin-helpers.ts:129:29) \n     at file:///Users/jamesclark/code/rxdb/src/replication-protocol/upstream.ts:441:48"
}

error with npm run test:node:sqlite-trial

Error: no such table: rx-migration-state-meta-mycollection-1-0
    at Object.all (file:///Users/jamesclark/code/rxdb/src/plugins/storage-sqlite/sqlite-basics-helpers.ts:94:33)
    at sqliteTransaction.databaseName (file:///Users/jamesclark/code/rxdb/src/plugins/storage-sqlite/sqlite-storage-instance.ts:128:32)
    at file:///Users/jamesclark/code/rxdb/src/plugins/storage-sqlite/sqlite-helpers.ts:179:31
{
    "code": "ERR_SQLITE_ERROR",
    "errcode": 1,
    "errstr": "SQL logic error"
}

Todos

  • Tests
  • Documentation
  • Typings
  • Changelog

@pubkey
Copy link
Owner

pubkey commented Mar 26, 2025

You have to close the old database before creating a new one with a changed schema.

@jameshclrk
Copy link
Contributor Author

You have to close the old database before creating a new one with a changed schema.

I added an await db.close() before creating the second database and still see an error thrown.

@pubkey
Copy link
Owner

pubkey commented Mar 31, 2025

@jameshclrk Thank you for the test case, this helps a lot. Could reproduce your error, working on a fix..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants