Skip to main content
Warning This document has not been updated for a while now. It may be out of date.
Last updated: 10 Feb 2022

Support government changes

Change a government in Whitehall

Following a General Election or other reason for governmental change the current Government in Whitehall will need to be closed, and a new one created.

The Content Support team will normally be the ones who close the government and re-assign ministers once a new government has been opened. However, a developer will often be required to monitor the queues, as detailed below.

Closing a government

Governments are listed at the government path of Whitehall Admin.

  1. Select the current government, and click the Prepare to close this government link.
  2. Close the government.

This will close the current government and remove all ministerial appointments.

This will cause a high number of documents to be represented by the Publishing API which might mean some delays on content being up to date on the website. Previous tests have shown that it takes around 3.5 hours for the queues to clear in integration.

Grafana monitoring for:

Open a new government

Create a new government

This will instantly create a new government. Changes can be seen in the Rails console by running Government.current.

The new government should also instantly appear in the response from /api/governments.

Applying a banner to political content published by the previous government

Content in Whitehall can be marked as political. Political content which was published under a previous government is historic?. This is highlighted on the page, and in search results. This feature is also known as history mode.

See these pages for example:

A content page A search results page

Marking content as political can happen automatically through the PoliticalContentIdentifier. The political flag on an Edition can also be set manually.

There is a Rake task to reindex all political content in search. This must be done after a government is closed.


If we need to backdate a government or split a single government into two distinct dates, we need to run a rake task to republish all political content from Whitehall to properly associate content with the government at it’s first published date:

Ending ministerial roles without closing a government

If we need to end all ministerial roles without explicitly closing a government, we can run a rake task:

This will end all ministerial roles except the Prime Minister. You might have to do that one manually.

Machinery of Government Changes

Following machinery of government changes, developers can help content designers make bulk changes to documents and users.

Bulk changing users

There is a Rake task in Signon to change the organisation that a user belongs to in bulk: data_hygiene:bulk_update_organisation[csv_file].

It accepts a CSV file which should have at least the following columns (in any order):

Column Header Description
Old email The old email address of the user.
New email The new email address of the user.
New organisation The slug of the new organisations for the user.

Note: It may be necessary to leave the old users around so they can still edit content for the old organisation. In that case you can bulk invite new users using the interface in Signon.

Bulk retagging documents

There is a Rake task in Whitehall to change the lead and supporting organisations that a document is tagged to in bulk: data_hygiene:bulk_update_organisation[csv_file].

It accepts a CSV file which should have at least the following columns (in any order):

Column Header Description
Slug The slug of the document.
Document type The type of the document, for example DetailedGuide. This is used when more than one document is matched by the Slug.
New lead organisations The slugs of the new leading organisations (separated by a comma). These will replace any existing organisations.
New supporting organisations The slugs of the new supporting organisations (separated by a comma). These will replace any existing organisations.

To run on anything other than a local environment, the CSV needs to be added manually to the /tmp directory using scp-push. $ gds govuk connect scp-push --environment [integration|staging|integration] name-of-machine[:1|:2|:3] path/to/file.csv /tmp/ The rake task can then be run from the command line following these instructions.

There is a similar Rake task to change the organisations for Manuals. A data migration is required to change the organisations for (Mainstream) Publisher documents. This is an example PR: Migrate Publisher docs

Reorder ministers/peoples role titles

During a reshuffle, a minister can gain two positions of state, known as RoleAppointments in Whitehall. One of these is perceived to be a more senior role than the other. However, Collections will just render these by ascending order of ActiveRecord IDs as default.

  1. SSH onto a whitehall machine in the environment you wish to apply the changes to and bring up a rails console.
  2. Query the Person you wish to find by slug, or surname and forename

    $ person = Person.find_by(slug: 'harry-potter')
  3. current_role_appointments are used to construct the current_roles_title which is used in collections by the header partial to render the titles. The IDs of each RoleAppointment will be assigned as the person_appointment_order which is then used to sort which comes first. So start by assigning each role to a variable.

    > first_role = person.current_role_appointments.first
    => #<RoleAppointment id: 5768, role_id: 3645, person_id: 351, created_at: "2021-09-15 16:02:32.000000000 +0100", updated_at: "2021-09-21 15:37:32.000000000 +0100", started_at: "2021-09-15 00:00:00.000000000 +0100", ended_at: nil, content_id: "82c03a1b-4252-44a0-a6b3-9438d589d081">
    > second_role = person.current_role_appointments.second
    => #<RoleAppointment id: 7114, role_id: 1536, person_id: 351, created_at: "2019-09-10 23:03:53.000000000 +0100", updated_at: "2021-09-21 15:34:30.000000000 +0100", started_at: "2019-09-10 00:00:00.000000000 +0100", ended_at: nil, content_id: "2b671e4e-fca9-4b0e-99f7-eed8706c5f0d">
  4. So it is clear which roles you are working with, you can use the RoleAppointmentPresenter to see how the final content item will appear for this role:

    => {:title=>"The Rt Hon Harry Potter MP - Secretary of State for Hogwarts", :locale=>"en", :details=>{:current=>true, :person_appointment_order=>5768, :started_on=>"2021-09-15T00:00:00+01:00"}, :publishing_app=>"whitehall", :update_type=>"major", :document_type=>"role_appointment", :public_updated_at=>Tue, 21 Sep 2021 15:37:32.000000000 BST +01:00, :schema_name=>"role_appointment"}
    => {:title=>"The Rt Hon Harry Potter MP - Minister for Witchcraft and Wizardry ", :locale=>"en", :details=>{:current=>true, :person_appointment_order=>7114, :started_on=>"2019-09-10T00:00:00+01:00"}, :publishing_app=>"whitehall", :update_type=>"major", :document_type=>"role_appointment", :public_updated_at=>Tue, 21 Sep 2021 15:34:30.000000000 BST +01:00, :schema_name=>"role_appointment"}
  5. You now need to swap the IDs. Start by identifying a safe RoleAppointment ID that is not used by any existing role appointment:

    > 7196
  6. Assign the current first_role to the safe RoleAppointment ID, you can use update_column to skip validation and other checks.

    first_role.update_column(:id, 7196)
  7. Now assign the second role to the first role’s initial iD

    second_role.update_column(:id, 5768)
  8. Now assign the first_role to the ID that thesecond_role `previously had

    first_role.update_column(:id, 7114)
  9. Finally publish the change:

    > first_role.publish_to_publishing_api
    => [:en]
    > second_role.publish_to_publishing_api
    => [:en]
  10. Reload the page in collections (cachebust where required) and you should see your change reflected.

Codeblock summary

person = Person.find_by(slug: 'harry-potter')
first_role = person.current_role_appointments.first
second_role = person.current_role_appointments.second
safe_id = RoleAppointment.maximum(:id).next # 1234 # 5678

first_role.update_column(:id, safe_id)
second_role.update_column(:id, 1234)
first_role.update_column(:id, 5678)