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 f5e5b19c
authored
Jul 17, 2014
by
Sebastian Hoitz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #1409
Find pending migrations and return them in getUndoneMigrations
1 parent
08e0ca7c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
17 deletions
lib/migrator.js
test/migrator.test.js
lib/migrator.js
View file @
f5e5b19
...
...
@@ -97,6 +97,12 @@ module.exports = (function() {
callback
&&
callback
(
null
,
result
);
};
var
filterByMigrationId
=
function
(
migrations
,
migrationIds
,
callback
)
{
var
result
=
migrations
.
filter
(
function
(
migration
)
{
return
migrationIds
.
indexOf
(
migration
.
migrationId
)
===
-
1
;
});
callback
&&
callback
(
null
,
result
);
};
var
migrationFiles
=
fs
.
readdirSync
(
this
.
options
.
path
).
filter
(
function
(
file
)
{
return
self
.
options
.
filesFilter
.
test
(
file
);
});
...
...
@@ -109,6 +115,22 @@ module.exports = (function() {
return
parseInt
(
a
.
filename
.
split
(
'-'
)[
0
])
-
parseInt
(
b
.
filename
.
split
(
'-'
)[
0
]);
});
var
existingMigrationIds
=
migrations
.
map
(
function
(
migration
)
{
return
migration
.
migrationId
;
});
var
getPendingMigrations
=
function
(
callback
)
{
getAllMigrationIdsFromDatabase
.
call
(
self
).
success
(
function
(
allMigrationIds
)
{
allMigrationIds
=
allMigrationIds
.
map
(
function
(
migration
)
{
return
parseInt
(
migration
.
to
);
});
if
(
allMigrationIds
)
{
filterByMigrationId
(
migrations
,
allMigrationIds
,
callback
);
}
});
};
if
(
this
.
options
.
from
)
{
filterFrom
(
migrations
,
this
.
options
.
from
,
function
(
err
,
migrations
)
{
if
(
self
.
options
.
to
)
{
...
...
@@ -118,24 +140,13 @@ module.exports = (function() {
}
});
}
else
{
getLastMigrationIdFromDatabase
.
call
(
this
).
success
(
function
(
lastMigrationId
)
{
if
(
lastMigrationId
)
{
filterFrom
(
migrations
,
lastMigrationId
,
function
(
err
,
migrations
)
{
if
(
self
.
options
.
to
)
{
filterTo
(
migrations
,
self
.
options
.
to
,
callback
);
}
else
{
callback
&&
callback
(
null
,
migrations
);
}
},
{
withoutEqual
:
true
});
}
else
{
if
(
self
.
options
.
to
)
{
filterTo
(
migrations
,
self
.
options
.
to
,
callback
);
}
else
{
callback
&&
callback
(
null
,
migrations
);
}
getPendingMigrations
(
function
(
err
,
pendingMigrations
)
{
if
(
self
.
options
.
to
)
{
filterTo
(
pendingMigrations
,
self
.
options
.
to
,
callback
);
}
else
{
callback
&&
callback
(
err
,
pendingMigrations
);
}
}).
error
(
function
(
err
)
{
callback
&&
callback
(
err
,
null
);
});
}
};
...
...
@@ -222,6 +233,31 @@ module.exports = (function() {
// private
var
getAllMigrationIdsFromDatabase
=
Migrator
.
prototype
.
getAllMigrationIdsFromDatabase
=
function
()
{
var
self
=
this
;
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
self
.
findOrCreateSequelizeMetaDAO
()
.
success
(
function
(
SequelizeMeta
)
{
SequelizeMeta
.
findAll
({
order
:
'id DESC'
,
attributes
:
[
'to'
]
})
.
success
(
function
(
meta
)
{
emitter
.
emit
(
'success'
,
meta
?
meta
:
null
);
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'error'
,
err
);
});
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'error'
,
err
);
});
}).
run
();
};
var
getLastMigrationFromDatabase
=
Migrator
.
prototype
.
getLastMigrationFromDatabase
=
function
()
{
var
self
=
this
;
...
...
test/migrator.test.js
View file @
f5e5b19
...
...
@@ -107,6 +107,21 @@ describe(Support.getTestDialectTeaser("Migrator"), function() {
})
})
})
it
(
"returns pending migrations"
,
function
(
done
)
{
this
.
init
(
undefined
,
function
(
migrator
,
SequelizeMeta
)
{
SequelizeMeta
.
create
({
from
:
20111117063700
,
to
:
20111117063700
}).
success
(
function
()
{
SequelizeMeta
.
create
({
from
:
20111117063700
,
to
:
20130909185621
}).
success
(
function
()
{
migrator
.
getUndoneMigrations
(
function
(
err
,
migrations
)
{
expect
(
err
).
to
.
be
.
null
expect
(
migrations
).
to
.
have
.
length
(
14
)
expect
(
migrations
[
0
].
filename
).
to
.
equal
(
'20111130161100-emptyMigration.js'
)
done
()
})
})
})
})
})
})
describe
(
'migrations'
,
function
()
{
...
...
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