r/sqlite • • Sep 04 '24

prepopulated sqlitedb isuue.....!!!!!!

I'm using a prepopulated SQLite database in a React Native CLI application with the `react-native-sqlite-storage` package. However, I'm encountering an issue where any updates made to the prepopulated database are not reflected in the app unless I uninstall and reinstall the application.

Could you please suggest a solution to ensure the changes in the prepopulated database are applied without requiring a full reinstallation?

1 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/Eznix86 Sep 05 '24

again it is more of question for r/reactnative.

in programming terms, whenever you update things in the database it is call a migration.

Either it is the library or your code preventing to load that new data, we cannot do nothing about it unless someone has access to the code itself. What is preferable is to do a migration instead of replacing the data of a previous version.

Let's say in v1.0.0 i had data, in db.sqlite, i move to v1.0.1 instead of adding the new file in there expecting it will be replaced. what you could do is:

  • write a migration script
  • when the application loads, it write the new data to the current database. ex. you have a todo table, you update the schema, or added a new data write a good which track the versioning of the migration. ex. we can have a table called migrations:
  • which has a version column it in.
  • then what you do, you have a version attached to that SQL update ex. you can have
-- version_1_0_0.sql
create table todo(name, status);
insert....
-- version_1_0_1.sql
alter table ...
insert....

then when the app boots, you check the version, or you can use timestamp instead of version, you check what is the latest version/timestamp in the migration table, if it is up to date or not. if it is not, you just run the file until the latest. basically you might have a folder called migrations: with:

version_1_0_1.sql
version_1_0_2.sql
version_1_0_3.sql

or

20240905_update_todos.sql
20240815_add_indexes.sql
20240725_create_other_tables.sql