0

I have an app in which I haven't set the SQLite version in and now I want to upgrade the app but I have some column changes in the new iPA. How can I implement the DB Migration in iOS? I am using FMDB for the database.

Nik
  • 1,679
  • 1
  • 20
  • 36

1 Answers1

0

Keep a constant which version point to the version increments. Each time the database updates increment the counter.

On app launch call the following code :

DatabaseMigrator *dbMigrator = [[DatabaseMigrator alloc]
                                initWithDatabaseFile:
                                [AbstractRepository databaseFilename]];

//for development only - toggle this to force the new database over
//dbMigrator.overwriteDatabase = YES;

[dbMigrator moveDatabaseToUserDirectoryIfNeeded];

[dbMigrator migrateToVersion:CURRENT_SCHEMA_VERSION];

BOOL marked = [FileUtils addSkipBackupAttributeToItemAtURL:[AbstractRepository databasePath]];

if (marked) {

    NSLog(@"succesfully Marked do not back up");

} else {

    NSLog(@"failed Marked do not back up");
}
yoshiiiiiiii
  • 953
  • 8
  • 20