Skip to content

Commit 18e4e0c

Browse files
authored
Swift Package Manager (#25)
* Start 0.4.0 changelog * try not to implicitely unwrap things * Add Package.swift * Add SPM instructions to the README * Nothing's ever simple... * Update the changelog * Run SPM build on travis
1 parent 4dcceaa commit 18e4e0c

File tree

6 files changed

+70
-4
lines changed

6 files changed

+70
-4
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## [0.4.0](https://github.com/garriguv/SQLiteMigrationManager.swift/releases/tag/0.4.0)
4+
5+
* Swift 4.2 support.
6+
* Upgrage example app.
7+
* SPM support.
8+
39
## [0.3.1](https://github.com/garriguv/SQLiteMigrationManager.swift/releases/tag/0.3.1)
410

511
* Set `APPLICATION_EXTENSION_API_ONLY` to `YES`.

Package.resolved

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"object": {
3+
"pins": [
4+
{
5+
"package": "SQLite.swift",
6+
"repositoryURL": "https://github.com/stephencelis/SQLite.swift.git",
7+
"state": {
8+
"branch": null,
9+
"revision": "210098546d59678f720e4ef67f8b562acfebbdb0",
10+
"version": "0.11.5"
11+
}
12+
}
13+
]
14+
},
15+
"version": 1
16+
}

Package.swift

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// swift-tools-version:4.0
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "SQLiteMigrationManager.swift",
6+
products: [
7+
.library(name: "SQLiteMigrationManager", targets: ["SQLiteMigrationManager"])
8+
],
9+
dependencies: [
10+
.package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.11.5")
11+
],
12+
targets: [
13+
.target(
14+
name: "SQLiteMigrationManager",
15+
dependencies: ["SQLite"],
16+
path: "SQLiteMigrationManager",
17+
sources: ["SQLiteMigrationManager.swift"]),
18+
.testTarget(
19+
name: "SQLiteMigrationManagerTests",
20+
dependencies: ["SQLiteMigrationManager"],
21+
path: "SQLiteMigrationManagerTests",
22+
sources: ["SQLiteMigrationManagerTests.swift"])
23+
])

README.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ print("needsMigration() \(manager.needsMigration())")
101101
### CocoaPods
102102

103103
SQLiteMigrationManager.swift is available through [CocoaPods](https://cocoapods.org). To install
104-
it, simply add the following line to your `Podfile`:
104+
it, add the following line to your `Podfile`:
105105

106106
```ruby
107107
pod "SQLiteMigrationManager.swift"
@@ -110,12 +110,21 @@ pod "SQLiteMigrationManager.swift"
110110
### Carthage
111111

112112
SQLiteMigrationManager.swift is available through [Carthage](https://github.com/Carthage/Carthage). To install
113-
it, simply add the following line to your `Cartfile`:
113+
it, add the following line to your `Cartfile`:
114114

115115
```ruby
116116
github "garriguv/SQLiteMigrationManager.swift"
117117
```
118118

119+
### Swift Package Manager
120+
121+
SQLiteMigrationManager.swift is availabel through [Swift Package Manager](https://swift.org/package-manager/).
122+
To install it, add the following dependency to your `Package.swift` file:
123+
124+
```swift
125+
.package(url: "https://github.com/garriguv/SQLiteMigrationManager.swift.git", from: "0.4.0")
126+
```
127+
119128
## Contributing
120129

121130
1. Fork it ( https://github.com/garriguv/SQLiteMigrationManager.swift/fork )

SQLiteMigrationManagerTests/SQLiteMigrationManagerTests.swift

+13-2
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ final class SQLiteMigrationManagerTests: XCTestCase {
258258
createMigrationTable()
259259
try CreateTable(version: 0).migrateDatabase(db)
260260
try AddRow(version: 1).migrateDatabase(db)
261-
subject = makeSubject(migrations: [AddRow(version: 2), FileMigration(url: testBundle.url(forResource: "3_add-row", withExtension: "sql")!)!, AddRow(version: 4)])
261+
let fileMigration = try makeFileMigration("3_add-row")
262+
subject = makeSubject(migrations: [AddRow(version: 2), fileMigration, AddRow(version: 4)])
262263

263264
XCTAssertNoThrow(try subject.migrateDatabase(), "successfully migrates database")
264265

@@ -282,7 +283,8 @@ final class SQLiteMigrationManagerTests: XCTestCase {
282283
createMigrationTable()
283284
try CreateTable(version: 0).migrateDatabase(db)
284285
try AddRow(version: 1).migrateDatabase(db)
285-
subject = makeSubject(migrations: [AddRow(version: 2), FileMigration(url: testBundle.url(forResource: "3_add-row", withExtension: "sql")!)!, AddRow(version: 4)])
286+
let fileMigration = try makeFileMigration("3_add-row")
287+
subject = makeSubject(migrations: [AddRow(version: 2), fileMigration, AddRow(version: 4)])
286288

287289
XCTAssertNoThrow(try subject.migrateDatabase(toVersion: 3), "successfully migrates database")
288290

@@ -311,6 +313,7 @@ extension SQLiteMigrationManagerTests {
311313

312314
enum TestError: Error {
313315
case BundleNotFound(String)
316+
case MigrationNotFound(String)
314317
}
315318

316319
private func makeSubject(migrations: [Migration], bundleName: String, file: StaticString = #file, line: UInt = #line) throws -> SQLiteMigrationManager {
@@ -324,6 +327,14 @@ extension SQLiteMigrationManagerTests {
324327
private func makeSubject(migrations: [Migration]) -> SQLiteMigrationManager {
325328
return SQLiteMigrationManager(db: db, migrations: migrations)
326329
}
330+
331+
private func makeFileMigration(_ fileName: String, file: StaticString = #file, line: UInt = #line) throws -> Migration {
332+
guard let url = testBundle.url(forResource: fileName, withExtension: "sql"), let fileMigration = FileMigration(url: url) else {
333+
XCTFail("migration not found: \(fileName)", file: file, line: line)
334+
throw TestError.MigrationNotFound(fileName)
335+
}
336+
return fileMigration
337+
}
327338
}
328339

329340
struct TestDB {

bin/run-tests

+1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ main() {
99
-sdk iphonesimulator12.1\
1010
-destination "platform=iOS Simulator,name=iPhone X,OS=12.1"\
1111
test
12+
swift build
1213
}
1314
main "$@"

0 commit comments

Comments
 (0)