Is it possible to configure database or model root paths?

762 views Asked by At

TL;DR: When using Firebase with Ember through EmberFire, Is there a way to define the root location where changes should be saved in the firebase database, either for the entire ember instance, or on a per-model basis?

Example: given a secret model, which by default would store a new secret in /secrets/<secret GUID>/, could we configure EmberFire to instead use a sub-path as the root, so a new secret would be created at: /<some_path>/secrets/<secret GUID>/?


Suppose we have a firebase database configured to support multiple versions of an app during development:

{
  "versions" : {
    "0_0_1" : {
      "isActive" : true
    },
    "0_0_2" : {
      "isActive" : false
    }
  }
}

And this secret.js model:

import DS from 'ember-data';

export default DS.Model.extend({
  content     : DS.attr('string', { defaultValue() { return "UNDEFINED"; } }),
});

By default, when saving a new secret object, a 'secrets' section is created at the root of the database:

{
  "versions" : {
    "0_0_1" : { ... },
    "0_0_2" : { ... }
  },
  "secrets" : {
    "<GUID>" : { "content" : ... }
  }

}

It could be that in 0.0.2 the 'secret' model is no longer used, and so it would be nice if instead we could configure EmberFire to just store the secret objects as a child of /versions/0_0_1/:

{
  "versions" : {
    "0_0_1" : {
      "isActive" : true,
      "secrets" : {
        "<GUID>" : { "content" : ... }
      }
    },
    "0_0_2" : {
      "isActive" : false
    }
  },
}

Ideally I want to configure my ember app to just treat the location /versions/0_0_1/ as if it was the database root.

So as far as the app is concerned, the database consists only of:

{
  "isActive" : true,
  "secrets" : {
    "<GUID>" : { "content" : ... }
  }
}

I understand that in production you really should only have one firebase database per version of the app if the object schema drastically changes, but unfortunately google only provides so many free databases to use, and so it would be nice when testing to be able to have multiple apps accessing the same database, just using different sub-paths.

When I tried changing firebase.databaseURL in config/environment.js from <MyApp>.firebaseio.com/ to <MyApp>.firebaseio.com/versions/0_0_1/ I get an error saying

FIREBASE FATAL ERROR: Database URL must point to the root of a Firebase Database (not including a child path)

so I'm assuming this may not be not supported, at least via the databaseURL configuration option. Is there perhaps another option that could be used instead?

Alternatively, is there a way on a per-Model basis to configure a root path instead of a global one?

0

There are 0 answers