From 212a6f7e53ee143edae8c0883c2687572a4edd08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Mon, 11 May 2020 09:06:04 +0200 Subject: [PATCH] Documentation --- Documentation/FullTextSearch.md | 4 ++-- Documentation/Migrations.md | 29 +++++++++++++---------------- Documentation/ReleaseProcess.md | 2 ++ 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Documentation/FullTextSearch.md b/Documentation/FullTextSearch.md index c4828b74d..78536aa34 100644 --- a/Documentation/FullTextSearch.md +++ b/Documentation/FullTextSearch.md @@ -280,7 +280,7 @@ let pattern = FTS3Pattern(matchingAnyTokenIn: "") // nil let pattern = FTS3Pattern(matchingAnyTokenIn: "*") // nil ``` -FTS3Pattern are regular [values](../README.md#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/4.5/Structs/StatementArguments.html): +FTS3Pattern are regular [values](../README.md#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/5.0.0-beta/Structs/StatementArguments.html): ```swift let documents = try Document.fetchAll(db, @@ -529,7 +529,7 @@ let pattern = FTS5Pattern(matchingAnyTokenIn: "") // nil let pattern = FTS5Pattern(matchingAnyTokenIn: "*") // nil ``` -FTS5Pattern are regular [values](../README.md#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/4.5/Structs/StatementArguments.html): +FTS5Pattern are regular [values](../README.md#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/5.0.0-beta/Structs/StatementArguments.html): ```swift let documents = try Document.fetchAll(db, diff --git a/Documentation/Migrations.md b/Documentation/Migrations.md index 3042ae81b..ee16df8fa 100644 --- a/Documentation/Migrations.md +++ b/Documentation/Migrations.md @@ -42,7 +42,7 @@ You migrate the database up to the latest version with the `migrate(_:)` method: try migrator.migrate(dbQueue) // or migrator.migrate(dbPool) ``` -Migrate a database up to a specific version: +Migrate a database up to a specific version (useful for testing): ```swift try migrator.migrate(dbQueue, upTo: "v2") @@ -53,27 +53,24 @@ try migrator.migrate(dbQueue, upTo: "v1") // ^ fatal error: database is already migrated beyond migration "v1" ``` -Check if consecutive migrations have been applied: +When several versions of your app are deployed in the wild, you may want to perform extra checks: ```swift -if try dbQueue.read(migrator.hasCompletedMigrations) { - // All migrations have been applied, up to the last one. -} -if try dbQueue.read(migrator.completedMigrations).last == "v2" { - // All migrations up to "v2" have been applied, and no further. -} -if try dbQueue.read(migrator.completedMigrations).contains("v2") { - // All migrations up to "v2" have been applied, and maybe further. +try dbQueue.read { db in + // Readonly apps may want to check if database lacks expected migrations: + if try migrator.hasCompletedMigrations(db) == false { + // database too old + } + + // All apps may want to check if database contains unknown (future) migrations: + if try migrator.hasBeenSuperseded(db) { + // database too new + } } ``` -Check if individual migrations have been applied: +See the [DatabaseMigrator reference](http://groue.github.io/GRDB.swift/docs/5.0.0-beta/Structs/DatabaseMigrator.html) for more migrator methods. -```swift -if try dbQueue.read(migrator.appliedMigrations).contains("v2") { - // "v2" migration has been applied -} -``` ## The `eraseDatabaseOnSchemaChange` Option diff --git a/Documentation/ReleaseProcess.md b/Documentation/ReleaseProcess.md index a2fb29a2f..83919571c 100644 --- a/Documentation/ReleaseProcess.md +++ b/Documentation/ReleaseProcess.md @@ -17,6 +17,8 @@ To release a new GRDB version: - CHANGELOG.md - GRDB.swift.podspec - README.md + - Documentation/FullTextSearch.md + - Documentation/Migrations.md - Support/Info.plist - Commit and tag - Check tag authors: `git for-each-ref --format '%(refname) %(authorname)' refs/tags`