diff --git a/README.md b/README.md index 5cb523f1..2dfd6b1d 100644 --- a/README.md +++ b/README.md @@ -594,6 +594,7 @@ module.exports = function (environment) { // Default Orbit settings (any of which can be overridden) orbit: { + schemaVersion: undefined, types: { bucket: 'data-bucket', model: 'data-model', @@ -623,6 +624,12 @@ module.exports = function (environment) { }; ``` +Note that `schemaVersion` should be set if you're using any Orbit sources, such +as `IndexedDBSource`, that track schema version. By default, Orbit's schema +version will start at `1`. This value should be bumped to a a higher number with +each significant change that requires a schema migration. Migrations themselves +must be handled in each individual source. + ## Contributing to EO ### Installation diff --git a/addon/-private/factories/schema-factory.ts b/addon/-private/factories/schema-factory.ts index 86148f46..693ee532 100644 --- a/addon/-private/factories/schema-factory.ts +++ b/addon/-private/factories/schema-factory.ts @@ -19,12 +19,13 @@ type SchemaInjections = { modelNames?: string[] } & RecordSchemaSettings; export default { create(injections: SchemaInjections = {}): RecordSchema { - if (!injections.models) { - const app = getOwner(injections); + const app = getOwner(injections); + const orbitConfig = app.lookup('ember-orbit:config'); + + if (injections.models === undefined) { const modelSchemas: Dict = {}; - let orbitConfig = app.lookup('ember-orbit:config'); - let modelNames = + const modelNames = injections.modelNames ?? getRegisteredModels( app.base.modulePrefix, @@ -46,6 +47,8 @@ export default { injections.models = modelSchemas; } + injections.version ??= orbitConfig.schemaVersion; + return new RecordSchema(injections); } }; diff --git a/tests/integration/config-test.ts b/tests/integration/config-test.ts index d9262dae..9511b5cd 100644 --- a/tests/integration/config-test.ts +++ b/tests/integration/config-test.ts @@ -14,6 +14,7 @@ module('Integration - Config', function (hooks) { 'config:environment', { orbit: { + schemaVersion: 2, types: { bucket: 'orbit-bucket', model: 'orbit-model', @@ -48,6 +49,7 @@ module('Integration - Config', function (hooks) { const normalizer = this.owner.lookup('service:orbit-normalizer'); const validatorFor = this.owner.lookup('service:orbit-validator'); + assert.equal(schema.version, 2, 'schema version matches configuration'); assert.equal( this.owner.lookup('service:orbit-store'), store,