Skip to content

Commit

Permalink
Adding optional migration callback to make migrations more general in…
Browse files Browse the repository at this point in the history
… usage.
  • Loading branch information
Anthony Roldan authored and xavierlacot committed Jul 26, 2011
1 parent bf1e55a commit 1bf1bb0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion joli.js
Expand Up @@ -398,7 +398,7 @@ joli.Models.prototype = {
});
},

migrate: function(version) {
migrate: function(version, migrationCallback) {
// create migration table
var query = 'CREATE TABLE IF NOT EXISTS ' + this.migration.table + ' (version)';
joli.connection.execute(query);
Expand All @@ -408,6 +408,14 @@ joli.Models.prototype = {
var query = 'DROP TABLE IF EXISTS ' + modelName;
joli.connection.execute(query);
});

// optional migration callback
if(migrationCallback && typeof(migrationCallback) == "function") {
migrationCallback({
table:this.migration.table,
newVersion:version
});
}

// insert migration
this.migration.setVersion(version);
Expand Down

0 comments on commit 1bf1bb0

Please sign in to comment.