Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
mongoose-migration
Advanced tools
Data migration tool for Mongoose
Run the following command to install it:
npm install mongoose-migration --save
The following command should be executed a single time on the project root directory. It will create the .migrate.json
configuration file.
migrate init
After creating it you need to edit and add the path to your models.
Example:
{
"basepath": "migrations",
"connection": "mongodb://localhost/db",
"current_timestamp": 0,
"models": {
"User": "models/user.js"
}
}
Note that on the previous example models/user.js
is the model definition file. This file should exports the mongoose model definition.
model/users.js
example:
...
module.exports = mongoose.model('User', schema);
migrate create <description>
Example:
migrate create "Add createdAt field to users collection"
Open up your migration file (created on the previous step). It should have a default up
and down
function.
Example:
exports.up = function(next) {
next();
};
exports.down = function(next) {
next();
};
Note: To load a mongoose model defined on your configuration file you should call this.model(<model name>)
Example:
exports.up = function(next) {
this
.model('User')
.update(
{},
{
$set: { createdAt: Date.now() }
},
{
multi: true,
strict: false
},
function (error, numberAffected, raw) {
if (error) {
console.error(error);
}
console.log('The number of updated documents was %d', numberAffected);
console.log('The raw response from Mongo was ', raw);
next();
}
);
};
exports.down = function(next) {
this
.model('User')
.update(
{},
{
$unset: { createdAt: 1 }
},
{
multi: true,
strict: false
},
function (error, numberAffected, raw) {
if (error) {
console.error(error);
}
console.log('The number of updated documents was %d', numberAffected);
console.log('The raw response from Mongo was ', raw);
next();
}
);
};
migrate
or
migrate up [number of migrations to perform]
Note: By default migrate
will execute all migrations created until now. However migrate up
will only execute one migration.
migrate down
or
migrate down [number of migrations to rollback]
migrate -h
migrate to [timestamp]
For contributing, open an issue and/or a pull request.
The MIT License (MIT)
Copyright (c) 2014 mccraveiro
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Data migration tool for Mongoose
The npm package mongoose-migration receives a total of 24 weekly downloads. As such, mongoose-migration popularity was classified as not popular.
We found that mongoose-migration demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.