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

migrationjs

v0.4.12

Published

migration system for js

Downloads

28

Readme

MigrationJS

MigrationJS is a database migration package for NodeJS. MigrationJS allows you to create migrations for your database and run them in a specific order. This way it is easy to introduce database changes to you application at ease.

Installation

npm i -g migrationjs

Commands

Commands are composed like this: migrationjs <command> <args>
The available commands are:

help
Gets a list of all the commands

migrate
This makes a new batch of all the migrations which did not run yet and executes the up function of those migrations.

rollback
This command executes the down function of the migrations of the latest batch.

make:migration <migration name>
This command creates a migration file. The name has to start with create if you want to generate a create-table migration template, or alter for an alter-table migration template

make:config
This command creates a migrationjs.conf.json file where you can configure your settings of MigrationJS.

Migration file

A migration file is a file which contains two functions: up and down. The up function is executed when you run migrationjs migrate and the down function is executed when you run migrationjs rollback. In those methods you may use the Schema object to create tables, alter tables, drop tables, etc. one example is shown below.

import {Migration, Blueprint, Schema} from 'migrationjs';


export default class CreateTestTable extends Migration {

    async up() {
        await Schema.create('test', (table: Blueprint) => {
            table.id();
            table.string('name');
        });
    }

    async down() {
        await Schema.dropIfExists('test');
    }
}

To run the created migration you have to run migrationjs migrate in the terminal. This will create a new batch of migrations and execute the up function of the created migration. To rollback the created migration you have to run migrationjs rollback in the terminal. This will execute the down function of the created migration.

Table functions

Create tables

To create a table you have to use the Schema.create function. This function takes two arguments: the name of the table and a callback function which takes a Blueprint object as argument. The Blueprint object contains all the functions to create a table.

await Schema.create('users', (table: Blueprint) => {
    table.id();
    table.string('name');
});
Updating tables

To update a table you have to use the Schema.table function. This function takes two arguments: the name of the table and a callback function which takes a Blueprint object as argument. The Blueprint object contains all the functions to update a table.

await Schema.table('users', (table: Blueprint) => {
    table.string('username');
});
Renaming / Dropping tables

To rename a table you have to use the Schema.rename function. This function takes two arguments: the name of the table and the new name of the table.

await Schema.rename(from: string, to: string);

To drop an existing table you have to use the Schema.drop function. This function takes one argument: the name of the table.

await Schema.dropIfExists('users'); 

Contributors