{"action":"created","issue":{"url":"https://api.github.com/repos/canton7/Simple.Migrations/issues/7","repository_url":"https://api.github.com/repos/canton7/Simple.Migrations","labels_url":"https://api.github.com/repos/canton7/Simple.Migrations/issues/7/labels{/name}","comments_url":"https://api.github.com/repos/canton7/Simple.Migrations/issues/7/comments","events_url":"https://api.github.com/repos/canton7/Simple.Migrations/issues/7/events","html_url":"https://github.com/canton7/Simple.Migrations/issues/7","id":184779965,"number":7,"title":"Prevent multiple migrations starting in parallel","user":{"login":"ashleydw","id":844437,"avatar_url":"https://avatars.githubusercontent.com/u/844437?v=3","gravatar_id":"","url":"https://api.github.com/users/ashleydw","html_url":"https://github.com/ashleydw","followers_url":"https://api.github.com/users/ashleydw/followers","following_url":"https://api.github.com/users/ashleydw/following{/other_user}","gists_url":"https://api.github.com/users/ashleydw/gists{/gist_id}","starred_url":"https://api.github.com/users/ashleydw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashleydw/subscriptions","organizations_url":"https://api.github.com/users/ashleydw/orgs","repos_url":"https://api.github.com/users/ashleydw/repos","events_url":"https://api.github.com/users/ashleydw/events{/privacy}","received_events_url":"https://api.github.com/users/ashleydw/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2016-10-24T08:36:51Z","updated_at":"2016-10-31T12:54:24Z","closed_at":null,"body":"In an environment with multiple instances of the same application, starting applications with the migration  logic in the Startup will start multiple migrations that run in parallel. This can lead to race-conditions where one or more migrations may fail as they all have read that they should start migrations to bring the database up to the latest version.\n\nI believe locking the `versioninfo` table with an exclusive lock may be the answer to this problem as it will prevent other migrations starting if one has already locked the table in its transaction.\n\nIn Postgres:  `LOCK TABLE versioninfo IN ACCESS EXCLUSIVE MODE;`\n"},"comment":{"url":"https://api.github.com/repos/canton7/Simple.Migrations/issues/comments/257286308","html_url":"https://github.com/canton7/Simple.Migrations/issues/7#issuecomment-257286308","issue_url":"https://api.github.com/repos/canton7/Simple.Migrations/issues/7","id":257286308,"user":{"login":"canton7","id":568104,"avatar_url":"https://avatars.githubusercontent.com/u/568104?v=3","gravatar_id":"","url":"https://api.github.com/users/canton7","html_url":"https://github.com/canton7","followers_url":"https://api.github.com/users/canton7/followers","following_url":"https://api.github.com/users/canton7/following{/other_user}","gists_url":"https://api.github.com/users/canton7/gists{/gist_id}","starred_url":"https://api.github.com/users/canton7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/canton7/subscriptions","organizations_url":"https://api.github.com/users/canton7/orgs","repos_url":"https://api.github.com/users/canton7/repos","events_url":"https://api.github.com/users/canton7/events{/privacy}","received_events_url":"https://api.github.com/users/canton7/received_events","type":"User","site_admin":false},"created_at":"2016-10-31T12:54:24Z","updated_at":"2016-10-31T12:54:24Z","body":"Right, I decided to go with the approach of running each migration + version table update in its own individual transaction, reading the current schema version at the beginning of each transaction, and properly handling the case where it was changed under our feet. This should support all databases without the need for multiple connections, or or database-type-specific locking which might not be supported by all databases.\r\n\r\nWork is underway, and I've got an implementation in place. It needs more testing, both against different databases and in different scenarios, before I'm happy to merge it."}}
{"actor":{"display_login":"canton7"}}