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

migrator

v0.1.4

Published

Take your datas and migrate them

Downloads

1,148

Readme

Have you ever been building an application and want to track your schema modifications in a meaningful and incremental fashion? Of course you have, we all have! I, for one, had an application that I ported from Rails to express.js and one of the big things I missed was the migrations. I haven't yet ported the "rollbacks", because I didn't use them. Also I didn't port over the abstraction layer because, well people should learn SQL especially when it comes to defining schema.

So what does migrator do?

migrator will process a directory of migrations, aptly named "./migrations", that are a mix of SQL and JS files and process them in ascending order, skipping over ones that have already been processed. Essentially it allows you to have a uniform way of migrating schema and data in a repeatable and dependable fashion. It comes with a executable "migrator" that assumes the following conventions:

  • You are executing it in the application root which has a directory "migrations" and a file "config.js" in it. The config file has (at least) the following format (note: if you are using mysql, swap 'postgresql' attribute for 'mysql'):
  • You define your current operating environment as the "NODE_ENV" environment variable.

If those conventions are hip to you then just install migrator using

and run it in the following fashion

and you are off migrating. If you don't like those conventions, configure them! The package exports a function "migrate" that you can use in the following manner:

For now the options hash just allows you to change the configured editor, it must be a path to the editor for auto opening new migration files. If you don't provide one, it uses your defined "EDITOR" environment variable.

If you opt for the configuration route, it's generally good to wrap it in an executable script and use it in similar manner to how you use the convention-based migrator.

How do I make migrations?

To create a migration, you can just use

OR

That will create a new file with the current timestamp as an integer with the extension .sql and open in the defined editor as described above OR the default environment variable EDITOR (run echo $EDITOR to find out what this is for your system).

If you want to migrate data, create a JS migration using

OR

and it will open a new file (similar format) with the extension .js with the necessary boilerplate to allow for the DB object to be passed in. If you do use the JS one, be sure to execute the callback parameter once all operations are done with a simple callback().

Q&A

You got questions, I got answers (sometimes) - ping me on twitter @voodootikigod. If you like this, go out and do something awesome with it, I got your back (but not rollback, at least not yet).