{"action":"created","comment":{"url":"https://api.github.com/repos/alphagov/publisher/pulls/comments/39964495","id":39964495,"diff_hunk":"@@ -0,0 +1,22 @@\n+class ChangeBusinessSupportEditionAreasToGssCodes < Mongoid::Migration\n+  def self.up\n+    # Editing of an edition with an Archived artefact is not allowed\n+    Edition.skip_callback(:save, :before, :check_for_archived_artefact)\n+\n+    BusinessSupportEdition.all.each do |edition|\n+      edition.area_gss_codes = Area.areas_for_edition(edition).map { |area|\n+        area.codes[\"gss\"]\n+      }.compact\n+\n+      edition.save!(validate: false) # Published editions can't be edited.\n+    end\n+  end\n+\n+  def self.down\n+    # If this needs rolling back perminantly, the area_gss_codes field should\n+    # probably just be removed from GOV.UK Content Models.\n+    #\n+    # .up is only adding data, not changing existing data, so I assume\n+    # a temporary rollback doesn't really require any action.","path":"db/migrate/20150828153331_change_business_support_edition_areas_to_gss_codes.rb","position":20,"original_position":20,"commit_id":"2d9eb01b5486f16a2e34f3be28616184c3ad4810","original_commit_id":"2d9eb01b5486f16a2e34f3be28616184c3ad4810","user":{"login":"jennyd","id":1822424,"avatar_url":"https://avatars.githubusercontent.com/u/1822424?v=3","gravatar_id":"","url":"https://api.github.com/users/jennyd","html_url":"https://github.com/jennyd","followers_url":"https://api.github.com/users/jennyd/followers","following_url":"https://api.github.com/users/jennyd/following{/other_user}","gists_url":"https://api.github.com/users/jennyd/gists{/gist_id}","starred_url":"https://api.github.com/users/jennyd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jennyd/subscriptions","organizations_url":"https://api.github.com/users/jennyd/orgs","repos_url":"https://api.github.com/users/jennyd/repos","events_url":"https://api.github.com/users/jennyd/events{/privacy}","received_events_url":"https://api.github.com/users/jennyd/received_events","type":"User","site_admin":false},"body":"I think we should remove the `area_gss_codes` field in the `down` method so that we can keep the data clean, rather than relying on ignoring extra fields in code if we need to roll back. We should be able to migrate the database back to its original state by rolling back this migration, and when we've switched over to using the GSS codes we should remove the `areas` field in another migration.","created_at":"2015-09-21T12:26:13Z","updated_at":"2015-09-21T12:26:13Z","html_url":"https://github.com/alphagov/publisher/pull/414#discussion_r39964495","pull_request_url":"https://api.github.com/repos/alphagov/publisher/pulls/414","_links":{"self":{"href":"https://api.github.com/repos/alphagov/publisher/pulls/comments/39964495"},"html":{"href":"https://github.com/alphagov/publisher/pull/414#discussion_r39964495"},"pull_request":{"href":"https://api.github.com/repos/alphagov/publisher/pulls/414"}}},"pull_request":{"url":"https://api.github.com/repos/alphagov/publisher/pulls/414","id":44933904,"html_url":"https://github.com/alphagov/publisher/pull/414","diff_url":"https://github.com/alphagov/publisher/pull/414.diff","patch_url":"https://github.com/alphagov/publisher/pull/414.patch","issue_url":"https://api.github.com/repos/alphagov/publisher/issues/414","number":414,"state":"open","locked":false,"title":"Gss codes for business support editions","user":{"login":"mikejustdoit","id":348052,"avatar_url":"https://avatars.githubusercontent.com/u/348052?v=3","gravatar_id":"","url":"https://api.github.com/users/mikejustdoit","html_url":"https://github.com/mikejustdoit","followers_url":"https://api.github.com/users/mikejustdoit/followers","following_url":"https://api.github.com/users/mikejustdoit/following{/other_user}","gists_url":"https://api.github.com/users/mikejustdoit/gists{/gist_id}","starred_url":"https://api.github.com/users/mikejustdoit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikejustdoit/subscriptions","organizations_url":"https://api.github.com/users/mikejustdoit/orgs","repos_url":"https://api.github.com/users/mikejustdoit/repos","events_url":"https://api.github.com/users/mikejustdoit/events{/privacy}","received_events_url":"https://api.github.com/users/mikejustdoit/received_events","type":"User","site_admin":false},"body":"We're working on removing BusinessSupportEdition's dependence on 'area slugs' in favour of referring to areas by their (more stable) GSS codes (http://www.ons.gov.uk/ons/guide-method/geography/products/names--codes-and-look-ups/standard-names-and-codes/index.html).\r\n\r\nSince the migration involves multiple applications and gems, we've decided to first add the GSS Codes to the BusinessSupportEditions, then think about removing the current area slugs after.\r\n\r\nI've explained the reasoning behind these changes in the commit messages.\r\n\r\nChanges of particular interest are in areas.js.erb and the EditionsController. I'm not 100% happy with how using Area slugs and GSS codes side-by-side is being handled, but as a temporary measure, it works and is tested.","created_at":"2015-09-14T14:06:58Z","updated_at":"2015-09-21T12:26:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"33f2051aa4ddf3b03130d6e6b23927d0a896f442","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/alphagov/publisher/pulls/414/commits","review_comments_url":"https://api.github.com/repos/alphagov/publisher/pulls/414/comments","review_comment_url":"https://api.github.com/repos/alphagov/publisher/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alphagov/publisher/issues/414/comments","statuses_url":"https://api.github.com/repos/alphagov/publisher/statuses/2d9eb01b5486f16a2e34f3be28616184c3ad4810","head":{"label":"alphagov:gss-codes-for-business-support-editions","ref":"gss-codes-for-business-support-editions","sha":"2d9eb01b5486f16a2e34f3be28616184c3ad4810","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":1996077,"name":"publisher","full_name":"alphagov/publisher","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/publisher","description":"The publishing tool for GOV.UK","fork":false,"url":"https://api.github.com/repos/alphagov/publisher","forks_url":"https://api.github.com/repos/alphagov/publisher/forks","keys_url":"https://api.github.com/repos/alphagov/publisher/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/publisher/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/publisher/teams","hooks_url":"https://api.github.com/repos/alphagov/publisher/hooks","issue_events_url":"https://api.github.com/repos/alphagov/publisher/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/publisher/events","assignees_url":"https://api.github.com/repos/alphagov/publisher/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/publisher/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/publisher/tags","blobs_url":"https://api.github.com/repos/alphagov/publisher/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/publisher/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/publisher/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/publisher/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/publisher/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/publisher/languages","stargazers_url":"https://api.github.com/repos/alphagov/publisher/stargazers","contributors_url":"https://api.github.com/repos/alphagov/publisher/contributors","subscribers_url":"https://api.github.com/repos/alphagov/publisher/subscribers","subscription_url":"https://api.github.com/repos/alphagov/publisher/subscription","commits_url":"https://api.github.com/repos/alphagov/publisher/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/publisher/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/publisher/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/publisher/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/publisher/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/publisher/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/publisher/merges","archive_url":"https://api.github.com/repos/alphagov/publisher/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/publisher/downloads","issues_url":"https://api.github.com/repos/alphagov/publisher/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/publisher/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/publisher/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/publisher/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/publisher/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/publisher/releases{/id}","created_at":"2011-07-04T15:35:13Z","updated_at":"2015-09-19T18:35:24Z","pushed_at":"2015-09-21T12:11:02Z","git_url":"git://github.com/alphagov/publisher.git","ssh_url":"git@github.com:alphagov/publisher.git","clone_url":"https://github.com/alphagov/publisher.git","svn_url":"https://github.com/alphagov/publisher","homepage":"","size":11849,"stargazers_count":23,"watchers_count":23,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":2,"forks":18,"open_issues":2,"watchers":23,"default_branch":"master"}},"base":{"label":"alphagov:master","ref":"master","sha":"1a0941192be89332fa9fb30e9acdd552a6154c06","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":1996077,"name":"publisher","full_name":"alphagov/publisher","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/publisher","description":"The publishing tool for GOV.UK","fork":false,"url":"https://api.github.com/repos/alphagov/publisher","forks_url":"https://api.github.com/repos/alphagov/publisher/forks","keys_url":"https://api.github.com/repos/alphagov/publisher/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/publisher/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/publisher/teams","hooks_url":"https://api.github.com/repos/alphagov/publisher/hooks","issue_events_url":"https://api.github.com/repos/alphagov/publisher/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/publisher/events","assignees_url":"https://api.github.com/repos/alphagov/publisher/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/publisher/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/publisher/tags","blobs_url":"https://api.github.com/repos/alphagov/publisher/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/publisher/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/publisher/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/publisher/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/publisher/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/publisher/languages","stargazers_url":"https://api.github.com/repos/alphagov/publisher/stargazers","contributors_url":"https://api.github.com/repos/alphagov/publisher/contributors","subscribers_url":"https://api.github.com/repos/alphagov/publisher/subscribers","subscription_url":"https://api.github.com/repos/alphagov/publisher/subscription","commits_url":"https://api.github.com/repos/alphagov/publisher/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/publisher/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/publisher/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/publisher/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/publisher/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/publisher/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/publisher/merges","archive_url":"https://api.github.com/repos/alphagov/publisher/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/publisher/downloads","issues_url":"https://api.github.com/repos/alphagov/publisher/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/publisher/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/publisher/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/publisher/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/publisher/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/publisher/releases{/id}","created_at":"2011-07-04T15:35:13Z","updated_at":"2015-09-19T18:35:24Z","pushed_at":"2015-09-21T12:11:02Z","git_url":"git://github.com/alphagov/publisher.git","ssh_url":"git@github.com:alphagov/publisher.git","clone_url":"https://github.com/alphagov/publisher.git","svn_url":"https://github.com/alphagov/publisher","homepage":"","size":11849,"stargazers_count":23,"watchers_count":23,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":2,"forks":18,"open_issues":2,"watchers":23,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alphagov/publisher/pulls/414"},"html":{"href":"https://github.com/alphagov/publisher/pull/414"},"issue":{"href":"https://api.github.com/repos/alphagov/publisher/issues/414"},"comments":{"href":"https://api.github.com/repos/alphagov/publisher/issues/414/comments"},"review_comments":{"href":"https://api.github.com/repos/alphagov/publisher/pulls/414/comments"},"review_comment":{"href":"https://api.github.com/repos/alphagov/publisher/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alphagov/publisher/pulls/414/commits"},"statuses":{"href":"https://api.github.com/repos/alphagov/publisher/statuses/2d9eb01b5486f16a2e34f3be28616184c3ad4810"}}}}