Registry / database / migy
library0.1.5jsnpmunverified

Easy migration tool for MySQL, Postgres, and SQLite databases. Current version 0.1.5. Migy offers a simple SQL-file-based migration system with rollback support, migration hashing for integrity verification, and works both as a standalone CLI and as part of an application. It supports popular database adapters (mysql2, postgres, sqlite3) and can be extended with custom adapters. Migrations are stored as .sql files with IDE-friendly syntax highlighting and support multiple queries per migration. Compared to alternatives like knex or db-migrate, migy is minimal and SQL-centric, without requiring a migration DSL or JavaScript-based migration definitions.

npm install migy
INSTALL
IMPORT
SIG · MIGY
M
migy
databasejavascriptv0.1.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

migy
const migy = require('migy')
import migy from 'migy'
Package uses CommonJS; ESM import is not supported.
migy.init
const migrator = await migy.init({db, adapter, dir})
const migrator = migy.init({db, adapter, dir})
migy.init is async and returns a promise.
migy.cli
migy.cli({db, adapter, dir})
migy.cli({db, adapter, dir, store})
store is optional but common, no major wrong usage except missing async handling.
migrate
await migrator.migrate()
migrator.migrate()
migrate() is async, must be awaited.

Shows how to set up migy as a standalone CLI tool with MySQL2.

const migy = require('migy'); const mysql = require('mysql2'); const conn = mysql.createConnection({ host: 'localhost', user: 'user', password: process.env.DB_PASSWORD ?? '', database: 'things' }); migy.cli({ db: conn, adapter: 'mysql2', dir: 'migrations' });
Debug
Known issues
gotchaMigrations must start with digits (e.g., 1.sql or 001_create_table.sql).
fix
Rename migration files to start with a number.
affects: >=0.0.0
gotchaMultiple queries in one migration must be separated by ### on a blank line.
fix
Use ### separator without surrounding quotes.
affects: >=0.0.0
gotchaRollback queries must be separated by ### DOWN or ### ROLLBACK on a blank line.
fix
Use ### DOWN or ### ROLLBACK as a separate line.
affects: >=0.0.0
breakingmigy.init is async and returns a promise object. Calling it without await will cause TypeError.
fix
Use await migy.init() or .then().
affects: >=0.1.0
gotchaAdapters are case-sensitive; 'mysql2' not 'MySQL2' or 'Mysql2'.
fix
Use 'mysql2', 'postgres', or 'sqlite3' exactly.
affects: >=0.0.0
deprecatedCustom adapter functions replace string adapter names in future versions.
fix
Consider using custom adapter functions if extending.
affects: >=0.1.5
Errors
Common errors & fixes
TypeError: migy.init is not a function
migy is imported incorrectly (e.g., ESM default import).
fix
Use const migy = require('migy') (CommonJS).
Error: Cannot find module 'mysql2'
Required database adapter not installed.
fix
Run npm install mysql2 (or pg, sqlite3) in the project.
Error: Migration directory 'migrations' does not exist
Specified directory for migration files doesn't exist.
fix
Create the directory and place .sql files inside.
Error: Migration file 'abc.sql' doesn't start with digits.
Migration filename does not start with a number.
fix
Rename file to start with digits (e.g., '01_abc.sql').
Error: Cannot find migration store 'migrations'
Database table for migration tracking does not exist.
fix
First migration run will create it automatically; ensure permissions.
Upgrade
Version history
0.1.5latest on npm
Audit
Dependencies
mysql2optionalAdapter for MySQL/MariaDB databases
pgoptionalAdapter for PostgreSQL databases
sqlite3optionalAdapter for SQLite databases
Agent activity
9 hits · last 30 days
node
8
Resources
packagemigy
migy — npm install migy · libregistry