不要怂,就是干,撸起袖子干!

Commit 3fc6c8bd by Sascha Depold

Add coffee support for --create-migration

1 parent 605391ad
......@@ -252,12 +252,33 @@ if (program.migrate || program.undo) {
} else if(program.createMigration) {
createMigrationsFolder()
var migrationName = [
try {
var config = readConfig()
} catch(e) {
console.log(e.message)
process.exit(1)
}
var mirationContent = ""
, migrationExtension = (program.coffee || config.coffee) ? '.coffee' : '.js'
, migrationName = [
moment().format('YYYYMMDDHHmmss'),
(typeof program.createMigration === 'string') ? program.createMigration : 'unnamed-migration'
].join('-') + '.js'
].join('-') + migrationExtension
var migrationContent = [
if (program.coffee || config.coffee) {
migrationContent = [
"module.exports = ",
" up: (migration, DataTypes, done) ->",
" # add altering commands here, calling 'done' when finished",
" done()",
"",
" down: (migration, DataTypes, done) ->",
" # add reverting commands here, calling 'done' when finished",
" done()"
].join('\n') + "\n"
} else {
migrationContent = [
"module.exports = {",
" up: function(migration, DataTypes, done) {",
" // add altering commands here, calling 'done' when finished",
......@@ -269,6 +290,8 @@ if (program.migrate || program.undo) {
" }",
"}"
].join('\n') + "\n"
}
fs.writeFileSync(configuration.migrationsPath + '/' + migrationName, migrationContent)
console.log('New migration "' + migrationName + '" was added to "' +
......
......@@ -145,6 +145,53 @@ describe(Support.getTestDialectTeaser("Executable"), function() {
;(function(flags) {
flags.forEach(function(flag) {
var prepare = function(callback) {
exec("rm -rf ./*", { cwd: __dirname + '/tmp' }, function() {
exec("../../bin/sequelize --init", { cwd: __dirname + '/tmp' }, function() {
exec("../../bin/sequelize " + flag + " 'foo'", { cwd: __dirname + '/tmp' }, callback)
})
})
}
describe(flag, function() {
it("creates a new file with the current timestamp", function(done) {
prepare(function() {
exec("ls -1 migrations", { cwd: __dirname + '/tmp' }, function(err, stdout) {
var date = new Date()
, format = function(i) { return (parseInt(i, 10) < 10 ? '0' + i : i) }
, sDate = [date.getFullYear(), format(date.getMonth() + 1), format(date.getDate()), format(date.getHours()), format(date.getMinutes())].join('')
expect(stdout).to.match(new RegExp(sDate + "..-foo.coffee"))
done()
})
})
})
it("adds a skeleton with an up and a down method", function(done) {
prepare(function() {
exec("cat migrations/*-foo.coffee", { cwd: __dirname + '/tmp' }, function(err, stdout) {
expect(stdout).to.include('up: (migration, DataTypes, done) ->')
expect(stdout).to.include('down: (migration, DataTypes, done) ->')
done()
})
})
})
it("calls the done callback", function(done) {
prepare(function() {
exec("cat migrations/*-foo.coffee", { cwd: __dirname + '/tmp' }, function(err, stdout) {
expect(stdout).to.include('done()')
expect(stdout.match(/(done\(\))/)).to.have.length(2)
done()
})
})
})
})
})
})(['--coffee --create-migration', '--coffee -c'])
;(function(flags) {
flags.forEach(function(flag) {
var prepare = function(callback) {
exec("rm -rf ./*", { cwd: __dirname + '/tmp' }, function(error, stdout) {
exec("../../bin/sequelize --init", { cwd: __dirname + '/tmp' }, function(error, stdout) {
var source = (flag.indexOf('coffee') === -1)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!