{"action":"closed","issue":{"url":"https://api.github.com/repos/db-migrate/node-db-migrate/issues/452","repository_url":"https://api.github.com/repos/db-migrate/node-db-migrate","labels_url":"https://api.github.com/repos/db-migrate/node-db-migrate/issues/452/labels{/name}","comments_url":"https://api.github.com/repos/db-migrate/node-db-migrate/issues/452/comments","events_url":"https://api.github.com/repos/db-migrate/node-db-migrate/issues/452/events","html_url":"https://github.com/db-migrate/node-db-migrate/issues/452","id":197577328,"number":452,"title":"Reduce boilerplate code when running migrations from SQL files","user":{"login":"maxsummers","id":24696273,"avatar_url":"https://avatars3.githubusercontent.com/u/24696273?v=4","gravatar_id":"","url":"https://api.github.com/users/maxsummers","html_url":"https://github.com/maxsummers","followers_url":"https://api.github.com/users/maxsummers/followers","following_url":"https://api.github.com/users/maxsummers/following{/other_user}","gists_url":"https://api.github.com/users/maxsummers/gists{/gist_id}","starred_url":"https://api.github.com/users/maxsummers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maxsummers/subscriptions","organizations_url":"https://api.github.com/users/maxsummers/orgs","repos_url":"https://api.github.com/users/maxsummers/repos","events_url":"https://api.github.com/users/maxsummers/events{/privacy}","received_events_url":"https://api.github.com/users/maxsummers/received_events","type":"User","site_admin":false},"labels":[{"id":758937549,"url":"https://api.github.com/repos/db-migrate/node-db-migrate/labels/stale","name":"stale","color":"ffffff","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-12-26T11:20:30Z","updated_at":"2017-11-30T09:43:49Z","closed_at":"2017-11-30T09:43:49Z","author_association":"NONE","body":"When `sql-file` option is used it creates the following migration file:\r\n\r\n```js\r\n'use strict';\r\n\r\nvar dbm;\r\nvar type;\r\nvar seed;\r\nvar fs = require('fs');\r\nvar path = require('path');\r\nvar Promise;\r\n\r\n/**\r\n  * We receive the dbmigrate dependency from dbmigrate initially.\r\n  * This enables us to not have to rely on NODE_PATH.\r\n  */\r\nexports.setup = function(options, seedLink) {\r\n  dbm = options.dbmigrate;\r\n  type = dbm.dataType;\r\n  seed = seedLink;\r\n  Promise = options.Promise;\r\n};\r\n\r\nexports.up = function(db) {\r\n  var filePath = path.join(__dirname, 'sqls', '20161226111110-test-up.sql');\r\n  return new Promise( function( resolve, reject ) {\r\n    fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){\r\n      if (err) return reject(err);\r\n      console.log('received data: ' + data);\r\n\r\n      resolve(data);\r\n    });\r\n  })\r\n  .then(function(data) {\r\n    return db.runSql(data);\r\n  });\r\n};\r\n\r\nexports.down = function(db) {\r\n  var filePath = path.join(__dirname, 'sqls', '20161226111110-test-down.sql');\r\n  return new Promise( function( resolve, reject ) {\r\n    fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){\r\n      if (err) return reject(err);\r\n      console.log('received data: ' + data);\r\n\r\n      resolve(data);\r\n    });\r\n  })\r\n  .then(function(data) {\r\n    return db.runSql(data);\r\n  });\r\n};\r\n\r\nexports._meta = {\r\n  \"version\": 1\r\n};\r\n```\r\n\r\nThis is a huge amount of non-optimized boilerplate code.\r\n\r\nIt's pretty common to have hundreds of migrations in actively developed project. Now, consider this boilerplate multiplied by one hundred. This will increase code base size significantly and will take additional time for IDE to analyze the code and build it's indices.\r\n\r\nPlease, consider to reduce the size of such migration files. I think the only relevant part of it is: `__dirname, 'sqls', '20161226111110-test-down.sql'`, so everything else could be moved to the library code.\r\n\r\n<bountysource-plugin>\r\n---\r\nWant to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/40399864-reduce-boilerplate-code-when-running-migrations-from-sql-files?utm_campaign=plugin&utm_content=tracker%2F73887&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F73887&utm_medium=issues&utm_source=github).\r\n</bountysource-plugin>"}}
{"actor":{"display_login":"stale"}}