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 91f3c8c1
authored
Aug 20, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correctly propagate the emitter
1 parent
b1b9a661
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
17 deletions
Makefile
bin/sequelize
lib/migrator.js
lib/sequelize.js
Makefile
View file @
91f3c8c
...
...
@@ -36,6 +36,6 @@ postgresn: postgres-native
# test all the dialects \o/
all
:
sqlite mysql postgres postgres-native
binary
all
:
sqlite mysql postgres postgres-native
.PHONY
:
sqlite mysql postgres pgsql postgres-native postgresn all test
binary
.PHONY
:
sqlite mysql postgres pgsql postgres-native postgresn all test
bin/sequelize
View file @
91f3c8c
...
...
@@ -114,8 +114,8 @@ if(typeof program.env === 'string') {
configuration
.
environment
=
program
.
env
}
if
(
program
.
migrate
)
{
if
(
configFileExists
())
{
if
(
program
.
migrate
)
{
if
(
configFileExists
())
{
var
config
,
options
=
{}
...
...
@@ -130,8 +130,9 @@ if(program.migrate) {
if
([
'database'
,
'username'
,
'password'
].
indexOf
(
key
)
==
-
1
)
{
options
[
key
]
=
value
}
if
(
key
===
"use_env_variable"
)
{
if
(
process
.
env
[
value
])
{
if
(
key
===
"use_env_variable"
)
{
if
(
process
.
env
[
value
])
{
var
db_info
=
process
.
env
[
value
].
match
(
/
([^
:
]
+
)
:
\/\/([^
:
]
+
)
:
([^
@
]
+
)
@
([^
:
]
+
)
:
(\d
+
)\/(
.+
)
/
);
config
.
database
=
db_info
[
6
];
...
...
@@ -153,17 +154,22 @@ if(program.migrate) {
,
migratorOptions
=
{
path
:
configuration
.
migrationsPath
}
,
migrator
=
sequelize
.
getMigrator
(
migratorOptions
)
if
(
program
.
undo
)
{
if
(
program
.
undo
)
{
sequelize
.
migrator
.
findOrCreateSequelizeMetaDAO
().
success
(
function
(
Meta
)
{
Meta
.
find
({
order
:
'id DESC'
}).
success
(
function
(
meta
)
{
if
(
meta
)
{
if
(
meta
)
{
migrator
=
sequelize
.
getMigrator
(
_
.
extend
(
migratorOptions
,
meta
),
true
)
}
migrator
.
migrate
({
method
:
'down'
})
migrator
.
migrate
({
method
:
'down'
}).
success
(
function
()
{
process
.
exit
(
0
)
})
})
})
}
else
{
sequelize
.
migrate
()
sequelize
.
migrate
().
success
(
function
()
{
process
.
exit
(
0
)
})
}
}
else
{
console
.
log
(
'Cannot find "'
+
relativeConfigFile
()
+
'". Have you run "sequelize --init"?'
)
...
...
lib/migrator.js
View file @
91f3c8c
...
...
@@ -58,8 +58,10 @@ module.exports = (function() {
}
else
{
self
.
options
.
logging
(
"Running migrations..."
)
}
migrations
.
forEach
(
function
(
migration
)
{
var
migrationTime
chainer
.
add
(
migration
,
'execute'
,
[
options
],
{
before
:
function
(
migration
)
{
if
(
self
.
options
.
logging
!==
false
)
{
...
...
@@ -67,6 +69,7 @@ module.exports = (function() {
}
migrationTime
=
process
.
hrtime
()
},
after
:
function
(
migration
)
{
migrationTime
=
process
.
hrtime
(
migrationTime
)
migrationTime
=
Math
.
round
(
(
migrationTime
[
0
]
*
1000
)
+
(
migrationTime
[
1
]
/
1000000
));
...
...
@@ -75,6 +78,7 @@ module.exports = (function() {
self
.
options
.
logging
(
'Completed in '
+
migrationTime
+
'ms'
)
}
},
success
:
function
(
migration
,
callback
)
{
if
(
options
.
method
===
'down'
)
{
deleteUndoneMigration
.
call
(
self
,
from
,
migration
,
callback
)
...
...
@@ -233,11 +237,21 @@ module.exports = (function() {
var
self
=
this
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
self
.
findOrCreateSequelizeMetaDAO
().
success
(
function
(
SequelizeMeta
)
{
SequelizeMeta
.
find
({
order
:
'id DESC'
}).
success
(
function
(
meta
)
{
emitter
.
emit
(
'success'
,
meta
?
meta
:
null
)
}).
error
(
function
(
err
)
{
emitter
.
emit
(
'error'
,
err
)
})
}).
error
(
function
(
err
)
{
emitter
.
emit
(
'error'
,
err
)
})
self
.
findOrCreateSequelizeMetaDAO
()
.
success
(
function
(
SequelizeMeta
)
{
SequelizeMeta
.
find
({
order
:
'id DESC'
})
.
success
(
function
(
meta
)
{
emitter
.
emit
(
'success'
,
meta
?
meta
:
null
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'error'
,
err
)
})
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'error'
,
err
)
})
}).
run
()
}
...
...
@@ -245,7 +259,8 @@ module.exports = (function() {
var
self
=
this
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
getLastMigrationFromDatabase
.
call
(
self
)
getLastMigrationFromDatabase
.
call
(
self
)
.
success
(
function
(
meta
)
{
emitter
.
emit
(
'success'
,
meta
?
meta
.
to
:
null
)
})
...
...
lib/sequelize.js
View file @
91f3c8c
...
...
@@ -210,7 +210,7 @@ module.exports = (function() {
}
Sequelize
.
prototype
.
migrate
=
function
(
options
)
{
this
.
getMigrator
().
migrate
(
options
)
return
this
.
getMigrator
().
migrate
(
options
)
}
Sequelize
.
prototype
.
query
=
function
(
sql
,
callee
,
options
,
replacements
)
{
...
...
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