coresmart / persistencejs

persistence.js is an asynchronous Javascript database mapper library. You can use it in the browser, as well on the server (and you can share data models between them).
http://persistencejs.org
1.73k stars 240 forks source link

Resolve issue with Issue with calling persistence.migrate with no par… #175

Open jaylagare opened 8 years ago

jaylagare commented 8 years ago

Per documentation: persistence.migrate() to run migrations up to the most recent

I encountered an issue where calling persistence.migrate with no parameters didn't do anything. Checking the code of persistence.migrations.js, I found the problem where version is undefined and thus no migration is done and only the callback is called: if (curVersion < version) Migrator.migrateUpTo(version, callback); else if (curVersion > version) Migrator.migrateDownTo(version, callback); else callback();

Solution is to update code from: migrate: function(version, callback) { if ( arguments.length === 1) { callback = version; version = this.migrations.length-1; }

to: migrate: function(version, callback) { if ( arguments.length === 1) { callback = version; } if (arguments.lemgth <= 1) { version = this.migrations.length-1; }