sindresorhus/conf

Migration creates wrong internal version number

Treverix opened this issue · 5 comments

The following code should create an config.json file with the config version number "0.0.1", instead it stores an internal version of "1.0.0":

const Conf = require('conf')

new Conf({
  migrations: {
    "0.0.1": store => {
      store.set('a', 'foo');
    }
  }
});

config.json:

{
	"a": "foo",
	"__internal__": {
		"migrations": {
			"version": "1.0.0"
		}
	}
}

This should give a config.json of version 2.0.0 with a and b set. Instead it creates a version 1.0.0 which only contains a:

const Conf = require('conf')

new Conf({
  migrations: {
    "1.0.0": store => {
      store.set('a', 'foo');
    },
    "2.0.0": store => {
      store.set('b', 'bar');
    },
  }
});

@Treverix unless you specify the projectVersion attribute, the migration system will use the version inside the package.json file. Are you sure the version you have isn't 1.0.0?

@sindresorhus this is not a bug. It's the intended and documented behaviour https://github.com/sindresorhus/conf#projectversion

Ah, I didn't expect it to be related to the project version. I thought, database migrations have their own versioning which is independent of the version of the application itself. In fact, on my project I didn't touch the version on the package.json, as I didn't need to do that.
I have some experience with other db migration tools where we define changesets for all changes of the DDL or for configuration data and to me it looked like the same here: a new 'migration version' is a new kind of changeset and so I define a version number for that.
If it is meant to be different here, I suggest an update on the readme to clarify the term 'version' in the migration context.