forked from mozilla/openbadges-backpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into staging
- Loading branch information
Showing
27 changed files
with
1,110 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
*.tar.gz | ||
*.pid | ||
|
||
/notes | ||
/docs | ||
/node_modules | ||
/bin/update-docs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!/usr/bin/env node | ||
|
||
var assert = require('assert'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var util = require('util'); | ||
var optimist = require('optimist'); | ||
var migrate = require('db-migrate'); | ||
var log = require('db-migrate/lib/log'); | ||
var mysql = require('../lib/mysql'); | ||
var migrations = require('../lib/migrations'); | ||
|
||
process.on('uncaughtException', function(err) { | ||
log.error(err.stack); | ||
process.exit(1); | ||
}); | ||
|
||
var argv = optimist | ||
.default({ | ||
verbose: false | ||
}) | ||
.usage('Usage: db-migrate [up|down|create] migrationName [options]') | ||
|
||
.describe('count', 'Max number of migrations to run.') | ||
.alias('c', 'count') | ||
.string('c') | ||
|
||
.describe('dry-run', "Prints the SQL but doesn't run it.") | ||
.boolean('dry-run') | ||
|
||
.describe('verbose', 'Verbose mode.') | ||
.alias('v', 'verbose') | ||
.boolean('v') | ||
|
||
.alias('h', 'help') | ||
.alias('h', '?') | ||
.boolean('h') | ||
.argv; | ||
|
||
if (argv.help || argv._.length == 0) { | ||
optimist.showHelp(); | ||
process.exit(1); | ||
} | ||
|
||
global.verbose = argv.verbose; | ||
global.dryRun = argv['dry-run']; | ||
if(global.dryRun) { | ||
log.info('dry run'); | ||
} | ||
|
||
function executeCreate() { | ||
if(argv._.length == 0) { | ||
log.error("'migrationName' is required."); | ||
optimist.showHelp(); | ||
process.exit(1); | ||
} | ||
|
||
argv.title = argv._.shift(); | ||
migrate.createMigration(argv.title, migrations.dir, function(err, migration) { | ||
assert.ifError(err); | ||
log.info(util.format('Created migration at %s', migration.path)); | ||
}); | ||
} | ||
|
||
function onComplete(err) { | ||
assert.ifError(err); | ||
log.info('Done'); | ||
} | ||
|
||
function run() { | ||
var action = argv._.shift(); | ||
switch(action) { | ||
case 'create': | ||
executeCreate(); | ||
break; | ||
case 'up': | ||
case 'down': | ||
if(verbose) { | ||
log.info("Using settings:", mysql.getDatabaseConfig()); | ||
} | ||
if(argv._.length > 0) { | ||
argv.destination = argv._.shift().toString(); | ||
} | ||
if(action == 'up') { | ||
migrations.up(argv, onComplete); | ||
} else { | ||
migrations.down(argv, onComplete); | ||
} | ||
break; | ||
|
||
default: | ||
log.error('Invalid Action: Must be [up|down|create].'); | ||
optimist.showHelp(); | ||
process.exit(1); | ||
break; | ||
} | ||
} | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
|
||
function findSHAInHead(file) { | ||
try { | ||
var head = fs.readFileSync(file, 'utf8').trim(); | ||
} | ||
catch (ex) { | ||
throw new Error('Could not read HEAD file: ' + file); | ||
} | ||
if(head.indexOf('ref:') === 0){ | ||
var ref = head.split(/\s+/)[1].trim(); | ||
var gitDir = path.dirname(file); | ||
var refFile = path.join(gitDir, ref); | ||
return findSHAInRef(refFile); | ||
} | ||
else if(/^[0-9a-f]{40}$/m.test(head)) { | ||
return head; | ||
} | ||
else { | ||
throw new Error('Unable to parse HEAD file: ' + file); | ||
} | ||
}; | ||
|
||
function findSHAInRef(file) { | ||
try { | ||
var sha = fs.readFileSync(file, 'utf8').trim(); | ||
} | ||
catch (ex) { | ||
throw new Error('Could not read ref file: ' + file); | ||
} | ||
return sha; | ||
} | ||
|
||
exports.findSHA = function(file) { | ||
var file = file || path.join(__dirname, '../.git/HEAD'); | ||
return findSHAInHead(file); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
var path = require('path'); | ||
var migrate = require('db-migrate'); | ||
var mysql = require('./mysql'); | ||
|
||
module.exports = { | ||
dir: path.resolve(__dirname, '..', 'migrations'), | ||
up: function(options, callback) { | ||
if (arguments.length == 1) { | ||
callback = options; | ||
options = {}; | ||
} | ||
options.config = options.config || mysql.getDatabaseConfig(); | ||
options.count = options.count || Number.MAX_VALUE; | ||
migrate.connect(options.config, function(err, migrator) { | ||
if (err) throw err; | ||
migrator.migrationsDir = module.exports.dir; | ||
migrator.driver.createMigrationsTable(function(err) { | ||
if (err) throw err; | ||
migrator.up(options, function(err) { | ||
migrator.driver.close(); | ||
callback(err); | ||
}); | ||
}); | ||
}); | ||
}, | ||
down: function(options, callback) { | ||
if (arguments.length == 1) { | ||
callback = options; | ||
options = {}; | ||
} | ||
options.config = options.config || mysql.getDatabaseConfig(); | ||
if (!options.destination && !options.count) | ||
options.count = 1; | ||
migrate.connect(options.config, function(err, migrator) { | ||
if (err) throw err; | ||
migrator.migrationsDir = module.exports.dir; | ||
migrator.driver.createMigrationsTable(function(err) { | ||
if (err) throw err; | ||
migrator.down(options, function(err) { | ||
migrator.driver.close(); | ||
callback(err); | ||
}); | ||
}); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.