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

dynograte

v2.2.2

Published

DynamoDB migration tool

Downloads

28

Readme

Dynograte

Dynograte is a Node.js DynamoDB migration tool

Installation

npm install dynograte

Dynograte also comes packaged with tooling for making your life easier. You obviously need it. You can install Dynograte globally with:

npm install dynograte -g

Features

  • Migrating DynamoDB tables from a directory
  • Migrating DynamoDB tables from functions
  • Command line tool for auto-generating migration files
  • Reminds you of a dinosaur

How it works

Dynograte creates a DynamoDB table with a name that you specify. This table is used to track migration files that have already been run. Dynograte will only run migration files that do not exist in the migrations table.

Examples

Dynograte can load migrations from a directory

const path = require('path');
const dynamodb = new aws.DynamoDB(config.dynamodb);

let migrationDir = path.resolve(__dirname, './dynamodb-migrations');

return dynograte.migrate({
  dynamodb: dynamodb,
  migrationTableName: 'my-awesome-migration-table',
  migrationDir: migrationDir
});

Dynograte can handle migrations as functions


return dynograte.migrate({
  dynamodb: dynamodb,
  migrationTableName: randomTableName
}, [
  (dynamodb) => {
    return theBestMigration(dynamodb);
  },
  (dynamodb) => {
    return Promise.resolve();
  }
]);

Or a single migration function


return dynograte.migrate({
  dynamodb: dynamodb,
  migrationTableName: randomTableName
}, (dynamodb) => {
  return theBestMigration(dynamodb);
});

Migration Retry

Dynograte supports migration retries. Retrying a migration is usefuly for safe operations that fail and should be tried multiple times.

NOTE: Retrying a DynamoDB migration can be very dangerous. Use this feature with caution. You should only retry migrations like creating a table. Retrying a migration that alters a table could cause a partial table alter that can be difficult to recover from. We recommend backing up your tables!

Dynograte uses the tri module for retries. You can either export true and use the Dynograte default retry options, or specify your own:

// My awesome migration that should retry
exports.retry = true;

exports.up = function(dynograte) {
  ...
};
// My awesome migration that should retry
exports.retry = {
  maxAttempts: 3,
  delay: 100,
  factor: 2,
  jitter: true
};

exports.up = function(dynograte) {
  ...
};

Often times, when a database migration is part of the process startup-tasks, the process may be killed if a migration completely fails to run. The process may restart and we may want to retry it again when it comes back online. If your migration fails, Dynograte remembers that the migration has failed and stores that information in the migration table in DynamoDB.

Dynograte allows you to export runNextMigrateAfterFail that will run a failed migration again the next time dynograte.migrate(...) is called:

// My awesome migration that should run the next time the migrations run if it
// failed to run previously.
exports.runNextMigrateAfterFail = true;

exports.up = function(dynograte) {
  ...
};

CLI

Dynograte comes packaged with a CLI, which will auto-generate migration files. Migration files are prefixed with the current Date in YY-MM-DD-HH-MM-SS format followed by a migration name of your choosing.

dynograte create --dir ~/Proj/dynomodb-migrations --migration update-users-table

The create command will generate a file in ~/Proj/dynomodb-migrations that has a file name similar to 2016-09-07-10-48-28_update-users-table.js.js and looks like:

'use strict';

exports.up = (dynamodb) => {

};

Tests

To run the tests, you can either run docker, or specify your own DynamoDB configuration in config.js.

Run Docker and tests:

npm run docker-test

Run tests without Docker:

npm test

start-docker.sh generates a config.js file that contains the DynamoDB configuration. You can also manually create it to include your own custom config:

'use strict';

const aws = require('aws-sdk');

module.exports = {
  dynamodb: {
    region: 'us-east-1',
    endpoint: new aws.Endpoint('http://localhost:32795')
  }
};