Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed config usage

now we just do a simple readdir to determine the
latest migration number
  • Loading branch information...
commit 7d2d16b3b0a0b48d47f06e0d017f50fec290634e 1 parent 540ec80
@tj authored
Showing with 26 additions and 37 deletions.
  1. +26 −37 bin/migrate
View
63 bin/migrate
@@ -102,27 +102,6 @@ while (args.length) {
}
/**
- * Load configuration.
- */
-
-function loadConfig() {
- try {
- return JSON.parse(fs.readFileSync('migrations/migrate.json', 'utf8'));
- } catch (err) {
- return { prev: -1 };
- }
-}
-
-/**
- * Save configuration.
- */
-
-function saveConfig(obj) {
- var json = JSON.stringify(obj);
- fs.writeFileSync('migrations/migrate.json', json);
-}
-
-/**
* Load migrations.
*/
@@ -158,10 +137,6 @@ try {
// ignore
}
-// load config
-
-var config = loadConfig();
-
// commands
var commands = {
@@ -187,24 +162,38 @@ var commands = {
*/
create: function(){
- var curr = ++config.prev
- , title = slugify(Array.prototype.slice.call(arguments).join(' '));
-
- // append '-' when title is present
+ var migrations = fs.readdirSync('migrations').filter(function(file){
+ return file.match(/^\d+/);
+ }).map(function(file){
+ return parseInt(file.match(/^(\d+)/)[1]);
+ }).sort();
+
+ var curr = migrations.pop() + 1
+ , title = slugify([].slice.call(arguments).join(' '));
title = title ? curr + '-' + title : curr;
-
- var path = 'migrations/' + title + '.js';
- log('create', join(cwd, path));
- fs.writeFileSync(path, template);
- saveConfig(config);
+ create(title);
}
};
-// perform migration
+/**
+ * Create a migration with the given `name`.
+ *
+ * @param {String} name
+ */
+
+function create(name) {
+ var path = 'migrations/' + name + '.js';
+ log('create', join(cwd, path));
+ fs.writeFileSync(path, template);
+}
+
+/**
+ * Perform a migration in the given `direction`.
+ *
+ * @param {Number} direction
+ */
function performMigration(direction) {
- // no migrations
- if (-1 == config.prev) abort('add migrations before running $ migrate ' + direction);
migrate('migrations/.migrate');
migrations().forEach(function(path){
var mod = require(process.cwd() + '/' + path);
Please sign in to comment.
Something went wrong with that request. Please try again.