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 1d805d22
authored
Sep 18, 2014
by
jtschoonhoven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed migrations bug from issue #1829, down migrations now operate only on completed migrations
1 parent
f7c25fca
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
8 deletions
lib/migrator.js
test/migrator.test.js
lib/migrator.js
View file @
1d805d2
...
...
@@ -33,17 +33,26 @@ module.exports = (function() {
},
options
||
{});
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
self
.
getUndoneMigrations
(
function
(
err
,
migrations
)
{
if
(
options
.
method
===
'down'
)
{
self
.
getCompletedMigrations
(
function
(
err
,
migrations
){
self
.
processMigrations
(
err
,
migrations
,
options
,
emitter
)
})
}
else
{
self
.
getUndoneMigrations
(
function
(
err
,
migrations
){
self
.
processMigrations
(
err
,
migrations
,
options
,
emitter
)
});
}
}).
run
();
};
Migrator
.
prototype
.
processMigrations
=
function
(
err
,
migrations
,
options
,
emitter
)
{
var
self
=
this
;
if
(
err
)
{
emitter
.
emit
(
'error'
,
err
);
}
else
{
var
chainer
=
new
Utils
.
QueryChainer
()
,
from
=
migrations
[
0
];
if
(
options
.
method
===
'down'
)
{
migrations
.
reverse
();
}
if
(
migrations
.
length
===
0
)
{
self
.
options
.
logging
(
'There are no pending migrations.'
);
}
else
{
...
...
@@ -55,7 +64,7 @@ module.exports = (function() {
chainer
.
add
(
migration
,
'execute'
,
[
options
],
{
before
:
function
(
migration
)
{
self
.
options
.
logging
(
migration
.
filename
);
self
.
options
.
logging
(
migration
.
filename
||
migration
.
id
);
migrationTime
=
process
.
hrtime
();
},
...
...
@@ -81,8 +90,6 @@ module.exports = (function() {
.
success
(
function
()
{
emitter
.
emit
(
'success'
,
null
);
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'error'
,
err
);
});
}
});
}).
run
();
};
Migrator
.
prototype
.
getUndoneMigrations
=
function
(
callback
)
{
...
...
@@ -151,6 +158,41 @@ module.exports = (function() {
}
};
Migrator
.
prototype
.
getCompletedMigrations
=
function
(
callback
)
{
var
self
=
this
;
var
filterByMigrationId
=
function
(
migrations
,
allMigrationIds
,
callback
)
{
return
migrations
.
filter
(
function
(
migration
)
{
return
allMigrationIds
.
indexOf
(
migration
.
migrationId
)
>
-
1
});
};
var
migrationFiles
=
fs
.
readdirSync
(
this
.
options
.
path
).
filter
(
function
(
file
)
{
return
self
.
options
.
filesFilter
.
test
(
file
);
});
var
migrations
=
migrationFiles
.
map
(
function
(
file
)
{
return
new
Migration
(
self
,
self
.
options
.
path
+
'/'
+
file
);
});
migrations
=
migrations
.
sort
(
function
(
a
,
b
)
{
return
parseInt
(
a
.
filename
.
split
(
'-'
)[
0
])
-
parseInt
(
b
.
filename
.
split
(
'-'
)[
0
]);
});
var
existingMigrationIds
=
migrations
.
map
(
function
(
migration
)
{
return
migration
.
migrationId
;
});
getAllMigrationIdsFromDatabase
.
call
(
self
)
.
then
(
function
(
allMigrationIds
)
{
allMigrationIds
=
allMigrationIds
.
map
(
function
(
migration
)
{
return
parseInt
(
migration
.
to
);
});
var
completedMigrations
=
filterByMigrationId
(
migrations
,
allMigrationIds
)
callback
(
null
,
completedMigrations
||
[])
})
};
Migrator
.
prototype
.
findOrCreateSequelizeMetaDAO
=
function
(
syncOptions
)
{
var
self
=
this
;
...
...
test/migrator.test.js
View file @
1d805d2
...
...
@@ -27,6 +27,44 @@ describe(Support.getTestDialectTeaser("Migrator"), function() {
}.
bind
(
this
)
})
describe
(
'getCompletedMigrations'
,
function
(){
it
(
"supports coffee files"
,
function
(
done
)
{
this
.
init
({
filesFilter
:
/
\.
coffee$/
,
to
:
20111117063700
},
function
(
migrator
,
SequelizeMeta
)
{
SequelizeMeta
.
create
({
from
:
null
,
to
:
20111117063700
}).
success
(
function
()
{
migrator
.
getCompletedMigrations
(
function
(
err
,
migrations
)
{
expect
(
err
).
to
.
be
.
null
expect
(
migrations
).
to
.
have
.
length
(
1
)
done
()
})
})
})
})
it
(
"only returns migrations if timestamps in db are after timestamps of files"
,
function
(
done
)
{
this
.
init
({
to
:
20111117063700
},
function
(
migrator
,
SequelizeMeta
)
{
SequelizeMeta
.
create
({
from
:
null
,
to
:
20111117063700
}).
success
(
function
()
{
migrator
.
getCompletedMigrations
(
function
(
err
,
migrations
)
{
expect
(
err
).
to
.
be
.
null
expect
(
migrations
).
to
.
have
.
length
(
1
)
done
()
})
})
})
})
it
(
"returns no migrations if timestamps in db are before timestamps of files"
,
function
(
done
)
{
this
.
init
({
to
:
20111117063700
},
function
(
migrator
,
SequelizeMeta
)
{
SequelizeMeta
.
create
({
from
:
null
,
to
:
20101117063700
}).
success
(
function
()
{
migrator
.
getCompletedMigrations
(
function
(
err
,
migrations
)
{
expect
(
err
).
to
.
be
.
null
expect
(
migrations
).
to
.
have
.
length
(
0
)
done
()
})
})
})
})
})
describe
(
'getUndoneMigrations'
,
function
()
{
it
(
"supports coffee files"
,
function
(
done
)
{
this
.
init
({
...
...
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