migratify

1.0.27 • Public • Published

Node.Js Mysql Migration tool

A simple Mysql migration tool than you can integrate in your project to perform database migration.

How to use:

  1. type npm i -g migratify (for CLI)
  2. type npm i migratify (inside your project directory for utility classes)
  3. That's it

Features

Create database:

Go to your project directory and type
migratify create-db This will ask you for your database name, password, user, host etc. Type the answers accordingly. And it will create a database for you. And inside your project directory, it will create a folder called "migrations". This is where your migration files will be stored.

Create table:

Go to your project directory and type migratify create-table tablename . This will create a migration file in the migrations directory. Replace the tablename argument with the name of the table you want to create. Open the newly created file in your code editor. It will look something like this:
const { Table } = require('migratify/Migration.class') let newTable =new Table("tablename") module.exports = async () => { newTable.create() }

Here is a list of methods that you can use to add properties in your table:

Method Description
newTable.setId(idName) Adds an ID property of that table. The parameter is a string. The name of the ID column
newTable.addColumn(columnName,dataType) Adds a column named "columnName" with type "dataType". The data types are MySQL data type.
newTable.addColumn(columnName,dataType).setNullable(true) Makes the column NOT NULL
newTable.addColumn(columnName,dataType).setDefaultValue(defaultValue) Sets the default value to a certain value.
newTable.addColumn(columnName,dataType).setUnique(true) Sets the default value to a certain value.
newTable.addForeignKey(columnName, refTable, refColumn) Sets a foreign key to column name that refers to refColumn column from the refTable table

Update table:

Go to your project directory and type migratify update-table tablename . This will create a migration file in the migrations directory. Replace the tablename argument with the name of the table you want to create. Open the newly created file in your code editor. It will look something like this:
const { Table } = require('../templates/Migration.class') let newTable = new Table("tablename") module.exports = async () => { newTable.update() }

Here is a list of methods that you can use to update your table:

Method Description
newTable.renameColumn(oldName, newName) Renames the column from oldName to newName
newTable.removeProperty(columnName) Removes a column named columnName
newTable.addColumn(columnName,dataType) Described earlier
newTable.addForeignKey(columnName, refTable, refColumn) Sets a foreign key to column name that refers to refColumn column from the refTable table
renameColumn(oldName, newName) Renames a column to a new name

Migrate:

To commit the changes to the database, run the following command: Type migratify migrate

This will run all the migration files and update the database schema.

Dump schema

To dump the schema of the database, run the command migratify dump-data.

Dump Data

To dump the schema of the database along with its data, run the command migratify dump-data.

Load from existing database:

To create migration files from an existing database, type the command on the terminal migratify load-db. This will ask the user for database name, password etc.

Rollback:

To undo the effect of the latest commit file, type the command on the terminal migratify rollback. Not only that it will roll back, it will also delete the migration file.

Help:

To see the list of commands, Type migratify help

Note:

Please add the logs.txt and config.txt to your project's .gitignore file.

Github Repo

Readme

Keywords

Package Sidebar

Install

npm i migratify

Weekly Downloads

3

Version

1.0.27

License

ISC

Unpacked Size

40.5 kB

Total Files

17

Last publish

Collaborators

  • shahriarkabir