dexie/Dexie.js

Table schema with hidden primary key cannot be imported after upgrading to v3

Open

#1,050 建立於 2020年5月15日

在 GitHub 查看
 (3 留言) (0 反應) (0 負責人)JavaScript (10,304 star) (625 fork)batch import
good first issue

描述

After reading that there were no major breaking changes when upgrading Dexie from 2.x to 3.x, I’m currently trying to upgrade one of my applications. However, in doing so, I have noticed that I cannot import a database that was exported with Dexie v2.x and dexie-export-import after the upgrade.

The import failed because the primary key of one of my tables was detected as having changed – which is not true (in the sense that I didn’t change it). That table is defined with a hidden primary key:

db.version(1).stores({
  //...other tables...
  user: '',
});

A file exported via dexie-export-import in v2 lists the table as follows:

{
  "name": "user",
  "schema": "null",
  "rowCount": 3
}

While a file exported with v3 lists that table as follows:

{
  "name": "user",
  "schema": "",
  "rowCount": 3
}

Removing the null in the Dexie v2 export and then importing that after the upgrade to Dexie v3 no longer causes the error and the import succeeds. My guess is that Dexie v3 expects a hidden primary key to be an empty string so when it sees "null" instead it regards the key as changed and throws the error.

I’m not sure if this is a bug in dexie-export-import or simply a breaking change in Dexie v3, but if it’s the latter I think it should be listed somewhere discoverable.

If this is not a bug, what would be the correct upgrade path to take? Since there might be users out there that exported their databases and I can hardly tell them to "remove that null in the exported file before re-importing it".

Thank you for this awesome library and your time! Have a good weekend.

貢獻者指南

Table schema with hidden primary key cannot be imported after upgrading to v3 · dexie/Dexie.js#1050 | Good First Issue