I am working on a small web app that stores user data locally using indexedDB which can be imported/exported by making use of JSON files. Since I plan on adding updates to the site, I want to know what best practices I should follow to make sure my app can allow importing of user data from older versions. It could be related to how I should define the properties of my user data object to make it future proof, or any library or tool I could implement that would make this migration process easier.

Do keep these points in mind:

  1. I am using NextJS to build this application and Dexie to manage indexedDB
  2. Without going into details, the user data file makes use of heavily nested objects and arrays and most likely won’t fit in a cookie or even in the local storage API
  3. This web app acts as a proof of concept which must only make use of the aforementioned core technologies, regardless of whether more efficient alternatives exist or not.
  • hosaka@programming.dev
    link
    fedilink
    arrow-up
    2
    ·
    7 hours ago

    Use Open API schema. You can define data models and endpoints or just the models, I do this at work. Then generate your code using openapi-generator.

    • undefined@links.hackliberty.org
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      6 hours ago

      Do you happen to do this in Ruby on Rails? I don’t know what happened but it seems like Swagger, JSON:API, and the serializers/deserializes are all abandoned.

      For personal projects I use GraphQL for everything, I’m not a fan of REST these days. Let me define a schema and let clients screw around with the data. I just won’t waste the time anymore despite the performance impact everyone might cry about.

      • expr@programming.dev
        link
        fedilink
        arrow-up
        1
        ·
        38 minutes ago

        Obligatory “JSON APIs are not REST because JSON is not hypermedia”.

        GraphQL is a mess too as you throw out any ability to reason about query performance and it still requires thick clients with complicated/duplicated business logic.

        If you’re doing RoR anyway, then go for https://htmx.org/. It’s much, much simpler and closer to how the web was originally designed. Highly recommend this book the author wrote on the subject (also provides tutorials walking through building an app): https://hypermedia.systems/book/contents/.

  • Ephera@lemmy.ml
    link
    fedilink
    arrow-up
    14
    ·
    15 hours ago

    Two rules of thumb that I’ve found useful:

    1. Introduce a version field top-level. If necessary, you can introduce a version 2, but keep the parser for version 1 around.
    2. You want to err on the side of using objects in place of single values, because you can add fields to an object without breaking backwards compatibility.
  • undefined@links.hackliberty.org
    link
    fedilink
    arrow-up
    6
    arrow-down
    1
    ·
    15 hours ago

    I can’t speak to your framework specifically, but:

    I’m assuming this is a REST API. I would suggest versioning the API, like /api/v1 for example.

    It’s funny, I’m currently dealing with this at work. The old API was just /api but on the backend we’ve mapped it to API::V1 (Ruby). It gets a little pesky backporting things to the older API so it’s good to start with a solid foundation as much as possible.

    Something else I might suggest: use a good serializer and deserializer. You don’t want to muck up your models with crazy translations for everything: having a middle layer to perform that has been so, so beneficial to us.