{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/4478","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/4478/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/4478/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/4478/events","html_url":"https://github.com/sequelize/sequelize/pull/4478","id":106179499,"number":4478,"title":"Model.beforeSync, Model.afterSync, sequelize.beforeBulkSync, sequelize.afterBulkSync","user":{"login":"alekbarszczewski","id":2742373,"avatar_url":"https://avatars.githubusercontent.com/u/2742373?v=3","gravatar_id":"","url":"https://api.github.com/users/alekbarszczewski","html_url":"https://github.com/alekbarszczewski","followers_url":"https://api.github.com/users/alekbarszczewski/followers","following_url":"https://api.github.com/users/alekbarszczewski/following{/other_user}","gists_url":"https://api.github.com/users/alekbarszczewski/gists{/gist_id}","starred_url":"https://api.github.com/users/alekbarszczewski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alekbarszczewski/subscriptions","organizations_url":"https://api.github.com/users/alekbarszczewski/orgs","repos_url":"https://api.github.com/users/alekbarszczewski/repos","events_url":"https://api.github.com/users/alekbarszczewski/events{/privacy}","received_events_url":"https://api.github.com/users/alekbarszczewski/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-09-12T19:21:46Z","updated_at":"2015-09-15T12:58:49Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/sequelize/sequelize/pulls/4478","html_url":"https://github.com/sequelize/sequelize/pull/4478","diff_url":"https://github.com/sequelize/sequelize/pull/4478.diff","patch_url":"https://github.com/sequelize/sequelize/pull/4478.patch"},"body":"* before/afterSync hooks on Model executed before/after Model.sync(...)\r\n* before/afterBulkSync hooks on sequelize (instance) executed before/after sequelize.sync(...)\r\n* useful for plugins (for example to create a trigger after model table has beem created etc)\r\n* TODO: add new tests\r\n\r\n```js\r\nvar Sequelize = require('sequelize')\r\n\r\nvar sequelize = new Sequelize('postgres://localhost/sequelize_test', {\r\n  logging: false\r\n})\r\n\r\n// executed \"before\" `sequelize.sync(...)`\r\nsequelize.addHook('beforeBulkSync', function (options) {\r\n  // this = sequelize instance\r\n  console.log('beforeBulkSync')\r\n})\r\n\r\n// executed \"after\" `sequelize.sync(...)`\r\nsequelize.addHook('afterBulkSync', function (options) {\r\n  // this = sequelize instance\r\n  console.log('afterBulkSync')\r\n})\r\n\r\nvar Model = sequelize.define('Model', {}, {\r\n  hooks: {\r\n    // executed \"before\" `Model.sync(...)`\r\n    beforeSync: function (options) {\r\n      // this = Model\r\n      console.log('beforeSync')\r\n    },\r\n    // executed \"after\" `Model.sync(...)`\r\n    afterSync: function (options) {\r\n      // this = Model\r\n      console.log('afterSync')\r\n    }\r\n  }\r\n})\r\n\r\nsequelize.sync()\r\n.then(function(){\r\n  console.log('done')\r\n})\r\n```\r\n\r\noutput\r\n\r\n```\r\nbeforeBulkSync\r\nbeforeSync\r\nafterSync\r\nafterBulkSync\r\ndone\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/140380041","html_url":"https://github.com/sequelize/sequelize/pull/4478#issuecomment-140380041","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/4478","id":140380041,"user":{"login":"mickhansen","id":699049,"avatar_url":"https://avatars.githubusercontent.com/u/699049?v=3","gravatar_id":"","url":"https://api.github.com/users/mickhansen","html_url":"https://github.com/mickhansen","followers_url":"https://api.github.com/users/mickhansen/followers","following_url":"https://api.github.com/users/mickhansen/following{/other_user}","gists_url":"https://api.github.com/users/mickhansen/gists{/gist_id}","starred_url":"https://api.github.com/users/mickhansen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mickhansen/subscriptions","organizations_url":"https://api.github.com/users/mickhansen/orgs","repos_url":"https://api.github.com/users/mickhansen/repos","events_url":"https://api.github.com/users/mickhansen/events{/privacy}","received_events_url":"https://api.github.com/users/mickhansen/received_events","type":"User","site_admin":false},"created_at":"2015-09-15T12:58:49Z","updated_at":"2015-09-15T12:58:49Z","body":"@alekbarszczewski `hooks: true` is the default for all other methods, and what plugins need, so i'd say that's the way to go."}}