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

db-migrator-distributed

v0.0.4

Published

A tool for executing DB migrations based on Sequelize and Umzug. Safely executes migrations among distributed, synchronously launched server instances, by acquiring a greedy lock on a migration table.

Downloads

462

Readme

db-migrator-distributed

About

A tool for executing DB migrations based on Umzug ( and Sequelize). Coming support for Firestore migrations...

The tool is safely executing migrations among distributed, synchronously launched server instances, by acquiring a greedy lock on a migration table.

Production tested

The tool has been tested and currently used in production env of one project.

It has been successfully tested with up to 6 simultaneously deployed instances.

Currently only tested with Postgres sequelize connection.

Getting started

  1. Install the package:
npm i db-migrator-distributed
  1. In the file where you want to execute the migrations (usually the starting point of your server), import the lib and instantiate the migrator:
import DbMigrator from 'db-migrator-distributed';

const dbMigrator = new DbMigrator({ sequelizeConnection: mySequelizeConn });
try {
  await dbMigrator.run();
} catch (err) {
  process.exit(1); // migrations were unsuccessful
}
  1. Set up your migration files dir and structure. The most typical one would be to have the /migrations dir hold your migrations and put it right under the root source files dir, eg: myProject/src/migrations. Otherwise, you can specify the dir path in the init params of the DbMigrator constructor (see below for full list of possible params).

List possible init params

  • sequelizeConnection {Sequelize} (mandatory) The Sequelize connection instance that you use to connect to your DB

  • migrationsTable {string} (optional) The DB table where Umzug keeps track of the executed migrations so far. Default: '_migrations'

  • migrationsLockTable {string} (optional) The DB table that is going to be used for acquiring the migrations lock. Default: '_migrations_lock'

  • lockTimeoutSeconds {number} (optional) The time (in seconds) after which locks should expire. Default: 60

  • migrationsDirPath {string} (optional) The dir path where you store your migrations files. Default: 'dist/migrations'. If you don't use Typescript or a separate /dist dir for the compiled TS files, then dist won't make sense for you.

  • migrationFilesPattern {RegEx | string} (optional) The regex by which Umzug will determine whether a file in your migrations dir is an actual migration file that is to be executed. Default: /^\d+[\w-_]+\.js$/ . This would match for example 20200330092617-create-users-table.js

  • extraMigrationFuncParams {any[]} (optional) Params, values, objects that you want to pass to your up() and down() migrations execution functions. By default, the first two params will be the Sequelize queryInterface and the Sequelize instance.

  • loggger {any} (optional) A logger that you want to use that the migrator will also use to log events. The default one is bunyan and it's set up to log to the console, so you don't have to provide anything, if you wish.

TODO

  • Finish support of Firestore migrations
  • Add support for rollback functionality
  • Test for other dialects, eg. MySQL