Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuking db during development #381

Merged
merged 15 commits into from
Jul 8, 2018

Conversation

groue
Copy link
Owner

@groue groue commented Jul 6, 2018

This is a pull request that addresses #378 by @bellebethcooper.


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:

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:

    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 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.


This pull request also adds the two following methods:

  • DatabaseWriter.erase()
  • DatabaseWriter.vacuum()

Those are not documented in the main README, and only exposed in the reference documentation.

@groue
Copy link
Owner Author

groue commented Jul 7, 2018

@bellebethcooper, what do you think of the description of the feature?

@groue groue merged commit 3e60b00 into development Jul 8, 2018
@groue groue deleted the feature/378-nuking-db-during-development branch July 8, 2018 04:31
@bellebethcooper
Copy link
Collaborator

@groue This looks great! So easy to use, also. Thanks for the quick turnaround! I think this will be super useful in future :)

@groue
Copy link
Owner Author

groue commented Jul 8, 2018

Sounds great 👍 Thank you, and Realm, for the inspiration!

@groue
Copy link
Owner Author

groue commented Jul 8, 2018

Shipped in v3.2.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants