ministryofjustice/courtfinder — pull request #221 by tomstuart (2014-10-27 17:59:27+00:00)
Title: Introduce jurisdictions

This is a significant change to the data model.

Before this change:

* courts were associated with areas of law through the `CourtsAreasOfLaw` model (e.g. “Bristol Civil and Family Justice Centre covers Adoption, Bankruptcy, Children…”); and
* courts were associated with councils through the `CourtCouncilLink` model (e.g. “Bristol Civil and Family Justice Centre covers Bath & NE Somerset Council, Bristol City Council, North Somerset Council… for cases involving Children”).

This was bad for two reasons:

1. Each `CourtCouncilLink` specified a particular area of law, but there was nothing to constrain these to the areas of law already associated with the court. It was possible for councils to be linked to courts via an area of the law that the court didn’t actually cover.
2. Each `CourtCouncilLink` connected an individual court with an individual council, which meant there wasn’t a central place to record information about the court’s relationship with all councils in a particular area of law (e.g. “Bristol Civil and Family Justice centre is the single point of entry for cases involving Children”).

This pull request renames the `CourtsAreasOfLaw` model to `Remit`, then removes the `CourtCouncilLink` model altogether, replacing it with a `Jurisdiction` model which connects courts to councils via their remit. This consolidates the relationships between courts, councils and areas of law, which solves both of the above problems:

1. Now we can only associate a court with a council via a `Remit`, which acts as the authoritative record of which areas of law are covered by that court.
2. Now a single `Remit` aggregates all of a court’s councils for a particular area of law, so in future we can use it to record information like the “this court is a single point of entry” flag.

The `admin-db-to-json.py` script has been updated to use the new data model, and I’ve verified that its exported JSON is unchanged by this pull request.

The final migration actually deletes the `court_council_links` table, so we should archive it before deploying these changes to production.