Pigmig is a postgresql database migration tool with a minimal feature set.
npm install pigmig
Provide a database via the
DATABASE_URLenvironment variable. Pigmig will find it automatically by reading it from
Create migrations and ensure their proper ordering. The easiest way to do this is by using the provided command line tool
npx pigmig.newmig src/db/migrations add_user_table
This creates a
src/db/migrationsthat is prepended with a timestamp, e.g.,
Run migrations. There are two ways to do this, via the cli or programmatically.
pigmig.migrate, passing in the path to your migrations directory.
npx pigmig.migrate src/db/migrations
Programmatically: Include the following line near the top of your
server.[js|ts]file or it's equivalent for your tech stack.
import pigmig from 'pigmig' ... await pigmig.migrate('src/db/migrations')
Pigmig creates a
migrations table if one does not already exist. It verifies the checksums of previously ran migrations. Each time it runs a new migration, it adds a row for it to the
The philosophy behind
pigmig is an "always up" / "no rollbacks" / "no down" migration strategy.