Welcome to the documentation for FMDBMigrationManager, a simple migration manager for FMDB. FMDBMigrationManager provides an easy way to manage database migrations with version control and rollback support.
Installation
FMDBMigrationManager can be installed using CocoaPods. Just add the following line to your Podfile:
pod 'FMDBMigrationManager'
Then, run the command:
pod install
Usage
Setting Up the Migration Manager
First, import the necessary dependencies:
import FMDBMigrationManager
Then, create an instance of FMDBMigrationManager and set up the database path:
let migrationManager = FMDBMigrationManager(databasePath: yourDatabasePath)
Replace `yourDatabasePath` with the actual path to your SQLite database file.
Creating Migrations
To create a migration, subclass FMDBMigration and override the necessary methods:
class MyMigration: FMDBMigration {
override func migrateDatabase(_ database: FMDatabase) throws {
// Perform necessary database changes here
}
override func databaseVersion() -> UInt64 {
return 1 // Update with the current version of the migration
}
}
Make sure to update the `databaseVersion` method with the current version of the migration. This version number should be unique for each migration.
Running Migrations
To run the migrations, call the `performMigrations` method of the migration manager:
try migrationManager.performMigrations()
This method will check the current version of the database and execute all pending migrations in order. If there are no pending migrations, it will do nothing.
Rolling Back Migrations
If you need to rollback a migration, use the `rollbackMigration` method of the migration manager:
try migrationManager.rollbackMigration()
This method will rollback the last executed migration. Note that you can only rollback one migration at a time.
Additional Methods
The migration manager provides additional methods to check the current version, get the list of migrations, and more. Please refer to the official documentation or the source code for more information.
Contributing
If you find a bug, have a feature request or want to contribute to FMDBMigrationManager, please check out our GitHub repository and follow the guidelines provided there.
License
FMDBMigrationManager is available under the MIT license. See the LICENSE file for more info.