{"id":48415,"library":"loopback-component-migration","title":"loopback-component-migration","description":"A database migration component for LoopBack 3.x projects. Version 1.0.3, last updated in 2019. Adds simple migration support similar to node-db-migrate, with REST endpoints for migrate/rollback. Tracks run migrations in a 'Migrations' table. Lightweight alternative to loopback-migration with fewer features but direct datasource access.","status":"maintenance","version":"1.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/coloseo/loopback-component-migration","tags":["javascript","loopback","strongloop","migrate"],"install":[{"cmd":"npm install loopback-component-migration","lang":"bash","label":"npm"},{"cmd":"yarn add loopback-component-migration","lang":"bash","label":"yarn"},{"cmd":"pnpm add loopback-component-migration","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for LoopBack 3.x integration","package":"loopback","optional":false}],"imports":[{"note":"Model is auto-registered on the app; access via app.models.Migration.","wrong":"const Migration = require('loopback-component-migration');","symbol":"Migration model","correct":"const Migration = app.models.Migration;"},{"note":"Configuration done via component-config.json, not direct require.","wrong":"// Trying to require component directly\nconst migration = require('loopback-component-migration');","symbol":"Migration options","correct":"// in component-config.json\n{\n  \"loopback-component-migration\": {\n    \"migrationsDir\": \"./path\",\n    \"dataSource\": \"myDB\",\n    \"enableRest\": true\n  }\n}"},{"note":"Must call next() callback to signal completion; asynchronous scripts require next().","wrong":"module.exports = {\n  up: (app) => { /* ... */ },\n  down: (app) => { /* ... */ }\n};","symbol":"Migration script","correct":"module.exports = {\n  up: function(app, next) { /* ... */ next(); },\n  down: function(app, next) { /* ... */ next(); }\n};"}],"quickstart":{"code":"// server/component-config.json\n{\n  \"loopback-component-migration\": {\n    \"migrationsDir\": \"./server/migrations\",\n    \"dataSource\": \"db\",\n    \"enableRest\": true\n  }\n}\n\n// server/migrations/001-initial.js\nmodule.exports = {\n  up: function(app, next) {\n    var ds = app.dataSources.db;\n    ds.automigrate('MyModel', function(err) {\n      if (err) return next(err);\n      ds.autoupdate('MyModel', function(err) {\n        next(err);\n      });\n    });\n  },\n  down: function(app, next) {\n    app.dataSources.db.automigrate('MyModel', function(err) {\n      next(err);\n    });\n  }\n};\n\n// Running migrations from boot script or manually\napp.models.Migration.migrate('up', '', function(err) {\n  if (err) console.error(err);\n  else console.log('Migrations complete.');\n});","lang":"javascript","description":"Configure the migration component in component-config.json, define a migration script, and run all pending migrations."},"warnings":[{"fix":"Use loopback >=3.1.1 as peer dependency.","message":"loopback-component-migration only supports LoopBack 3.x, not 2.x or 4.x.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Consider alternatives like loopback-migration or migrate directly with a database library.","message":"This package is not actively maintained; last release in 2019.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Always pass a string for the second argument: Migration.migrate('down', '', callback).","message":"Migrate.down with empty string rolls back all migrations; the second parameter cannot be omitted.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure every 'up' and 'down' function invokes next(err) exactly once.","message":"Migration scripts must call next() to proceed; forgetting to call next() will hang the migration process.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Keep enableRest false in production; run migrations programmatically or from a CLI.","message":"REST API for migrations (enableRest) is considered a security risk in production.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.3':15 '2019':19 '3':11 'access':54 'add':20 'altern':43 'compon':3,8 'databas':6 'datasourc':53 'db':28 'direct':52 'endpoint':32 'featur':50 'fewer':49 'javascript':55 'last':16 'lightweight':42 'loopback':2,10,46,56 'loopback-component-migr':1 'loopback-migr':45 'migrat':4,7,22,29,37,40,47,58 'migrate/rollback':34 'node':27 'node-db-migr':26 'project':13 'rest':31 'run':36 'similar':24 'simpl':21 'strongloop':57 'support':23 'tabl':41 'track':35 'updat':17 'version':14 'x':12","created_at":"2026-06-07T16:56:32.109466+00:00","updated_at":"2026-06-07T16:56:32.109466+00:00","problems":[{"fix":"Run: npm install --save loopback-component-migration","cause":"Package not installed or not listed in dependencies.","error":"Cannot find module 'loopback-component-migration'"},{"fix":"Ensure component-config.json has valid JSON and the component object is correct: {\"loopback-component-migration\": {}}","cause":"Migration model not registered yet; component-config.json might be misconfigured or not loaded.","error":"TypeError: app.models.Migration.migrate is not a function"},{"fix":"Create the migrations directory or set a custom path in component-config.json with \"migrationsDir\":\"path/to/migrations\".","cause":"Default migrationsDir does not exist.","error":"ENOENT: no such file or directory, open '.../migrations'"},{"fix":"Ensure you call next() only once, typically at the end of the operation.","cause":"Migration script called next() multiple times in up/down function.","error":"Error: Callback was already called"}],"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/coloseo/loopback-component-migration","github":"https://github.com/coloseo/loopback-component-migration","docs":null,"changelog":null,"pypi":null,"npm":"loopback-component-migration","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}}