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 🙏

© 2026 – Pkg Stats / Ryan Hefner

migrilla

v1.0.2

Published

Simple PostgreSQL migration tool for Node.js with atomic transactions and beautiful CLI

Readme

🦍 Migrilla

npm version npm downloads Node.js Version License: MIT

Simple PostgreSQL migration tool for Node.js applications.

🇷🇺 Русская версия | 🇺🇸 English version

🚀 Quick Start Guide - Get started in under 5 minutes!

🚀 Installation

npm install migrilla

⚙️ Usage

Commands

migrilla up      # Apply all pending migrations
migrilla down    # Rollback the last applied migration
migrilla status  # Show migration status
migrilla help    # Show help message

Environment Variables

Configure database connection using environment variables:

MIGRILLA_DB_HOST=localhost           # Database host (default: localhost)
MIGRILLA_DB_PORT=5432               # Database port (default: 5432)
MIGRILLA_DB_NAME=myapp              # Database name (default: postgres)
MIGRILLA_DB_USER=postgres           # Database user (default: postgres)
MIGRILLA_DB_PASSWORD=mypassword     # Database password
MIGRILLA_DATABASE_URL=postgres://user:pass@host:port/db  # Full connection string
MIGRILLA_DB_SSL=true                # Use SSL connection (default: false)

💾 How It Works

✅ Reads SQL files from migrations/ directory
✅ Tracks applied migrations in migrilla_state table
Atomic execution - each migration runs in a transaction
✅ Provides beautiful console output
✅ Handles errors gracefully

🦍 Migration Files

Create migration files in the migrations/ directory:

File Naming Pattern

001_migration_name_up.sql    # Apply migration
001_migration_name_down.sql  # Rollback migration

Example Structure

migrations/
├── 001_add_users_table_up.sql
├── 001_add_users_table_down.sql
├── 002_add_orders_table_up.sql
├── 002_add_orders_table_down.sql
└── 003_add_indexes_up.sql
└── 003_add_indexes_down.sql

📚 Examples

Example Migration Files

001_add_users_table_up.sql

CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  email VARCHAR(255) UNIQUE NOT NULL,
  name VARCHAR(255) NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

001_add_users_table_down.sql

DROP TABLE IF EXISTS users;

002_add_orders_table_up.sql

CREATE TABLE orders (
  id SERIAL PRIMARY KEY,
  user_id INTEGER REFERENCES users(id),
  amount DECIMAL(10,2) NOT NULL,
  status VARCHAR(50) DEFAULT 'pending',
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

002_add_orders_table_down.sql

DROP TABLE IF EXISTS orders;

Running Migrations

# Apply all pending migrations
migrilla up

# Check migration status
migrilla status

# Rollback last migration
migrilla down

Example Output

$ migrilla up
✅ Migrilla initialized successfully
🔄 Applying migration: 001_add_users_table
✅ Executed: 001_add_users_table
🔄 Applying migration: 002_add_orders_table
✅ Executed: 002_add_orders_table
🎉 All migrations applied successfully!

$ migrilla status

📊 Migration Status:
==================
✅ Applied | 001_add_users_table
✅ Applied | 002_add_orders_table
⏳ Pending | 003_add_indexes

📈 Summary:
Total migrations: 3
Applied: 2
Pending: 1

$ migrilla down
✅ Migrilla initialized successfully
🔄 Rolling back migration: 002_add_orders_table
✅ Executed: 002_add_orders_table
✅ Migration rolled back successfully!

🔧 Programmatic Usage

You can also use Migrilla programmatically with functional approach:

const createMigrilla = require('migrilla');

const migrilla = createMigrilla({
  host: 'localhost',
  port: 5432,
  database: 'myapp',
  user: 'postgres',
  password: 'password'
});

// Apply migrations
await migrilla.up();

// Rollback last migration
await migrilla.down();

// Get status
await migrilla.status();

// Close connection
await migrilla.close();

Why Functions Instead of Classes?

  • Immutable Configuration: Configuration is closed over by functions
  • No State Mutations: More predictable and testable code
  • Better Performance: Reduced object instantiation overhead
  • Functional Style: Clean separation of concerns

Manual Transaction Control

You can also execute custom operations within transactions:

// Transaction API with automatic management
await migrilla.executeInTransaction(async (client) => {
  await client.query('INSERT INTO users (name) VALUES ($1)', ['John']);
  await client.query('UPDATE users SET active = true WHERE name = $1', ['John']);
});

🛠️ Configuration Options

const migrilla = new Migrilla({
  // Database connection options (pg Pool options)
  host: 'localhost',
  port: 5432,
  database: 'myapp',
  user: 'postgres',
  password: 'password',
  
  // Migrilla specific options
  migrationsDir: './migrations',    // Directory with migration files
  stateTable: 'migrilla_state'      // Table name for tracking migrations
});

🔒 Transaction Safety

Migrilla ensures atomic execution of migrations:

  • Each migration runs in a transaction
  • If any part of the migration fails, everything is rolled back
  • Migration state is updated only after successful execution
  • No partial migrations or inconsistent state

This means your database will always be in a consistent state, even if a migration fails halfway through.

📖 Read the complete Transaction Guide for detailed information about transaction handling.

📋 See API Reference for complete method documentation.

🚀 View all Features for a comprehensive overview of capabilities.

📝 Requirements

  • Node.js 18.0.0 or higher
  • PostgreSQL database
  • Migration files in migrations/ directory

🧪 Testing

# Run basic tests
npm test

🎉 Key Benefits

  • Zero Dependencies (except pg module)
  • No Configuration Required (works with defaults)
  • Production Ready (atomic operations)
  • Developer Friendly (beautiful output)
  • Extensible (programmatic API)
  • Transaction Safe (automatic rollback on errors)

📁 Project Structure

📖 See PROJECT_STRUCTURE.md for detailed information about project organization and file descriptions.

📊 View PROJECT SUMMARY for a complete overview of achievements and implementation details.

🔄 Check MIGRATION GUIDE for upgrading between versions.

🤝 Contributing

Issues and pull requests are welcome!

📄 License

MIT