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

sql-apply

v2.1.6

Published

This library performs flyway migrations on a postgres database without using external tools.

Downloads

26

Readme

Node.js CI codecov

SQL Apply

This project aims at doing what the already existing flyway project is doing in the JVM world. It allows you to define one or multiple directories where you can create SQL files. Upon applying these files the library will check if the files have already been applied before (by looking into a migrations table in the DB). If they have not yet been applied they will be executed sequantially.

There are already other libraries available for Node that helps you with performing DB migrations, why create a new one? Because I want a library that exists that allows you to write the migration scripts in pure SQL (no need for every function / feature in SQL to get a corresponding translation written in JS). I also want the migrations to be executable from code. This way it's very low effort to making sure that all environments (local / staging / prod) are all being kept up to date.

Is this difficult? I don't know, perhaps it is. We'll find out. At least I'll start and see where I land. This is still a young project, so don't hesitate to report Issues if you find them or to come with suggestion on how this could be done better. As a first step it's expected to support postgres, in later stages there's no reason why functionality can't be extended to support other SQL databases.

Installation

This project is published at npmjs here. You can install it using npm i -S sql-apply.

Execution

This project can both be used from inside nodejs projects by saving it as a dependency and then running runMigrations (don't forget to await the result). It can also be used from the command line through npx sql-apply migrate -m <directory-with-migrations>. Of course additional parameters exist, just run npx sql-apply to see available options.

Limitations

This project currently uses IF NOT EXISTS syntax which means it's only compatible with Postgres 9.1 and upward.

Features

These features are not yet implemented, but the aim is to:

  • Allow project to bootstrap a migrations table on first run.
  • Allow one or multiple target folders to be used for migration scripts
  • Ensuring that scripts are applied in an ordered manner according to naming convention.
  • Migrations scripts will be written in SQL.

For full information please refer to the API Documentation.

Conventions

The project aims at staying true to the flyway project mentioned above. For this the name convention consists of:

  • Prefix: Defaults to V.
  • Version: Dots or underscores separated in as many parts as one likes.
  • Separator: Defaults to __ (two underscores) and separates the version from the description.
  • Description: A text with words separated by underscores or spaces.
  • Suffix: Defaults to .sql.

For example, the following are all valid migration scripts:

  • V1__some_description.sql
  • V15.003__some_other_script.sql

The library will enforce that versions are monotonically increasing starting at 1.

Requirements

  • Node 11 or higher
  • npm
  • Postgres

License

MIT