mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
README.md
This commit is contained in:
1 parent
dfa5b95284
commit
c7bb3f54eb
1 file changed
+8
-6
@@ -927,15 +927,17 @@ migrator.registerMigration("createTables") { db in
|
||||
You might even store your migrations as bundle resources:
|
||||
|
||||
```swift
|
||||
// Load paths to migration01.sql, migration02.sql, etc.
|
||||
let migrationPaths = NSBundle.mainBundle()
|
||||
// Execute migration01.sql, migration02.sql, etc.
|
||||
NSBundle.mainBundle()
|
||||
.pathsForResourcesOfType("sql", inDirectory: "databaseMigrations")
|
||||
.sort()
|
||||
for path in migrationPaths {
|
||||
migrator.registerMigration((path as NSString).lastPathComponent) { db in
|
||||
try db.executeMultiStatement(String(contentsOfFile: path))
|
||||
.forEach { path in
|
||||
let migrationName = (path as NSString).lastPathComponent
|
||||
migrator.registerMigration(migrationName) { db in
|
||||
let sql = try String(contentsOfFile: path, encoding: NSUTF8StringEncoding)
|
||||
try db.executeMultiStatement(sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Database Changes Observation
|
||||
|
||||
Reference in new issue
Block a user