0

I'm using FMDB IOS framework to manage my sqlite database.

But now I have second version of my database, so I need to update my sqlite file (on devices with installed app)

Here is my steps: (database is in Application Support/db/db.sqlite )

  1. create second . sqlite file (named "2_db.sqlite") and copy it into my main Bundle
  2. Use this code on every start

    -(void)migrateWithDBAtPath:(NSString *)dbPath {
        FMDBMigrationManager *manager = [FMDBMigrationManager managerWithDatabaseAtPath:dbPath migrationsBundle:[NSBundle mainBundle]];
        NSError *error = nil;
        BOOL success = [manager migrateDatabaseToVersion:UINT64_MAX progress:nil error:&error];
    }
    

dbPath is .../Library/Application Support/db/db.sqlite

But after this steps I have no migration and 0 pendingVersions in migrateDatabaseToVersion:progress:error:

What am I doing wrong? Thanks.

kudinovdenis
  • 625
  • 6
  • 12

1 Answers1

0

Objective-C way:

FMDBMigrationManager * manager = [FMDBMigrationManager managerWithDatabaseAtPath: @"Path to your db" migrationsBundle:[NSBundle mainBundle]];
     //Path to the sql file with the statements to apply to your db
     NSString * expectedPath = [[NSBundle mainBundle] pathForResource: @"1" ofType: @"sql"];
     FMDBFileMigration * fileMigration = [FMDBFileMigration migrationWithPath: expectedPath];
     //Apply the statements in 1.sql
     BOOL successFileMigration =[ fileMigration migrateDatabase: [manager database]  error:nil];
jmartinalonso
  • 2,324
  • 1
  • 19
  • 22