Reputation: 15
This is my first question here so I hope I'm not messing it up so far...
So, the thing is that I'm developing an android app using SugarORM for the database. I managed to successfully create the tables and I even can save and search objects with SugarORM, but I want the application to have a set of data stored in the database for the user to use right from the start. I read about SugarORM's versioning and thought that maybe I could create a 1.sql script with the initial data to load, tried it but didn't work. Then I thought that maybe I should try to do it for a 2nd version, instead of the first, so I moved the content in my 1.sql file to a 2.sql, changed the version number in the AndroidManifest.xml to
<meta-data android:name="VERSION" android:value="2" />
and nothing happened...
Is there a way for SugarORM to automatically load initial data to my tables right after I created them? Or do I need to programmatically create a method that does it for me on the onCreate() method of my main activity?
Upvotes: 0
Views: 649
Reputation: 151
Right now there seems to be no way to do this with a migration script. But there's already an issue for this: https://github.com/satyan/sugar/issues/87. So maybe we will have it in the future.
By the way, in DBFlow you can do it like this - At leat they promote it on their documentation page: https://github.com/Raizlabs/DBFlow/blob/master/usage/Migrations.md
Upvotes: 0
Reputation: 9060
I believe version corresponds to the structure of your db. And I don't believe it's the right way to go, even if you can do it there. What if your user clears the app data in the settings ?
I think you should use Preferences to store a simple boolean value say isSeeded and this value is retrieved when your app starts. If isSeeded returns false, fill the db with prepared data and save the value back as true.
Upvotes: 0