{"id":43305,"library":"mysql-migrator","title":"mysql-migrator","description":"mysql-migrator is an npm package for managing MySQL/MariaDB database migrations and data seeding in Node.js projects, currently at version 2.0.0. It provides a simple CLI-like interface to create and run migration and seeding files with built-in rollback support. Key differentiators include support for both ES6 and CommonJS module systems, a straightforward API using a Migrator class, and built-in table creation/drop helpers via the tbl object. The package is actively maintained and integrates directly with npm scripts for ease of use.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/helloakn/mysql-migrator","tags":["javascript","mysql-migrations","migrations","seedings","nodejs-migration","mysql-migration"],"install":[{"cmd":"npm install mysql-migrator","lang":"bash","label":"npm"},{"cmd":"yarn add mysql-migrator","lang":"bash","label":"yarn"},{"cmd":"pnpm add mysql-migrator","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"MySQL driver required for database connection","package":"mysql2","optional":false}],"imports":[{"note":"Named export in ESM; CommonJS uses destructured require.","wrong":"const Migrator = require('mysql-migrator')","symbol":"Migrator","correct":"import { Migrator } from 'mysql-migrator'"},{"note":"Utility function for logging migration results.","wrong":"const Output = require('mysql-migrator')","symbol":"Output","correct":"import { Output } from 'mysql-migrator'"},{"note":"tbl is an object passed to migration functions for table operations.","wrong":"Using tbl without passing it as parameter to up/rollback","symbol":"tbl","correct":"module.exports = { up: async (tbl) => { ... } }"},{"note":"query is a function passed to seeding functions for raw SQL queries.","wrong":"Using query without passing it to seeding functions","symbol":"query","correct":"module.exports = { up: async (query) => { ... } }"}],"quickstart":{"code":"// Install: npm install mysql-migrator\n// Initialize migrator.js:\nimport { Migrator, Output } from 'mysql-migrator';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nconst dbConfig = {\n  host: 'localhost',\n  user: process.env.DB_USER ?? 'root',\n  port: 3306,\n  password: process.env.DB_PASSWORD ?? '',\n  database: process.env.DB_NAME ?? 'mydb'\n};\nconst migrationsPath = __dirname + '/migrations';\nconst migrator = new Migrator(dbConfig, migrationsPath);\nconst result = await migrator.init();\nOutput(result);\nprocess.exit();\n\n// Create migration: node migrator.js migration:create create_table_user\n// Create migration file: exports.up = async (tbl) => { await tbl.create('users', { id: 'int NOT NULL AUTO_INCREMENT', name: 'varchar(255) NOT NULL' }); };\n// Run up: node migrator.js migration:up\n// Rollback: node migrator.js migration:rollback","lang":"javascript","description":"Sets up a migrator instance, creates a migration, runs it up, and rolls back."},"warnings":[{"fix":"Use module.exports = { up: async (tbl) => { ... } } in migration files.","message":"Migration and seeding files must be CommonJS (module.exports) even if the app is ESM.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Update to new Migrator({ host, user, password, database }, migrationsPath) syntax.","message":"Version 2.0.0 changed the API: Migrator constructor now requires a config object instead of separate parameters.","severity":"breaking","affected_versions":"2.0.0"},{"fix":"Change exports.up to module.exports = { up: ... }","message":"The old migration file format using exports.up is deprecated in favor of module.exports.","severity":"deprecated","affected_versions":">=1.0.0 <2.0.0"},{"fix":"Run rollback multiple times to revert multiple batches.","message":"Rollback will only revert the most recent batch of migrations, not individual ones.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"search_vec":"'2.0.0':25 'activ':80 'api':61 'built':44,68 'built-in':43,67 'class':65 'cli':31 'cli-lik':30 'commonj':56 'creat':35 'creation/drop':71 'current':22 'data':17 'databas':14 'differenti':49 'direct':84 'eas':89 'es6':54 'file':41 'helper':72 'includ':50 'integr':83 'interfac':33 'javascript':92 'key':48 'like':32 'maintain':81 'manag':12 'migrat':3,6,15,38,64,95,96,100,103 'modul':57 'mysql':2,5,94,102 'mysql-migr':1,4,93,101 'mysql/mariadb':13 'node.js':20 'nodej':99 'nodejs-migr':98 'npm':9,86 'object':76 'packag':10,78 'project':21 'provid':27 'rollback':46 'run':37 'script':87 'seed':18,40,97 'simpl':29 'straightforward':60 'support':47,51 'system':58 'tabl':70 'tbl':75 'use':62,91 'version':24 'via':73","created_at":"2026-06-05T16:59:10.004518+00:00","updated_at":"2026-06-05T16:59:10.004518+00:00","problems":[{"fix":"Run 'npm install mysql-migrator' and ensure import statements match the module system.","cause":"Package not installed or import path incorrect","error":"Cannot find module 'mysql-migrator'"},{"fix":"Use import { Migrator } from 'mysql-migrator' for ESM or const { Migrator } = require('mysql-migrator') for CJS.","cause":"Using require incorrectly for ESM build","error":"Migrator is not a constructor"},{"fix":"Ensure up/rollback function signature is async (tbl) => { ... }","cause":"Migration file uses tbl without receiving it as parameter","error":"Cannot read properties of undefined (reading 'create')"},{"fix":"Check DB_USER, DB_PASSWORD, host, and port in dbConfig.","cause":"Database credentials are incorrect or insufficient privileges","error":"Access denied for user 'user'@'host'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/helloakn/mysql-migrator#readme","github":"https://github.com/helloakn/mysql-migrator","docs":null,"changelog":null,"pypi":null,"npm":"mysql-migrator","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}