npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bridge-node-mongo-migration

v2.0.0

Published

A Node.JS Promised based library intends to provide a migration framework based on MongoDb.

Downloads

3

Readme

codecov

bridge-node-mongo-migration

A Node.JS Promised based library intends to provide a migration framework based on MongoDb.

TODO

  • [] Test with mongodb replicasSet management

How it works

This library manage the following cases:

  • Do not run already run migrations (based on mongoDb store)
  • Alert on altered already run migrations
  • Locking feature while processing (based on mongoDb store)
  • Rollback management (Up/Down)
  • Conditional migration on custom condition

Migration Process

  • Acquire the lock (if not just do nothing)
  • List all migrations in the migration folder (order based on natural file sort)
  • Filter Not Runnable migrations (custom condition filtering)
  • Filter already run migrations
  • Run sequentially all pending migrations
  • If an error occurred while running a migration rollback all newly run migrations (including the failed migration)

Installation

npm i bridge-node-mongo-migration

Usage

This library is a Promise based library

Import this package import {Configuration, Runner} from 'bridge-node-mongo-migration';

You need to provide a configuration.

The configuration Object needs the following keys :

  • mongo : Global mongo client configuration
    • url : Mongo connection URI string (http://mongodb.github.io/node-mongodb-native/2.2/api/MongoClient.html)
    • database : Mongo database to use
    • clientOptions: Mongo client options. See Official mongo documentation for futher details
  • [optional] migrationCollectionName: The name of the MongoDB collection to track already ran migrations, default to _migrations
  • [optional] lockingCollectionName: The name of the MongoDB collection used during migration process, default to _migration_lock
  • [optional] log: Custom logging function with this signature (level: string, message: string, payload: any) => void, default none

Create your configuration

Then, instantiate migration runner : const runner = new Runner(config, <directory to scan>);

The second parameter is the directory that store your migrations scripts (relative to your working directory)

Define your migrations.

Each migrations must be defined in a specific folder (according to your configuration object).

You must define ONE file per migration. This file should :

  • Respect the following naming convention : {orderNumber}_{name} which is resolved by the following regex
  • Export a default class that extends the Migration base class Available with import {Migration} from 'bridge-node-mongo-migration';

A migration could be ignored on custom condition, to achieve that you need to override isRunnable(db: Db): Promise<boolean> migration method.

A migration could be run each times you start a migration process (useful for seeds). To achieve this you need to override alwaysRun(db: Db): Promise<boolean> method on your Migration class.

And finally run the migration process with : runner.executePendingMigrations();