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

Persisting the results data from the two-part tariff match and allocate service #616

Merged
merged 26 commits into from
Jan 8, 2024

Conversation

Beckyrose200
Copy link
Contributor

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

As part of the work we have been doing, we've been hacking away at a branch in a mob to build the two-part-tariff service. As a result of this, we have some refactoring to do to tidy up the work we have done in our mob. We are keeping track of the refactoring to do in this issue DEFRA/water-abstraction-team#105. This PR will extract the persistAllocatedLicencesToResultsService out of our hacky branch and into its own PR along with the unit tests.

…te service

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

As part of the work we have been doing, we've been hacking away at a branch in a mob to build the two-part-tariff service. As a result of this, we have some refactoring to do to tidy up the work we have done in our mob. We are keeping track of the refactoring to do in this issue DEFRA/water-abstraction-team#105. This PR will extract the `persistAllocatedLicencesToResultsService`out of our hacky branch and into its own PR along with the unit tests.
@Beckyrose200 Beckyrose200 added the enhancement New feature or request label Dec 20, 2023
@Beckyrose200 Beckyrose200 marked this pull request as ready for review January 3, 2024 10:51
Copy link
Member

@Cruikshanks Cruikshanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some suggestions around the comments. We've already discussed moving where the `reviewReturnResultId gets set so I haven't bothered to flag it here.

@Jozzey Jozzey requested a review from Cruikshanks January 8, 2024 15:22
Co-authored-by: Jason Claxton <[email protected]>
Co-authored-by: Becky Ransome <[email protected]>
We can avoid bringing in an extra module and let the DB generate the ID by using [returning()](https://vincit.github.io/objection.js/api/query-builder/find-methods.html#returning).

We initially avoided it because it gave the impression that it ignores what we ask the DB to return and instead returns everything. But [this issue](Vincit/objection.js#1773) and our own testing confirmed Objection.js is just combining what we passed in with what we asked the DB to return, which gives the impression the DB is sending back more than we wanted.
Copy link
Member

@Cruikshanks Cruikshanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more suggested extra comment to include if you think it makes sense. I'll be all done after that - promise!

Co-authored-by: Alan Cruikshanks <[email protected]>
@Jozzey Jozzey requested a review from Cruikshanks January 8, 2024 17:06
Copy link
Member

@Cruikshanks Cruikshanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jozzey Jozzey merged commit bfa7c8a into main Jan 8, 2024
6 checks passed
@Jozzey Jozzey deleted the persist-two-part-tariff-results branch January 8, 2024 17:20
Cruikshanks added a commit that referenced this pull request Jan 27, 2024
Recently the team have found they repeatedly have to wipe the schemas, tables and views from their local `water_system_test` DB.

We initially put it down to us changing migrations that might have already been run.

> As a team we are happy for migrations that have yet to be run in production to be edited. Typically a migration is one of the first things created when working on a new feature but you don't know what you actually need until the feature is complete.

But we now know it was when we started [Persisting the results data from the two-part tariff match and allocate service](#616). We added `public` to the list of schemas the database helper should clean but overlooked that is also where our migrations tables sit.

So, we'd become locked in a cycle.

- Attempt to run migrations and they fail (because they are trying to create things that already exist)
- Delete schemas, and tables and views in `public` manually
- Re-run migrations and all is well
- Run unit tests which inadvertently delete migration records
- All is well for awhile
- Someone adds a new migration
- Go back to step one

This change fixes the issue by ensuring the Knex migration tables are ignored by the database helper when cleaning.
Cruikshanks added a commit that referenced this pull request Jan 27, 2024
Recently the team have found they repeatedly have to wipe the schemas, tables and views from their local `water_system_test` DB.

We initially put it down to us changing migrations that might have already been run.

> As a team we are happy for migrations that have yet to be run in production to be edited. Typically a migration is one of the first things created when working on a new feature but you don't know what you need until the feature is complete.

But we now know it was when we started [Persisting the results data from the two-part tariff match and allocate service](#616). We added `public` to the list of schemas the database helper should clean but overlooked that is also where our migrations tables sit.

So, we'd become locked in a cycle.

- Attempt to run migrations and they fail (because they are trying to create things that already exist)
- Delete schemas, then tables and views in `public` manually
- Re-run migrations and all is well
- Run unit tests which inadvertently delete migration records
- All is well for awhile
- Someone adds a new migration
- Go back to step one

This change fixes the issue by ensuring the Knex migration tables are ignored by the database helper when cleaning.
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.

3 participants