0.2.0 โ€ข Published 7 months ago

@ky210299/ez-migrate v0.2.0

Weekly downloads
-
License
ISC
Repository
-
Last release
7 months ago

@ky210299/ez-migrate

A lightweight CLI for database migrations and SQL seedsโ€”designed for simplicity, speed, and reliability.
Perfect for small-to-medium projects that need an easy, zero-boilerplate way to version your schema and seed data.


๐Ÿ“‘ Table of Contents

  1. Installation
  2. Usage
  3. Configuration
  4. Commands
  5. Examples
  6. Environment Variables
  7. Contributing
  8. Author

๐Ÿš€ Installation

# Global install (recommended)
npm install -g @ky210299/ez-migrate

# Local install
npm install @ky210299/ez-migrate

Run via:

# If installed globally:
ez-migrate <command> [options]

# If installed locally:
npx @ky210299/ez-migrate <command> [options]

๐Ÿ”ง Usage

Initialize a minimal config file in your project root:

ez-migrate init [path]

โš™๏ธ Configuration

When you run ez-migrate init, it will generate an ez-migrate.config.json file (and create the migrations/seeds folders if missing).

ez-migrate.config.json

This file defines how database migrations and seeds are managed and executed.

๐Ÿ”น dialect

The database type where migrations will be applied.
Possible values: "mysql", "sqlite" (others may be added in the future).

๐Ÿ”น migrationsPath

Path to the directory where SQL migration files are stored.
Example: "./migrations"

๐Ÿ”น seedsPath

Path to the directory where SQL seed files are stored.
Example: "./seeds"

๐Ÿ”ธ envKeys

Specifies the environment variable names used to connect to the main database.

{
  "user": "DB_USER",         // Database user
  "password": "DB_PASSWORD", // Database password
  "port": "DB_PORT",         // Database port
  "host": "DB_HOST",         // Database host
  "database": "DB_NAME"      // Database name
}

๐Ÿ”ธ tracker

Configuration for the tracker database, used to record which migrations have been applied.

{
  "envKeys": {
    "user": "DB_USER",         
    "password": "DB_PASSWORD",
    "port": "DB_PORT",         
    "host": "DB_HOST",         
    "database": "DB_NAME"      
  },
  "dialect": "mysql",          // or "sqlite"
  "sqlitePath": "./migrations" // only for sqlite tracker
}

๐Ÿ“š Commands

ez-migrate <command> [options]
  • make
    Create a new migration file in migrations/.

    • -s, --seed: create a seed file in seeds/ instead.
  • seed
    Execute all SQL seed files in order.

  • init path
    Generate config file

  • status
    Display applied vs pending migrations.

  • migrate
    Apply all pending migrations.

  • up
    Run the next pending migration.

  • down
    Roll back the most recent migration.

  • rollback
    Revert the last batch of migrations done.

  • reset
    Roll back and apply all migrations

  • redo
    Undo and reapply the last migration.


๐Ÿ’ก Examples

# Create a new migration
ez-migrate make add_users_table

# Create a new seed
ez-migrate make --seed populate_demo_data

# Apply pending migrations
ez-migrate migrate

# Roll back last batch
ez-migrate rollback

# Check current status
ez-migrate status

๐Ÿ”‘ Environment Variables

Make sure you have set your environment variables and are specified in your ez-migrate.json before running any commands. You can use a .env

DB_HOST=localhost
DB_USER=root
DB_PASSWORD=secret
DB_PORT=3306
DB_NAME=my_database

๐Ÿค Contributing

  1. Fork the repo
  2. Create a feature branch (git switch -c feat/my-feature)
  3. Commit your changes (git commit -m '{feat|fix|ref|chore}: Add this ..')
  4. Push to the branch (git push origin feat/my-feature)
  5. Open a Pull Request

๐Ÿ‘ค Author

@ky210299

0.2.0

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago