不要怂,就是干,撸起袖子干!

Commit ea52cb9d by Mick Hansen

feat(sync): sync now takes a match regex parameter and will not execute sync unl…

…ess the target database name matches the regex
1 parent 93cba388
Showing with 20 additions and 0 deletions
......@@ -607,6 +607,7 @@ module.exports = (function() {
*
* @param {Object} [options={}]
* @param {Boolean} [options.force=false] If force is true, each DAO will do DROP TABLE IF EXISTS ..., before it tries to create its own table
* @param {RegEx} [options.match] Match a regex against the database name before syncing, a safety check for cases where force: true is used in tests but not live code
* @param {Boolean|function} [options.logging=console.log] A function that logs sql queries, or false for no logging
* @param {String} [options.schema='public'] The schema that the tables should be created in. This can be overriden for each table in sequelize.define
* @return {Promise}
......@@ -617,6 +618,12 @@ module.exports = (function() {
options = Utils._.defaults(options || {}, this.options.sync, this.options);
options.logging = options.logging === undefined ? false : options.logging;
if (options.match) {
if (!options.match.test(this.config.database)) {
return Promise.reject('Database does not match sync match parameter');
}
}
var when;
if (options.force) {
when = this.drop(options);
......
......@@ -706,6 +706,19 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
})
})
})
describe("match", function () {
it('will return an error not matching', function () {
return this.sequelize.sync({
force: true,
match: /alibabaizshaek/
}).then(function () {
throw new Error('I should not have succeeded!');
}, function (err) {
assert(true);
});
});
});
})
describe('drop should work', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!