@ns3777k/mongoose-migrate
v1.0.2
Published
[![Build Status](https://travis-ci.org/ns3777k/mongoose-migrate.svg?branch=master)](https://travis-ci.org/ns3777k/mongoose-migrate) [![npm (scoped)](https://img.shields.io/npm/v/@ns3777k/mongoose-migrate.svg)](https://www.npmjs.com/package/@ns3777k/mongoo
Downloads
3
Readme
mongoose-migrate
A dead simple mongoose migrations tool for mongoose 5.
$ npm install --save @ns3777k/mongoose-migrate
Or
$ yarn add @ns3777k/mongoose-migrate
And finally you can manage your migrations:
$ migrate --help
Take a look at Contributing guide for development purposes.
Docker
You can use pre-built image to run migrations:
$ docker run --rm \
-v /my/project/path:/project \
ns3777k/mongoose-migrate \
--dsn mongodb://... \
-m /project/src/migrations up
Here we're mounting the whole project and then specify path to migration directory. The reason to do that is because
your migrations can use modules from node_modules
directory or separated schemas (like in example below).
Example migration
// Migration: 1555839074983-example-migration.js
import { Schema as AdvSchema } from '../schemas/adv';
/**
* @param {Mongoose} mongoose
* @returns {Promise}
*/
export async function up(mongoose) {
mongoose.model('Adv', AdvSchema, 'Adv');
await mongoose.model('Adv').insertMany([
{
title: 'Use github!',
text: 'Use github for free!'
},
{
title: 'Use adblock',
text: 'Use adblock to block the advs'
}
]);
}
/**
* @param {Mongoose} mongoose
* @returns {Promise}
*/
export async function down(mongoose) {
mongoose.model('Adv', AdvSchema, 'Adv');
await mongoose.model('Adv').deleteMany();
}