SQLiteMigrationManager.swift works by introducing a schema_migrations table into the database:
CREATE TABLE "schema_migrations" (
"version" INTEGER NOT NULL UNIQUE
);
Each row in schema_migrations corresponds to a single migration that has been applied and represents a unique version of the schema. This schema supports any versioning scheme that is based on integers, but it is recommended that you utilize an integer that encodes a timestamp.
let db = try Connection("path/to/store.sqlite")
let manager = SQLiteMigrationManager(db: self.db)
if !manager.hasMigrationsTable() {
try manager.createMigrationsTable()
}
SQLiteMigrationManager.swift
SQLiteMigrationManager.swift is a schema management system for SQLite.swift. It is heavily inspired by FMDBMigrationManager.
Concept
SQLiteMigrationManager.swift works by introducing a
schema_migrations
table into the database:Each row in
schema_migrations
corresponds to a single migration that has been applied and represents a unique version of the schema. This schema supports any versioning scheme that is based on integers, but it is recommended that you utilize an integer that encodes a timestamp.Usage
Have a look at the example project.
Creating the Migrations Table
Creating a SQL File Migrations
Create a migration file in your migration bundle:
SQLiteMigrationManager.swift will only recognize filenames of the form
<version>_<name>.sql
. The following filenames are valid:1.sql
2_add_new_table.sql
3_add-new-table.sql
4_add new table.sql
Creating a Swift Migration
Swift based migrations can be implemented by conforming to the
Migration
protocol:Migrating a Database
Inspecting the Schema State
Installation
Swift Package Manager
SQLiteMigrationManager.swift is available through Swift Package Manager. To install it, add the following dependency to your
Package.swift
file:CocoaPods
SQLiteMigrationManager.swift is available through CocoaPods. To install it, add the following line to your
Podfile
:Carthage
SQLiteMigrationManager.swift is available through Carthage. To install it, add the following line to your
Cartfile
:Contributing
bin/setup
)git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)Author
Vincent Garrigues, vincent@garriguv.io
License
SQLiteMigrationManager.swift is available under the MIT license. See the LICENSE file for more info.