diff --git a/README.md b/README.md index 3c3e18842..a62384425 100644 --- a/README.md +++ b/README.md @@ -4344,6 +4344,35 @@ if appliedMigrations.contains("v2") { } ``` +### The `eraseDatabaseOnSchemaChange` Option + +A DatabaseMigrator can automatically wipe out the full database content, and recreate the whole database from scratch, if it detects that a migration has changed its definition: + +```swift +var migrator = DatabaseMigrator() +migrator.eraseDatabaseOnSchemaChange = true +``` + +Beware! This flag can destroy your precious users' data! + +Yet it may be useful in those two situations: + +1. During application development, as you are still designing migrations, and the schema changes often. + + In this case, it is recommended that this flag does not ship in the distributed application: + + ```swif + var migrator = DatabaseMigrator() + #if DEBUG + // Speed up development by nuking the database when migrations change + migrator.eraseDatabaseOnSchemaChange = true + #endif + ``` + +2. When the database content can easily be recreated, such as a cache for some downloaded data. + +The `eraseDatabaseOnSchemaChange` option triggers a recreation of the database if and only the migrator detects a *schema change*. A schema change is any difference in the `sqlite_master` table, which contains the SQL used to create database tables, indexes, triggers, and views. + ### Advanced Database Schema Changes