Conditionally run post-attachment migrations
Introduce placeholder migrations for Backbone models so they never implicitly run migrations whenever they are `fetch`ed. We prefer to run our migrations explicitly upon app startup and then let Backbone models be (slightly) dumb(er) models, without inadvertently triggering migrations.
This commit is contained in:
parent
887bd83852
commit
805031ade8
6 changed files with 87 additions and 25 deletions
23
js/modules/migrations/get_placeholder_migrations.js
Normal file
23
js/modules/migrations/get_placeholder_migrations.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
const Migrations0DatabaseWithAttachmentData =
|
||||
require('./migrations_0_database_with_attachment_data');
|
||||
const Migrations1DatabaseWithoutAttachmentData =
|
||||
require('./migrations_1_database_without_attachment_data');
|
||||
|
||||
|
||||
exports.getPlaceholderMigrations = () => {
|
||||
const last0MigrationVersion =
|
||||
Migrations0DatabaseWithAttachmentData.getLatestVersion();
|
||||
const last1MigrationVersion =
|
||||
Migrations1DatabaseWithoutAttachmentData.getLatestVersion();
|
||||
|
||||
const lastMigrationVersion = last1MigrationVersion || last0MigrationVersion;
|
||||
|
||||
return [{
|
||||
version: lastMigrationVersion,
|
||||
migrate() {
|
||||
throw new Error('Unexpected invocation of placeholder migration!' +
|
||||
'\n\nMigrations must explicitly be run upon application startup instead' +
|
||||
' of implicitly via Backbone IndexedDB adapter at any time.');
|
||||
},
|
||||
}];
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue