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

guzu

v0.0.8

Published

Database migration manager for PosgreSQL

Downloads

11

Readme

guzu

guzu is a database migration tool, inspired by goose. Guzu means goose in Japanese.

Project goals:

  • No configuration files
  • SQL only migrations
  • Timestamped migrations
  • Immutable migrations once applied

Install

npm install guzu --save-dev

Usage

Options

All the commands require a data source name and a migrations directory where the migration files are located. You can pass these values as command line arguments or as environment variables.

The default value for the migrations directory is . (i.e. the current directory).

Command line arguments:

  • --dsn: The data source name. (e.g. postgres://admin:password@localhost:5432)
  • --dir: The migrations directory. (e.g. ./migrations)

Environment variables:

  • GUZU_DSN: The data source name. (e.g. postgres://admin:password@localhost:5432)
  • GUZU_DIR: The migrations directory. (e.g. ./migrations)

create

Create a new SQL migration:

npx guzu create <name>

status

Print the status of all migrations:

npx guzu status

up

Apply all pending migrations:

npx guzu up

up-by-one

Apply the next pending migration:

npx guzu up-by-one

down

Roll back the last applied migration:

npx guzu down

redo

Roll back the last migration and re-apply it.

npx guzu redo

Use this command when you are working on a new migration and you need to iterate on it. It will roll back the last migration and re-apply it even if the hash of the migration file has changed.

This command will ignore hash mismatches and should only be used during development.

seed

Seed the database with the migrations without applying them:

npx guzu seed

Use this command if you are migrating from another database migration tool and you want to seed the database with the migrations without applying them.

Migrations

sqlmigrations only supports migrations written in SQL.

A sample SQL migration looks like this:

-- +guzu up
CREATE TABLE users (
	id SERIAL PRIMARY KEY,
	name text NOT NULL
);

-- +guzu down
DROP TABLE users;

Each migration file must have a -- +guzu up annotation. The -- +guzu down annotation is optional. If a file has both annotations, the -- +guzu up annotation must come first.

By default, all migrations are run within a transaction. You can disable this by adding a -- +guzu NO TRANSACTION annotation.

Development

You can run the CLI using npm start:

npm start -- <command>

For a fast development cycle, you should sping up a PostgreSQL database and set both the GUZU_DSN and GUZU_DIR environment variables. You can use the integration test setup for that.

Start the database:

npm run db:up

Set the environment variables:

export GUZU_DSN=postgres://admin:password@localhost:5432
export GUZU_DIR=./integration/migrations/base

You can reset the database with:

npm run db:reset

A VSCode launch configuration with these settings is provided for debugging.

Unit tests

Run the tests:

npm test

Integration tests

The integration tests require Docker, we run a PostgreSQL database in a container. You can start the database with:

npm run db:up

The database will be available at postgres://admin:password@localhost:5432.

Run the integration tests:

npm run test:integration

Publishing a new release

  1. Bump the package version: npm version <major|minor|patch>
  2. Push the new version: git push --follow-tags
  3. Create a new release: gh release create