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 50cdf475
authored
Dec 29, 2011
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored sequelize meta
1 parent
2ee83449
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
19 deletions
lib/migrator.js
spec/migrator.spec.js
lib/migrator.js
View file @
50cdf47
...
...
@@ -42,7 +42,7 @@ module.exports = (function() {
migrations
.
forEach
(
function
(
migration
)
{
chainer
.
add
(
migration
,
'execute'
,
[
options
],
{
success
:
function
(
migration
,
callback
)
{
saveSuccessfulMigration
.
call
(
self
,
migration
,
callback
)
saveSuccessfulMigration
.
call
(
self
,
migration
s
[
0
],
migration
,
callback
)
}
})
})
...
...
@@ -115,7 +115,8 @@ module.exports = (function() {
if
(
!
storedModel
)
{
SequelizeMeta
=
self
.
sequelize
.
define
(
'SequelizeMeta'
,
{
lastMigrationId
:
DataTypes
.
STRING
from
:
DataTypes
.
STRING
,
to
:
DataTypes
.
STRING
})
}
...
...
@@ -151,7 +152,7 @@ module.exports = (function() {
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
getLastMigrationFromDatabase
.
call
(
self
)
.
success
(
function
(
meta
)
{
emitter
.
emit
(
'success'
,
meta
?
meta
.
lastMigrationId
:
null
)
emitter
.
emit
(
'success'
,
meta
?
meta
.
to
:
null
)
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
...
...
@@ -175,23 +176,14 @@ module.exports = (function() {
return
moment
(
getFormattedDateString
(
s
),
"YYYYMMDDHHmmss"
)
}
var
saveSuccessfulMigration
=
function
(
migration
,
callback
)
{
var
saveSuccessfulMigration
=
function
(
from
,
to
,
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
)
})
self
.
findOrCreateSequelizeMetaModel
().
success
(
function
(
SequelizeMeta
)
{
SequelizeMeta
.
create
({
from
:
from
.
migrationId
,
to
:
to
.
migrationId
})
.
success
(
callback
)
})
}
return
Migrator
...
...
spec/migrator.spec.js
View file @
50cdf47
...
...
@@ -90,7 +90,7 @@ describe('Migrator', function() {
setup
()
Helpers
.
async
(
function
(
done
)
{
SequelizeMeta
.
create
({
lastMigrationId
:
'20111117063700'
}).
success
(
function
()
{
SequelizeMeta
.
create
({
from
:
null
,
to
:
'20111117063700'
}).
success
(
function
()
{
migrator
.
getUndoneMigrations
(
function
(
err
,
migrations
)
{
expect
(
err
).
toBeNull
()
expect
(
migrations
.
length
).
toEqual
(
7
)
...
...
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