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

serverless-sequelize-migrations

v1.1.2

Published

A Serverless plugin to manage sequelize migrations

Downloads

2,124

Readme

Features:

  • Create migration file
  • List pending and executed migrations
  • Apply pending migrations
  • Revert applied migrations
  • Reset all applied migrations

Documentation

Installation

  1. Add Serverless Sequelize Migrations to your project:
npm install --save serverless-sequelize-migrations
  1. Inside your serverless.yml file add the following entry to the plugins section (if there is no plugin section in the file you'll need to add it):
plugins:
    - serverless-sequelize-migrations

You can check whether the plugin is ready to be used through the terminal. To do so, type the following command on the CLI:

serverless --help

the console should display SequelizeMigrations as one of the available plugins in your Serverless project.

Setting up Sequelize

For the plugin to work correctly, you have to set the database information as environment variables on the service provider section as follows:

provider:
  environment:
    DB_DIALECT: 'database_dialect' /* one of 'mysql' | 'mariadb' | 'postgres' | 'mssql' */
    DB_NAME: 'database_name'
    DB_USERNAME: 'database_username'
    DB_PASSWORD: 'database_password'
    DB_HOST: 'database_host'
    DB_PORT: 'database_port'

or by using DB_CONNECTION_URL

provider:
  environment:
    DB_CONNECTION_URL: database_dialect://database_username:database_password@database_host:database_port/database_name`

Replace the variables with the information of your own database.

Obs: This plugin does not have support to create the database itself.

As per Sequelize docs, you'll have to manually install the driver for your database of choice:

# One of the following:
$ npm install --save pg pg-hstore # Postgres
$ npm install --save mysql2 # MySQL
$ npm install --save mariadb # MariaDB
$ npm install --save tedious # Microsoft SQL Server

Usage and command line options

To see the available commands of the plugin, run sls migrations --help on the terminal. The following should appear:

migrations .................... Sequelize migrations management for Serverless
migrations create ............. Create a migration file
migrations up ................. Execute all pending migrations
migrations down ............... Rolls back one or more migrations
migrations reset .............. Rolls back all migrations
migrations list ............... Shows a list of migrations
    --path / -p ........................ Specify the migrations path (default is './migrations')
    --verbose / -v ..................... Shows sequelize logs

For any of these commands, you can specify two parameters:

  • --path to inform the path of migrations on your project.
  • --verbose to show sequelize execution logs during the operations.

In order to see the options of each command individually, you can run sls migrations <command> --help on the terminal.

The commands (those that have some option) and it's options are presented below:

  • migrations create
--name / -n (required) ... Specify the name of the migration to be created
  • migrations up
--rollback / -r .......... Rolls back applied migrations in case of error (default is false)
--dbDialect ........................ Specify the database dialect (one of: 'mysql', 'mariadb', 'postgres', 'mssql')
--dbHost ........................... Specify the database host
--dbPort ........................... Specify the database port
--dbName ........................... Specify the database name
--dbUsername ....................... Specify the database username
--dbPassword ....................... Specify the database password
  • migrations down
--times / -t ............. Specify how many times to roll back (default is 1)
--name / -n .............. Specify the name of the migration to be rolled back (e.g. "--name create-users.js")
--dbDialect ........................ Specify the database dialect (one of: 'mysql', 'mariadb', 'postgres', 'mssql')
--dbHost ........................... Specify the database host
--dbPort ........................... Specify the database port
--dbName ........................... Specify the database name
--dbUsername ....................... Specify the database username
--dbPassword ....................... Specify the database password
  • migrations list
--status / -s ............ Specify the status of migrations to be listed (--status pending [default] or --status executed)
--dbDialect ........................ Specify the database dialect (one of: 'mysql', 'mariadb', 'postgres', 'mssql')
--dbHost ........................... Specify the database host
--dbPort ........................... Specify the database port
--dbName ........................... Specify the database name
--dbUsername ....................... Specify the database username
--dbPassword ....................... Specify the database password

Custom migrations path

You can also define a migrations path variable on the custom section of your project service file.

custom:
  migrationsPath: './custom/migrations/path'

Important: if you inform the --path option through the CLI, this configuration will be ignored.

Credits and inspiration

This plugin was first based on Nevon's serverless-pg-migrations.

License

MIT