migratify
v2.0.6
Published
**A simple MySQL database migration tool for Node.js projects.**
Readme
Migratify
A simple MySQL database migration tool for Node.js projects.
Migratify helps you manage database schema changes easily through migration files. It allows you to create databases, tables, modify schemas, and migrate changes across environments.
Installation
Install the CLI globally:
npm install -g migratifyInstall inside your project for utility classes:
npm install migratifyFeatures
- Create databases directly from CLI
- Create and update tables using migration files
- Manage schema changes easily
- Foreign key support
- Rollback migrations
- Dump schema and data
- Load migrations from an existing database
- New: Database dispersion tool for syncing development databases
New Feature: Database Dispersion
Migratify now includes a powerful dispersion tool to ship changes from your development database to other databases effortlessly.
Run:
migratify disperseYou can also save database settings to reuse them later.
Note: Migratify must be installed globally to use this feature.
Usage
Create Database
Inside your project directory run:
migratify create-dbYou will be prompted for:
- Database name
- Host
- Username
- Password
After creation, a migrations folder will be generated inside your
project.
All migration files will be stored there.
Create Table
Run:
migratify create-table tablenameA migration file will be created inside the migrations directory.
Example migration file:
const { Table } = require("migratify/Migration.class");
let newTable = new Table("tablename");
module.exports = async () => {
newTable.create();
};Table Methods
Method Description
newTable.setId(idName) Adds an ID column to the table
newTable.addColumn(columnName, dataType) Adds a column with MySQL data type
addColumn(...).setNullable(true) Allows NULL values
addColumn(...).setDefaultValue(value) Sets default value
addColumn(...).setUnique(true) Makes column unique
newTable.addForeignKey(column, refTable, refColumn) Creates a foreign key
Update Table
Run:
migratify update-table tablenameExample migration:
const { Table } = require("../templates/Migration.class")
let newTable = new Table("tablename")
module.exports = async () => {
newTable.update()
}Update Methods
Method Description
renameColumn(oldName, newName) Rename column
removeProperty(columnName) Remove column
addColumn(columnName, dataType) Add new column
addForeignKey(column, refTable, refColumn) Add foreign key
Run Migrations
Apply migration files to the database:
migratify migrateThis will execute all migration files and update the database schema.
Dump Schema
Dump database schema:
migratify dump-schemaDump Data
Dump schema with data:
migratify dump-dataLoad From Existing Database
Generate migration files from an existing database:
migratify load-dbYou will be prompted for database credentials.
Rollback
Undo the latest migration:
migratify rollbackThis will:
- Roll back the migration
- Delete the migration file
Help
View all commands:
migratify helpGit Ignore
Add the following files to .gitignore:
logs.json
config.txtRepository
GitHub Repo:
https://github.com/shahriarKabir44/migratify
