0

Scenario:

You create an excel sheet in 2018. It has lookup tables in sheets. Let's call this DB ver 1. User submits the excel as a form-Form ID 1. Now in 2019 you update the lookup tables and publish a new version of the excel. This is now DB ver 2. User submits latest 2019 excel as a form -ID 2.

Now try doing this in a web application. We are using Rule.JS, Formula.JS and JS promises along with indexed db to mimic excel like functions. We are using indexeddb to avoid the multiple calls to the db for lookups. So only STATIC data is stored in indexeddb. All this works when work with the latest data. My design challenge is to do this for older forms that might need to use old versions of the db lookup tables.

When you open Form Id 1 in the browser- Db ver 1 should be loaded.

When you open Form Id 2 in the browser - Db ver 2 should be loaded.

Problem:

  1. Can indexeddb be used to load a specific version on page load using the indexedDB.open(dbname,ver)?
  2. Can indexeddb version be downgraded on page load?
  3. Can we pass the version# as an argument from JS on page load?

The problem is that each form needs to pull a specific version of the the Db based on when it was submitted. Using indexedDb, i understand that it is a forward looking database. So we can only upgrade to a newer version and not downgrade. Is there a way to do this with indexeddb or am i barking up the wrong tree?

One solution i came up with is to create two tables in SQL. 1 actual table, 1 archive table. Each time the data is updated, we move the old data to the archive table with the version #. If the form is looking for a specific version, the GetData(lookupvariable, ver#) can search either table to find the value for that specific version. This way, i will have to eventually convert everything to an AJAX call and do away with indexeddb.

1 Answer 1

1

An IDB datastore named foo will have the same data no matter what the version. So if you add data in v1, then change it to v2, the data doesn't go away. IDB uses versioning as a way to let you change the structure. You can only modify object stores when the version changes.

So I'd say yes - you are barking up the wrong tree here, using versioning as a way of partitioning data. I think your solution of an archive table actually makes much more sense.

Sign up to request clarification or add additional context in comments.

5 Comments

Raymond- Thanks for validating my thoughts. I think i will do the archive approach. But for curiosity, do you think we could delete the indexeddb on each page load and use the version partitioning to load that specific version into the browser? I know that causes its own hell if multiple tabs are open. But i just want to check if it is even possible?
Why would you delete the IDB on each page load? Doesn't that defeat the purpose of storing the data?
We are making like over 100 calls using promises to the indexed db for each form. That's because we mimicked the excel formulae using javascript/jsquery. And these are complex scientific formulae. So this was a way to limit the ajax calls and use a client side db to reduce traffic.
Right, but that doesn't answer why you would delete your data. Your comment above explains why you want to use IDB - it's local to the user and quicker. But it doesn't make sense to delete the data on every load.
I was discussing the possibility of deleting the db and data on each page load, so that the version can be specified and the version partitioning take care of the creation and populating the data. But as we discussed, it is not worth it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.