Migration options for preloaded sqlite database in iphone app - iphone

My app uses a preloaded SQLLite database with coredata bindings. I create the preloaded database file with a secondary app that has the core data bindings/model etc. I put the preloaded db into my app's resources folder and copy that to the writable documents folder when the app is first run.
My question is about migration. Since my app released, my users have been creating data and in my next release I want to change the data model and migrate some of the data to the new model. I'm just not sure the best way to do this. I've read about core data migration methods but they seem to require my app to be a core data project, which it isn't (though my secondary database-creating app is). Will I have to do this migration manually by issuing direct SQL statements against the db? And what about the core data bindings, will I have to manually update them?
I'm really just looking for pointers in the right/best direction. Any suggestions? Thanks in advance!

SQLLite doesn't really have any data migration tools like Core Data. Unless you count "ALTER TABLE". If the migration is very complex, or you think you will have more complex migrations in the future you could make a Core Data model that more or less lines up with the old SQLite model and import to it, and then migrate to a newer Core Data model, and then stick with it.
This is likely slower then ALTER TABLE though, or at the very least "not faster".

Related

SQL database in iPhone

I'd like to write an app which use Core Data and need some solution to insert information into my database.
Could I use phpmyadmin for filling the db and then just export to sql or I need another solution?
You could indeed populate an SQLite (note: not SQL) database directly and then use this with Core Data. However, I'd recommend against this, because it may cause maintenance problems down the road when the schema for Core Data's SQLite storage changes under your feet. Consider using Core Data itself to populate the database. And if you do this, you can fairly easily later on change the backing strategy of Core Data from SQLite to something else without incurring lots of work elsewhere.
More discussion:
Populating sqlite db created by CoreData
Any way to pre populate core data?
http://www.raywenderlich.com/980/core-data-tutorial-how-to-preloadimport-existing-data
http://forums.pragprog.com/forums/90/topics/2436
Well, phpMyAdmin is for MySQL and Core Data uses SQLite.
It's possible though. You could export as SQL in phpMyAdmin and replace one or two things to make it compatible with SQLite.
Also, see Christian Kienle's Core Data editor

Is there a a way to migrate data from Core Data to Online Database?

My app currently uses core data. I created a new version of the app that is all cloud based and the database is online. Therefore this requires user registration/accounts to access the data. The easiest thing is for me to make it a separate app, but then I lose the user base I already have.
Is there a way for me to transfer data from the iPhone's core data database to the online database? I am using https://www.parse.com/
Have a look into this github project,
https://github.com/itsniper/FTASync
Sure. To transfer data from CoreData to Parse, just create a PFObject for each row in your CoreData table, and save them to Parse. You can use saveAll to be faster. Then, you don't need the local copy in CoreData any more, so you can remove it.

How to see core data tables and how to delete the data from a real device

Two questions about Core Data:
1. Is it possible to see the actual data(the db tables) that is stored when using core data?
2. When using the iPhone simulator i can delete the core data db by resetting the simulator. But how can i delete the core data db when using a real device?
Your Mac comes with a command line tool sqlite3. You can use it to do queries against the core data database. Not sure if that violates any rules against reverse engineering that might exist in any license agreements.
You can delete the db for convenience during development by deleting your app from the device and reinstalling it. If you don't want to do it by deleting the app, you will have to write some code in your app to delete it I think.
You can directly view an sqlite store using any sqlite tool including the command line sqlite3 tool. However, (1) Core Data uses a custom undocumented schema so looking at the store doesn't tell you much and (2) the structure of the sqlite store file itself has little relationship to how the managed objects behave in memory. Core Data isn't an sql wrapper. It just takes the managed objects apart to store them in SQL. SQL is just an option and Core Data works fine without it.
To "delete the core data db" you simply delete the persistent store file. Look where you initialize the persistentStoreCoordinator (in the Xcode templates, it's in the app delegate.) The URL for the persistent store/s will be there. Just close down the Core Data stack and then delete the store file with NSFileManager. Then restart the Core Data stack.

Iphone programming- Importing an existing sql table to sqlite or core data

I have a simple table that I'm pulling from our existing sql database. Its just a 1mb Vehicle table. It contains enough information that I don't want to create it from scratch, but I can not find a definitive answer on how to import this table into my sqlite environment on the mac.
I've seen a few posts about python scripts that import to Core Data but I don't think thats the way to go.
The table I saved out as .rpt file. Any direction other than the one I'm traveling would be great.
The most correct (and pretty easy) way to do this is to write a little Mac OS X command line tool program that reads the data from your SQLite database and uses Core Data to load the data into a Core Data persistent store.
That persistent store -- the resulting Core Data schema'd SQLite file -- can be added as a resource to your iOS app project and it'll "just work".
Checkout Christian Kienle's Core Data Editor, which let's you import data from CSV files into Core Data: http://christian-kienle.de/CoreDataEditor
It is also useful after the data is imported for debugging.

Update core data database in app update without migrating

I have an application in iTunes app store using core data. Currently I'm developing a new version that has a new core data model. I do not want to migrate the data when updating. I just want to remove the old one and in with the new.
Whats the best way to handle this? My current (temporary?) solution is to change the path of the sqlite file which leaves the old database in the app.
Is there a migration option to remove the store if it can not be migrated, or some other solution?
I would probably check for the existence of the original database using NSFileManager and delete/remove it if found. The best place to do this is probably when you create the persistent store that Core Data uses.