Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions addon/-private/factories/schema-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ModelDefinition> = {};

let orbitConfig = app.lookup('ember-orbit:config');
let modelNames =
const modelNames =
injections.modelNames ??
getRegisteredModels(
app.base.modulePrefix,
Expand All @@ -46,6 +47,8 @@ export default {
injections.models = modelSchemas;
}

injections.version ??= orbitConfig.schemaVersion;

return new RecordSchema(injections);
}
};
2 changes: 2 additions & 0 deletions tests/integration/config-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module('Integration - Config', function (hooks) {
'config:environment',
{
orbit: {
schemaVersion: 2,
types: {
bucket: 'orbit-bucket',
model: 'orbit-model',
Expand Down Expand Up @@ -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,
Expand Down