{"action":"closed","issue":{"url":"https://api.github.com/repos/db-migrate/node-db-migrate/issues/248","labels_url":"https://api.github.com/repos/db-migrate/node-db-migrate/issues/248/labels{/name}","comments_url":"https://api.github.com/repos/db-migrate/node-db-migrate/issues/248/comments","events_url":"https://api.github.com/repos/db-migrate/node-db-migrate/issues/248/events","html_url":"https://github.com/db-migrate/node-db-migrate/issues/248","id":63266903,"number":248,"title":"How to query exist data before migration","user":{"login":"rkmax","id":395707,"avatar_url":"https://avatars.githubusercontent.com/u/395707?v=3","gravatar_id":"","url":"https://api.github.com/users/rkmax","html_url":"https://github.com/rkmax","followers_url":"https://api.github.com/users/rkmax/followers","following_url":"https://api.github.com/users/rkmax/following{/other_user}","gists_url":"https://api.github.com/users/rkmax/gists{/gist_id}","starred_url":"https://api.github.com/users/rkmax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkmax/subscriptions","organizations_url":"https://api.github.com/users/rkmax/orgs","repos_url":"https://api.github.com/users/rkmax/repos","events_url":"https://api.github.com/users/rkmax/events{/privacy}","received_events_url":"https://api.github.com/users/rkmax/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/db-migrate/node-db-migrate/labels/question","name":"question","color":"d4c5f9"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-03-20T17:12:18Z","updated_at":"2015-03-22T16:22:10Z","closed_at":"2015-03-22T16:22:10Z","body":"Example\r\n\r\nI need add a new `notNull: true` column, but the table has rows. so\r\n\r\n1. I need get current the data from the table\r\n2. add the new column with the `notNull: true` property\r\n3. insert updated records\r\n4. update the column definition with `notNull: true`\r\n\r\n\r\n```js\r\ndbm = dbm || require('db-migrate');\r\nvar type = dbm.dataType,\r\n    async = require('async');\r\n\r\nexports.up = function(db, callback) {\r\n\r\n  async.series([\r\n      db.addColumn.bind(db, 'users', 'email', {\r\n        type: type.STRING\r\n      }),\r\n      // get the current and update\r\n      db.changeColumn.bind(db, 'users', 'email', {\r\n        type: type.STRING,\r\n        notNull: true\r\n      }),            \r\n  ], callback);\r\n};\r\n\r\nexports.down = function(db, callback) {\r\n  db.removeColumn('users', 'email', callback);\r\n};\r\n```\r\n\r\nHow i can get the current data?\r\n\r\n<bountysource-plugin>\r\n---\r\nWant to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/9805565-how-to-query-exist-data-before-migration?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>"}}