mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-30 04:28:44 +00:00
eraseDatabaseOnSchemaChange documentation
This commit is contained in:
1 parent
fc2d5419b3
commit
d814249c5a
1 file changed
+29
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user