I have an objectStore created with:

    db.createObjectStore('mystore', {autoIncrement: true})
      .createIndex('myindex', 'myindex', {unique: true});

I need to amend the schema to use inline keys, like:

    db.createObjectStore('mystore', {autoIncrement: true, keyPath: 'seq'})
      .createIndex('myindex', 'myindex', {unique: true});

I dont see any way to modify the object store like that inside a migration

有帮助吗?

解决方案

Unfortunately the primary key for an object store cannot be changed after that object store's creation.

To migrate, you'll have to create a new store with your inline key and then copy over the data.

I'm guessing this is related to your other question. Note that you don't need inline keys to use puts. The IDBIndex exposes a put() method as well. You can likely achieve what you're looking for by adding a new index and using it to put() your records.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top