vasern / vasern

Vasern is a fast, lightweight and open source data storage for React Native

Home Page:https://vasern.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

alter a schema

apppro123 opened this issue · comments

I want to add a new propertie to one of my schemas.

The problem is that i'm not sure how this is going to work on the devices. If a user has the old database and now gets the new one they wont have a value for the new propertie (if im right).
So how can i alter a schema that it works for the user who has already the old database. (Another question would be how to alter a schema in general (delete/change properties)?

Or are there other solutions out there of other device databases?

Thanks for any help on it!

Hi @apppro123, I am sorry for this late reply.

Note: At the moment, Vasern has not integrated a method for automatically update schema (schema migration). So the following answer and recommendation is somewhat handy

1. Adding new property
You are right, users with the previous database schema will not have the new property. In this case, you can check if the property exists. For example:

if ('newPropertyName' in record === false) {
  // This record doesn't have 'newPropertyName'
  // do something with record belong to the previous DB schema
}

2. Update schema (remove/update)
Since there isn't an automatic schema migration feature, behaviors that will be expected are:

  • Update property name will be applied without any issue.

  • Update property type is not recommend, as it will cause parse value incorrectly. For example, changing from string to int will cause the new value to be NaN

  • Remove property is not recommended as it will cause parse value incorrectly. The app can be crashed in some cases. So instead of completely remove the property, change it to optional property.
    For example, change property: string to property: ?string (add the ?). You will still receive the property from the record of the previous DB schema, but not in the record of the new DB schema.

Hope it helps, I do think on either integrate the migration feature or completely make it NoSQL (which mean no schema -> no schema migration). Let me know if any part that you need to understand more.

Besides, I've been focusing on the Vasern Server, which Vasern data can be sync across React Native (mobile apps), Reactjs (web apps, websites), and the server.

Since you have been using Vasern, I'd love to show you some works and hear from your feedback (if possible). If you are keen on, let me know how can I reach you (email, facebook, etc.) or have a chat on our slack channel here

Thanks for getting in touch with me. Since the issue is solved, I'll close it. Feel free to reopen or create a new issue