Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 3fc6c8bd
authored
Feb 07, 2014
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add coffee support for --create-migration
1 parent
605391ad
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
17 deletions
bin/sequelize
test/sequelize.executable.test.js
bin/sequelize
View file @
3fc6c8b
...
...
@@ -252,23 +252,46 @@ if (program.migrate || program.undo) {
}
else
if
(
program
.
createMigration
)
{
createMigrationsFolder
()
var
migrationName
=
[
moment
().
format
(
'YYYYMMDDHHmmss'
),
(
typeof
program
.
createMigration
===
'string'
)
?
program
.
createMigration
:
'unnamed-migration'
].
join
(
'-'
)
+
'.js'
var
migrationContent
=
[
"module.exports = {"
,
" up: function(migration, DataTypes, done) {"
,
" // add altering commands here, calling 'done' when finished"
,
" done()"
,
" },"
,
" down: function(migration, DataTypes, done) {"
,
" // add reverting commands here, calling 'done' when finished"
,
" done()"
,
" }"
,
"}"
].
join
(
'\n'
)
+
"\n"
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
(
'-'
)
+
migrationExtension
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"
,
" done()"
,
" },"
,
" down: function(migration, DataTypes, done) {"
,
" // add reverting commands here, calling 'done' when finished"
,
" done()"
,
" }"
,
"}"
].
join
(
'\n'
)
+
"\n"
}
fs
.
writeFileSync
(
configuration
.
migrationsPath
+
'/'
+
migrationName
,
migrationContent
)
console
.
log
(
'New migration "'
+
migrationName
+
'" was added to "'
+
...
...
test/sequelize.executable.test.js
View file @
3fc6c8b
...
...
@@ -142,6 +142,53 @@ describe(Support.getTestDialectTeaser("Executable"), function() {
})
})([
'--create-migration'
,
'-c'
])
;(
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
)
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment