0.4.12 • Published 5 months ago

migrationjs v0.4.12

Weekly downloads
34
License
ISC
Repository
github
Last release
5 months ago

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

0.4.9

5 months ago

0.4.8

5 months ago

0.4.10

5 months ago

0.4.11

5 months ago

0.4.12

5 months ago

0.4.7

6 months ago

0.4.6

6 months ago

0.4.5

6 months ago

0.4.4

8 months ago

0.3.101

11 months ago

0.3.100

11 months ago

0.3.103

11 months ago

0.3.102

11 months ago

0.3.105

11 months ago

0.3.104

11 months ago

0.3.106

11 months ago

0.4.1

11 months ago

0.4.0

11 months ago

0.4.3

9 months ago

0.4.2

9 months ago

0.3.31

1 year ago

0.3.30

1 year ago

0.3.32

1 year ago

0.3.29

1 year ago

0.3.28

1 year ago

0.3.27

1 year ago

0.3.26

1 year ago

0.3.25

1 year ago

0.3.24

2 years ago

0.3.23

2 years ago

0.3.22

2 years ago

0.3.21

3 years ago

0.3.20

3 years ago

0.3.19

3 years ago

0.3.18

3 years ago

0.3.17

3 years ago

0.3.16

3 years ago

0.3.15

3 years ago

0.3.14

3 years ago

0.3.13

3 years ago

0.3.12

3 years ago

0.3.11

3 years ago

0.3.9

3 years ago

0.3.10

3 years ago

0.3.8

3 years ago

0.3.7

3 years ago

0.3.6

3 years ago

0.3.5

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.17

4 years ago

0.1.18

4 years ago

0.2.2

4 years ago

0.1.16

4 years ago

0.1.15

4 years ago

0.1.14

4 years ago

0.1.13

4 years ago

0.1.11

4 years ago

0.1.12

4 years ago

0.1.10

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago