Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new 'points' job #1028

Merged
merged 9 commits into from
Sep 24, 2024
Merged

Implement new 'points' job #1028

merged 9 commits into from
Sep 24, 2024

Conversation

Cruikshanks
Copy link
Member

https://eaflood.atlassian.net/browse/WATER-4645

In Start importing licence version points to 'water', we added a step to the licence-import job to start importing licence points to a new table we'd created: water.licence_version_purpose_points.

However, we've since encountered two issues with that original approach.

  • We've found the legacy UI also displays details about sources, which are connected to points. Our original solution didn't cater for this, which means we cannot switch wholly to it
  • Updating the licence_version_purpose_points table happens as the last step of the licence-import job. But we've found it is often failing because of bad licence data, which means our new step is never getting called

So, in this change, we are creating a whole new job to handle points. Part of the change is NALD points will now sit in their own table. return_requirement_points and licence_version_purpose_points will link to it rather than holding their own copies of the licence. The job will be responsible for updating all three.

https://eaflood.atlassian.net/browse/WATER-4645

In [Start importing licence version points to 'water'](#1009) we added a step to the **licence-import** job to start importing licence points to a new table we'd created: `water.licence_version_purpose_points`.

However, we've since encountered two issues with that original approach.

- We've found the legacy UI also display details about sources, which are connected to points. Our original solution didn't cater for this which means we cannot switch wholly to it
- Updating the `licence_version_purpose_points` table happens as the last step of the **licence-import** job. But we've found it is often failing because of bad licence data, which means our new step is never getting called

So, in this change we are creating a whole new job to handle points. Part of the change is NALD points will now sit in their own table. `return_requirement_points` and `licence_version_purpose_points` will link to it rather than holding their own copies of the licence. The job job will be responsible for updating all three.
@Cruikshanks Cruikshanks added the enhancement New feature or request label Sep 24, 2024
@Cruikshanks Cruikshanks self-assigned this Sep 24, 2024
Cruikshanks added a commit to DEFRA/water-abstraction-service that referenced this pull request Sep 24, 2024
This will create the new sources table then populate it.

Then it will create the new `points` table and update the existing points tables ready for linking to it.

We don't drop any redundant columns in this migration because there will be a period where we have to wait for the [changes we've made to the **water-abstraction-import**](DEFRA/water-abstraction-import#1028) to take affect.
@Cruikshanks Cruikshanks marked this pull request as ready for review September 24, 2024 13:03
@Cruikshanks Cruikshanks merged commit 6e2e300 into main Sep 24, 2024
3 of 4 checks passed
@Cruikshanks Cruikshanks deleted the new-licence-points-job branch September 24, 2024 13:04
Cruikshanks added a commit to DEFRA/water-abstraction-system that referenced this pull request Sep 24, 2024
https://eaflood.atlassian.net/browse/WATER-4600
https://eaflood.atlassian.net/browse/WATER-4645

> Part of the work to migrate return versions from NALD to WRLS

In [Add Licence Version Purpose Point model](#1288) we added our second model that represented a table in the `water` schema that hold point information. When we added `ReturnRequirementPointModel` it was to represent points linked to a return requirement.

In the setup journey for new return requirements you select the points to associate from those against the licence. We were extracting this information from the `permit.licence` table until we realised that [water-abstraction-import](https://github.com/DEFRA/water-abstraction-import) does not populate it when a licence is 'dead'.

We need to be able to create new return requirements even for dead licences in order to correct historic information. So, this source being defunct we made changes to the import to populate a new `water.licence_version_purpose_points` from which we could then derive a licence's points.

That worked great for returns setup, so we moved to updating the view licence summary page to use the new source. It also was effected by the issue that point information was no longer available if the licence was dead. The page includes information about the water source for a licence. It was then we realised that the water source is derived from a licence's points!

What we'd built for return requirements and licence version purposes was missing this information.

We investigated the NALD data properly and came away with some realisations

- NALD maintains a central list of 'points' (we knew this, but like addresses felt this was unnecessary)
- Each point holds a lot more data than just the National Grid References for its location
- Each NALD point is linked to a NALD source, and these too hold extra information

There was extra information users were maintaining against each point that we were missing. This information explained why points were centrally managed and other records were linked to them. This realisation meant we needed to completely re-think how we should maintain points in WRLS going forward.

So, in [the water-abstraction-service](DEFRA/water-abstraction-service#2638) we've created a migration to add new `sources` and `points` tables. We'also amended the existing `licence_version_purpose_points` and `return_requirement_points` to make it possible to link them to `points`. (Their `ngr_*` fields plus things like `description` are now defunct but to avoid breaking changes we'll need to drop them in a future change.)

In [water-abstraction-import](DEFRA/water-abstraction-import#1028) we've added a new job to ensure `points` gets populated as part of the import. We've also incorporated populating and linking `licence_version_purpose_points` and `return_requirement_points` as part of the new job.

With those changes in place, this change updates everything around the existing point models, as well as adding the new ones.

The water sources are reference data, so as part of adding `SourceModel` we include a seeder. The existing models and their tests are updated to represent the fact they are now just `many-to-many` models. This means we make `points` a top level property of `ReturnRequirementModel` and `LicenceVersionPurposeModel`.

The logic for describing a point is copied to `PointModel`. We'll delete `BasePointModel` in the next change, where we update the existing functionality to use the new structure.
Cruikshanks added a commit to DEFRA/water-abstraction-system that referenced this pull request Sep 25, 2024
https://eaflood.atlassian.net/browse/WATER-4600
https://eaflood.atlassian.net/browse/WATER-4645

> Part of the work to migrate return versions from NALD to WRLS

In [Add Licence Version Purpose Point model](#1288), we added our second model, which represented a table in the `water` schema that holds point information. When we added `ReturnRequirementPointModel,` it was to represent points linked to a return requirement.

In the setup journey for new return requirements, you select the points to associate with those against the licence. We were extracting this information from the `permit.licence` table until we realised that [water-abstraction-import](https://github.com/DEFRA/water-abstraction-import) does not populate it when a licence is 'dead'.

We need to be able to create new return requirements, even for dead licences, to correct historical information. So, this source being defunct, we made changes to the import to populate a new `water.licence_version_purpose_points` from which we could then derive a licence's points.

That worked great for returns setup, so we also updated the view licence summary page to use `water.licence_version_purpose_points`. The issue that point information was not available if the licence was dead affected it. The page also includes information about a licence's water source. It was then that we realised that the water source is derived from a licence's points!

What we'd built for return requirements and licence version purposes was missing this information.

We investigated the NALD data properly and came up with some new realisations.

- NALD maintains a central list of 'points' (we knew this, but like addresses felt this was unnecessary)
- Each point holds a lot more data than just the National Grid References for its location
- Each NALD point is linked to a NALD source, and these, too, hold extra information

There was extra information users were maintaining against each point that we were missing. This information explained why points were centrally managed and linked to other records. This realisation meant we needed to completely re-think how we should maintain points in WRLS going forward.

So, in [the water-abstraction-service](DEFRA/water-abstraction-service#2638), we've created a migration to add new `sources` and `points` tables. We also amended the existing `licence_version_purpose_points` and `return_requirement_points` to make it possible to link them to `points`. (Their `ngr_*` fields plus things like `description` are now defunct, but to avoid breaking changes, we'll need to drop them in a future change.)

In [water-abstraction-import](DEFRA/water-abstraction-import#1028), we've added a new job to ensure `points` get populated as part of the import. We've also incorporated populating and linking `licence_version_purpose_points` and `return_requirement_points` into the new job.

With those changes in place, this change updates everything around the existing point models and adds new ones.

The water sources are reference data, so we include a seeder when adding `SourceModel`. We update the existing models and their tests to reflect the fact that they are now just `many-to-many` models. This means we make `points` a top-level property of `ReturnRequirementModel` and `LicenceVersionPurposeModel`.

We then go through _all_ existing logic and update it to use the new points data structure.
Cruikshanks added a commit that referenced this pull request Oct 2, 2024
https://eaflood.atlassian.net/browse/WATER-4645

> Part of the work to migrate return versions from NALD to WRLS

In [Implement new 'points' job](#1028) we amended the import service to include a new 'points' job. Having realised that the way were intending to store point information was insufficient, we made enough changes to our points schema to warrant its own job to manage importing the NALD data.

We thought we'd captured everything 'point' related in the change but have since spotted 'Means of abstraction'. This is linked to a point in NALD and gives how water will be abstracted, for example, "Surface Mounted Pump (Fixed)". We are required to display this in the UI. Having [added the new column](DEFRA/water-abstraction-service#2642), this ensures it gets populated.
Cruikshanks added a commit that referenced this pull request Oct 7, 2024
https://eaflood.atlassian.net/browse/WATER-4645

> Part of the work to migrate return versions from NALD to WRLS

In [Implement new 'points' job](#1028) we amended the import service to include a new 'points' job. Having realised that the way we intended to store point information was insufficient, we made enough changes to our points schema to warrant its own job to manage importing the NALD data.

We thought we'd captured everything 'point' related in the change but have since spotted 'Means of abstraction'. This is linked to an abstraction purpose in NALD and gives how water will be abstracted, for example, "Surface Mounted Pump (Fixed)". We are required to display this in the UI. Having [added the new column](DEFRA/water-abstraction-service#2642), this ensures it gets populated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant