Use ActiveAndroid on existing database-content - android

I developed an Android-App where I saved data in a SQLite database using the SQLiteOpenHelper.
I am wondering if I could update my app by using ActiveAndroid, but in a way that the user data previously stored in the database will be preserved.
Is that possible?

You would have to perform a data migration during runtime after the user upgrades to the newest version of the app. The process could be broken down into the following steps, I have also assigned database version values to each step.
The user has all of their data stored in a SQLite database and has not upgraded their app yet. [DB = SQlite v1]
On upgrade, when the user is upgrading to the next version of the
app read all data from the old SQLite database and store it into the
ActiveAndroid database. [DB = SQLite v1 and ActiveAndroid v1]
Once all of the data has been migrated to the new ActiveAndroid database then delete all tables of the SQLite database so that you don't use extra storage space that you do not need. [DB = SQLite v2 and ActiveAndroid v1]
In the next release you can then assume that user has had their data fully migrated and at this point it is finally safe to remove all code that was previously referencing the SQLite database. [DB = ActiveAndroid v2]

Related

Save a Room Database file in Firebase

I have been working on an Android application that populates a Google Map with markers from a Room Database and all user data is stored in a Firebase Realtime Database.
The application first copies the Room Database from the assets folder, so all the changes will take place in the copy of the database. The Room Database has 11 columns at the moment and only one of the column's values are changed.
Now I have reached the part where I would need to save the copy of the Room database to the corresponding user in the Firebase Realtime Database, so that if the application is uninstalled or if anything else happens, then the data and changes related to the markers would persist.
How could I save the copy of the Room Database in the Firebase Realtime Database and how can I pull that copy from the Realtime Database and set it as the version to use?
I did come across people looking for a solution to a similar problem but the solution so far has been to migrate the Room Database to the Firebase Realtime Database.
example: Link Android Room Database with Firebase Realtime Database
I also thought about getting rid of the Room Database and just using the Firebase Realtime Database but the management of the data related to the markers seems difficult not to mention the amount of reprogramming. Also if this is the best/only way to go, then if I have the database stored on Firebase, should each user have their own copy of the database, or should it include only the data that changes and a reference to the corresponding item in the main database with the rest of the data?
I just recently started using Firebase and I am not sure what would be the correct approach.
Thanks in advance!
Android's Room database is a SQL database, while Firebase's Realtime Database is a NoSQL database. There is no direct mapping from the data in your SQL database, to Firebase's NoSQL model.
But it's not clear why you'd want to store the data in Firebase. If you just want a place to store the Room files so you can retrieve them later, you might be better off using Cloud Storage for which Firebase also has SDKs. You can just upload the SQLite file to Storage, and retrieve it from there later.

Some records are deleting automatically after some point in time from the Android SQLite database with Sugar ORM

I am working on an android application that is using for collecting data. We have realized now a new issue, some records are missing from the database after some days/weeks. We used the SQLite database with Sugar ORM.

Update prepopulated Room database

Imagine I deliver a prepopulated database with my application version 1.
The prepopulated database includes a table "my_items" with the column item:
item
------
apple
For application version 2 I deliver an updated prepopulated database, so table "my_items" includes
item
------
apple
milk
How would one make sure that the new prepopulated data is transfered to the database of the app in a non-destructive way? (user is allowed to insert new items to "my_items" by himself and I need to keep his input). I read the Room migrations documentation, but it seems like the prepopulated data is only read on a destructive migration, which is not what I want, as the items entered by the user himself shall remain available.
Room's built in migration processing does not support the merging of existing data into a new prepopulated database.
An approach that should work is to give the prepackaged database file for each app version a unique name, e.g. my_items1.db, my_items2.db, etc. In app version 2, create the main database from prepackaged database file my_items2.db. Then open the database for the previous version as a separate Room database instance, query it to find the items added by the user, and insert those into the new main database with appropriate default values for new fields. This merge processing could be triggered by the onCreate() callback for the main database. The merge processing should be done in a transaction. If it completes successfully, you can close and delete the database for the previous version. In the event of failure, you'll need to notify the user and implement some sort of mitigation processing.

Link Android Room Database with Firebase Realtime Database

I am using Android Room Database for creating the database for my android app. It works perfectly for me locally but I cannot link to a server to have it online as well.
I am using Firebase for Authentication. I am trying to use Firebase Realtime Database to save the whole database object from Room and load the correct database on app startup according to the authenticated user.
I want to ask if this is possible at all? and if I can just save a whole instance of Room database or I need to re-create the database on Firebase and save my data item by item?
I also can't seem to be able to get access to the database data of Room, as when I get an object of the AppDatabase class it doesn't really pass the data. And I don't know how should do the opposite, to assign the data retrieved from Firebase later to the local data saved?
Also if it's not possible with Firebase, do you have any recommendation for some other server I can use with Room?
After a lot of researches and looking desperately for an answer here's what I reached:
Firebase already got a straight forward way to create the database and host it online. (I had my database already created so was trying to save time, but creating it from scratch using Firebase Realtime Database was a lot faster)
Room Database is quite perfect if you are planning to save your database locally and offline (Up to the post date)
I think their is no need to connect your Room Database with Firebase Realtime database because,okay first try to solve this problem, why we use Room Database ?because when we don't have internet, we can get data from Room Database , no need of network... Firebase also provides offline mode , it can also save data in persistence, so why we use Room Database ?.. Hope you got the point...
Similar project created by me which uses
Firebase authentication to login user
Save and cache user notes to sql lite database with Room
Save user notes to firebase base database
✍️ Simple Note Making App use Sqllite Room 🧰 for caching the notes and 📥 Firebase Database for online storage
https://github.com/LanguageXX/Simple-Note-App-with-Online-Storage
Hope that helps you

Data not persisted with Room Persistence Library while upgrading Database Version

When I upgrade my Database from Version 1 to Version 2 and insert new data then all old data stored in Version 1 of database were deleted and I can see only newly inserted data in database.
Any idea how to persist data while upgrading database with Room Library?
I found solution from the same link. And when the migration class is not provided then Room Library deletes whole Database with data on onUpgrade() and create Database again.
It is compulsory to provide Migration class if you want to persist data on onUpgrade()

Categories

Resources