dexie / Dexie.js

A Minimalistic Wrapper for IndexedDB
https://dexie.org
Apache License 2.0
11.58k stars 642 forks source link

Trying to add store. Getting "Dexie specification of currently installed DB version is missing" #491

Closed nbrustein closed 4 years ago

nbrustein commented 7 years ago

I'm trying to figure out how to add stores in a new version. In version 1, I had 2 stores. Now I want to add 3 more. I've tried various things but keep getting errors either telling me that an index does not exist or "Dexie specification of currently installed DB version is missing". As far as I have found, none of the examples in the docs show how to ADD a store, only how to change an existing one.

Here is what I have now, and I'm getting the "installed DB version is missing" error. How should it look? Thanks.

db.version(1).stores({
    "readable_stems":"&[readableId+stemId]",
    "stems":"&id,&[languageId+name]"
});

db.version(2).stores({
    "user_readable_states":"&id,&[userId+readableId]",
    "readable_stems":"&[readableId+stemId]",
    "stems":"&id,&[languageId+name]",
    "user_stem_states":"&[userId+stemId],[userId+starred]",
    "chapter_paginations":"&id,&[userId+readableId+chapterIndex+targetWidth+targetHeight]"
})
dfahlander commented 7 years ago

You're doing it correctly. I think the error message might be shown when your browser's database is at version (1) but your page doesnt contain the version(1) spec. Are you sure you include your db.version(1) code in your app so that Dexie has it before trying to open the db?

If not, your browser might have a version else than 1 or 2. For example, if you have created your DB outside Dexie, it might be on version 0.1 instead of 1 because Dexie multiplies version with 10.

nbrustein commented 7 years ago

When you say "your page doesnt contain the version(1) spec", you mean that I have not included the bit that says db.version(1).stores ..., right? I have done that part. The code I am running is the whole thing I pasted above. Also, the database was created with Dexie initially. I even tried clearing out storage, going back to the code that just had version 1, loading the page, and then switching over to the new code that has version 1 and version 2. And I got the same error.

It seems like the upgrade is not happening. When I inspect the database in the chrome tools, it still says version 10. Also if I update the code above to the following, I never see the console.log.

db.version(2).stores({
    "user_readable_states":"&id,&[userId+readableId]",
    "readable_stems":"&[readableId+stemId]",
    "stems":"&id,&[languageId+name]",
    "user_stem_states":"&[userId+stemId],[userId+starred]",
    "chapter_paginations":"&id,&[userId+readableId+chapterIndex+targetWidth+targetHeight]"
}).upgrade(function() {
     console.log('upgrading to version ', version);
})

One thing that I'm doing that might be adding complexity here is that I'm running the code in both the browser and in a web worker. But what I would expect to happen is that the browser code gets loaded first and the database gets updated to version 2, and then the web worker code gets run and finds the database which is already at version 2. I don't see why it would cause an issue.

(Also, I recognize that in version 2 I don't need to repeat the definitions for stems and readable_stems. I've tried removing those from version 2 and I get the same error)

Any ideas of what I can look for to identify the issue?

nbrustein commented 7 years ago

I figured it out. Turns out my versions were strings, not integers. So I was actually running

db.version("1").stores({
    "readable_stems":"&[readableId+stemId]",
    "stems":"&id,&[languageId+name]"
});

db.version("2").stores({
    "user_readable_states":"&id,&[userId+readableId]",
    "user_stem_states":"&[userId+stemId],[userId+starred]",
    "chapter_paginations":"&id,&[userId+readableId+chapterIndex+targetWidth+targetHeight]"
})

For some reason that was working fine with version "1" but not with version "2".

Thanks for the help, and for the project.

deltragon commented 7 years ago

Had run into the same problem. Would it be possible to give a warning anytime a non-integer version number is used?

dfahlander commented 7 years ago

Could add a type check in the code.

playground commented 6 years ago

I'm get this error too. Dexie specification of currently installed DB version is missing let db = new Dexie('mydb');

db.version(version) .stores({ assets: '&type,content' })

deltragon commented 6 years ago

@playground: have you checked if version is an integer? if it's a string, it doesn't work, but there currently is no type check, so you have to check it yourself.

playground commented 6 years ago

@deltragon that works.