{"id":48634,"library":"mysql-migration-promise","title":"mysql-migration-promise","description":"A promise-based MySQL migration utility for Node.js, version 0.3.1. It provides a simple API to run SQL migration scripts automatically on application startup. The package enforces a naming convention (V<version>__<name>.sql) and supports single or multiple statements per file depending on connection settings. Compared to alternatives like db-migrate or knex, it is minimal and focused, but lacks CLI tools, rollback support, and active maintenance.","status":"active","version":"0.3.1","language":"javascript","source_language":"en","source_url":"https://github.com/bvangelov/node-mysql-migration","tags":["javascript","nodejs","mysql","mysql-migration","migration"],"install":[{"cmd":"npm install mysql-migration-promise","lang":"bash","label":"npm"},{"cmd":"yarn add mysql-migration-promise","lang":"bash","label":"yarn"},{"cmd":"pnpm add mysql-migration-promise","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for database connections; the library depends on the mysql2 API for creating connections and querying.","package":"mysql2","optional":false}],"imports":[{"note":"Package is CommonJS-only; ESM import will fail. Use require() or dynamic import.","wrong":"import mysqlMigration from 'mysql-migration-promise';","symbol":"default","correct":"const mysqlMigration = require('mysql-migration-promise');"},{"note":"init() is async and returns a promise; must be awaited or used with .then().","wrong":"mysqlMigration.init(connection, './migrations');","symbol":"init","correct":"const migrationService = await mysqlMigration.init(connection, './migrations');"},{"note":"migrate() is async and returns a promise; must be awaited.","wrong":"migrationService.migrate();","symbol":"migrate","correct":"await migrationService.migrate();"}],"quickstart":{"code":"const mysql = require('mysql2');\nconst mysqlMigration = require('mysql-migration-promise');\n\nasync function runMigrations() {\n  const connection = mysql.createConnection({\n    host: 'localhost',\n    user: 'root',\n    password: 'root',\n    database: 'mydb',\n    multipleStatements: true\n  });\n\n  const migrationService = await mysqlMigration.init(connection, './migrations');\n  await migrationService.migrate();\n  console.log('Migrations completed successfully.');\n  connection.end();\n}\n\nrunMigrations().catch(err => console.error(err));","lang":"javascript","description":"Initializes a MySQL connection, runs migrations from the ./migrations folder, and closes the connection."},"warnings":[{"fix":"Either enable multipleStatements: true in the connection config, or split migration scripts into separate files with single statements.","message":"Multiple SQL statements in a single migration file are not supported unless multipleStatements option is enabled in the MySQL connection.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Rename migration files to match the required pattern.","message":"Migration files must follow the naming convention V<version>__<name>.sql (e.g., V1__init.sql). Files that do not match are ignored.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use __dirname + '/migrations' to ensure the path is relative to the calling file.","message":"The init() function expects an absolute or relative path to the migrations folder. If relative, it is resolved from the current working directory, not the module's location.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Manually revert changes or use a more feature-rich migration tool if rollback is needed.","message":"There is no rollback or undo functionality; migrations are only applied forward.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'0.3.1':15 'activ':71 'altern':52 'api':20 'applic':28 'automat':26 'base':8 'cli':66 'compar':50 'connect':48 'convent':35 'db':55 'db-migrat':54 'depend':46 'enforc':32 'file':45 'focus':63 'javascript':73 'knex':58 'lack':65 'like':53 'mainten':72 'migrat':3,10,24,56,78,79 'minim':61 'multipl':42 'mysql':2,9,75,77 'mysql-migr':76 'mysql-migration-promis':1 'name':34 'node.js':13 'nodej':74 'packag':31 'per':44 'promis':4,7 'promise-bas':6 'provid':17 'rollback':68 'run':22 'script':25 'set':49 'simpl':19 'singl':40 'sql':23,37 'startup':29 'statement':43 'support':39,69 'tool':67 'util':11 'v':36 'version':14","created_at":"2026-06-07T16:57:38.656344+00:00","updated_at":"2026-06-07T16:57:38.656344+00:00","problems":[{"fix":"Run: npm install mysql-migration-promise","cause":"The package is not installed or require path is incorrect.","error":"Cannot find module 'mysql-migration-promise'"},{"fix":"Use: const mysqlMigration = require('mysql-migration-promise');","cause":"The import method does not match the module export (e.g., using ES6 import when module uses CommonJS).","error":"Error: init is not a function"},{"fix":"Rename the file to something like V1__init.sql.","cause":"The migration file name is not in the required format.","error":"Error: Migration file name does not match pattern V<version>__<name>.sql"}],"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/bvangelov/node-mysql-migration#readme","github":"https://github.com/bvangelov/node-mysql-migration","docs":null,"changelog":null,"pypi":null,"npm":"mysql-migration-promise","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-07","next_check":"2026-09-05","install_tag":null}}