1.1.0 • Published 5 years ago

sequelize-sync-cfn-custom-resource v1.1.0

Weekly downloads
7
License
-
Repository
github
Last release
5 years ago

sequelize-sync-cfn-custom-resource

This library supplies a custom resource handler generator that uses your models and migrations in a webpackable way to sync/migrate your database.

Usage

Install

npm install --save sequelize-sync-cfn-custom-resource

Migration Preparation

For your migrations to be webpackable they must be required by some module.

Use the prepare-sequelize-migrations binary that arrives with this module, which creates a .migrations.js file that will soon be required by your custom resource.

./node_modules/.bin/prepare-sequelize-migrations

The generated file should probably be git ignored.

See the script for more complex usage.

Custom Resource Handler

In your own JavaScript module:

const createHandler = require('@puresec/sequelize-sync-cfn-custom-resource');

module.exports.handler = createHandler({
  requireModels: () => require('./models'),
  requireMigrations: () => require('./.migrations'),
  logging: (message) => { /* ... */ }, // optional
});

Use your module's handler for the function that is used as the custom resource.

How it works

During the CloudFormation lifecycle, the custom resource will:

  • create: Sync the initial schema and mark all migrations as executed.
  • update: Run all pending migrations (make sure the resource has a UUID updated with every new migration).
  • delete: Does nothing for now.

The createHandler function receives 2 functions:

  • requireModels: returns your required models (must export sequelize and Sequelize).
  • requireMigrations: returns your required migrations, generated using the prepare-sequelize-migrations binary.

These functions are supplied so that webpack can pack the relevant JavaScript files into the function's artifact, with your own code.

They are supplied as functions so that failure to require them will not prevent sending a response to CloudFormation (using safe-cfn-custom-resource).

Development

Publish a new version

Set the "version" in package.json, then run:

npm publish --access public

(if you have permissions)