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 0c888ff0
authored
Dec 27, 2011
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sequelize binary can now handle -m/--migrate
1 parent
7d1be4e6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
7 deletions
lib/migrator.js
lib/query-chainer.js
lib/sequelize.js
lib/migrator.js
View file @
0c888ff
...
@@ -40,7 +40,11 @@ module.exports = (function() {
...
@@ -40,7 +40,11 @@ module.exports = (function() {
migrations
.
reverse
()
migrations
.
reverse
()
migrations
.
forEach
(
function
(
migration
)
{
migrations
.
forEach
(
function
(
migration
)
{
chainer
.
add
(
migration
,
'execute'
,
[
options
])
chainer
.
add
(
migration
,
'execute'
,
[
options
],
{
success
:
function
(
migration
,
callback
)
{
saveSuccessfulMigration
.
call
(
self
,
migration
,
callback
)
}
})
})
})
chainer
chainer
...
@@ -129,18 +133,32 @@ module.exports = (function() {
...
@@ -129,18 +133,32 @@ module.exports = (function() {
// private
// private
var
getLastMigration
Id
FromDatabase
=
function
()
{
var
getLastMigrationFromDatabase
=
function
()
{
var
self
=
this
var
self
=
this
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
self
.
findOrCreateSequelizeMetaModel
().
success
(
function
(
SequelizeMeta
)
{
self
.
findOrCreateSequelizeMetaModel
().
success
(
function
(
SequelizeMeta
)
{
SequelizeMeta
.
find
({
order
:
'id DESC'
}).
success
(
function
(
meta
)
{
SequelizeMeta
.
find
({
order
:
'id DESC'
}).
success
(
function
(
meta
)
{
emitter
.
emit
(
'success'
,
meta
?
meta
.
lastMigrationId
:
null
)
emitter
.
emit
(
'success'
,
meta
?
meta
:
null
)
}).
error
(
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
}).
error
(
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
}).
error
(
function
(
err
)
{
emitter
.
emit
(
err
)
})
}).
error
(
function
(
err
)
{
emitter
.
emit
(
err
)
})
}).
run
()
}).
run
()
}
}
var
getLastMigrationIdFromDatabase
=
function
()
{
var
self
=
this
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
getLastMigrationFromDatabase
.
call
(
self
)
.
success
(
function
(
meta
)
{
emitter
.
emit
(
'success'
,
meta
?
meta
.
lastMigrationId
:
null
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
}).
run
()
}
var
getFormattedDateString
=
function
(
s
)
{
var
getFormattedDateString
=
function
(
s
)
{
var
result
=
null
var
result
=
null
...
@@ -157,5 +175,24 @@ module.exports = (function() {
...
@@ -157,5 +175,24 @@ module.exports = (function() {
return
moment
(
getFormattedDateString
(
s
),
"YYYYMMDDHHmmss"
)
return
moment
(
getFormattedDateString
(
s
),
"YYYYMMDDHHmmss"
)
}
}
var
saveSuccessfulMigration
=
function
(
migration
,
callback
)
{
var
self
=
this
getLastMigrationFromDatabase
.
call
(
this
).
success
(
function
(
dbEntry
)
{
if
(
dbEntry
)
{
dbEntry
.
updateAttributes
({
lastMigrationId
:
migration
.
migrationId
})
.
success
(
callback
)
.
error
(
function
(
err
)
{
throw
new
Error
(
err
)
})
}
else
{
self
.
findOrCreateSequelizeMetaModel
().
success
(
function
(
SequelizeMeta
)
{
SequelizeMeta
.
create
({
lastMigrationId
:
migration
.
migrationId
})
.
success
(
callback
)
})
}
}).
error
(
function
(
err
)
{
throw
new
Error
(
err
)
})
}
return
Migrator
return
Migrator
})()
})()
lib/query-chainer.js
View file @
0c888ff
...
@@ -17,9 +17,9 @@ module.exports = (function() {
...
@@ -17,9 +17,9 @@ module.exports = (function() {
}
}
Utils
.
addEventEmitter
(
QueryChainer
)
Utils
.
addEventEmitter
(
QueryChainer
)
QueryChainer
.
prototype
.
add
=
function
(
emitterOrKlass
,
method
,
params
)
{
QueryChainer
.
prototype
.
add
=
function
(
emitterOrKlass
,
method
,
params
,
options
)
{
if
(
!!
method
)
{
if
(
!!
method
)
{
this
.
serials
.
push
({
klass
:
emitterOrKlass
,
method
:
method
,
params
:
params
})
this
.
serials
.
push
({
klass
:
emitterOrKlass
,
method
:
method
,
params
:
params
,
options
:
options
})
}
else
{
}
else
{
observeEmitter
.
call
(
this
,
emitterOrKlass
)
observeEmitter
.
call
(
this
,
emitterOrKlass
)
this
.
emitters
.
push
(
emitterOrKlass
)
this
.
emitters
.
push
(
emitterOrKlass
)
...
@@ -46,8 +46,15 @@ module.exports = (function() {
...
@@ -46,8 +46,15 @@ module.exports = (function() {
if
(
serial
)
{
if
(
serial
)
{
var
emitter
=
serial
.
klass
[
serial
.
method
].
apply
(
serial
.
klass
,
serial
.
params
)
var
emitter
=
serial
.
klass
[
serial
.
method
].
apply
(
serial
.
klass
,
serial
.
params
)
emitter
.
success
(
function
()
{
emitter
.
success
(
function
()
{
if
(
serial
.
options
&&
serial
.
options
.
success
)
{
serial
.
options
.
success
(
serial
.
klass
,
function
()
{
self
.
finishedEmits
++
self
.
finishedEmits
++
exec
()
exec
()
})
}
else
{
self
.
finishedEmits
++
exec
()
}
}).
error
(
function
(
err
)
{
}).
error
(
function
(
err
)
{
self
.
finishedEmits
++
self
.
finishedEmits
++
self
.
fails
.
push
(
err
)
self
.
fails
.
push
(
err
)
...
...
lib/sequelize.js
View file @
0c888ff
...
@@ -56,8 +56,8 @@ module.exports = (function() {
...
@@ -56,8 +56,8 @@ module.exports = (function() {
return
defineCall
(
this
,
DataTypes
)
return
defineCall
(
this
,
DataTypes
)
}
}
Sequelize
.
prototype
.
migrate
=
function
(
_
options
)
{
Sequelize
.
prototype
.
migrate
=
function
(
options
)
{
new
Migrator
(
_
options
).
migrate
()
new
Migrator
(
this
,
options
).
migrate
()
}
}
Sequelize
.
prototype
.
query
=
function
(
sql
,
callee
,
options
)
{
Sequelize
.
prototype
.
query
=
function
(
sql
,
callee
,
options
)
{
...
...
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