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

Restructure models by type and scheme #78

Merged
merged 9 commits into from
Jan 6, 2023
Merged

Conversation

Cruikshanks
Copy link
Member

@Cruikshanks Cruikshanks commented Jan 5, 2023

DEFRA/water-abstraction-team#69

Our next step in refactoring the models to deal with legacy issues is to identify them by type and scheme. Admittedly, we know we are just dealing with one type (legacy) and scheme (water). But more will be coming and this helps set the groundwork for implementing base classes that allow us to start hiding some of the issues with the existing DB.

So, we move the existing models into a new models/water folder and we add new LegacyBaseModel and WaterBaseModel which all our existing classes will inherit from. We then move any existing logic for dealing with the legacy data into the LegacyBaseModel and take the opportunity to update it (originally based on a 2016 solution).

@Cruikshanks Cruikshanks added the housekeeping Refactoring, tidying up or other work which supports the project label Jan 5, 2023
@Cruikshanks Cruikshanks self-assigned this Jan 5, 2023
DEFRA/water-abstraction-team#69

Our next step in refactoring the models to deal with legacy issues is to identify them by type and scheme. Admittedly, we know we are just dealing with the one type (legacy) and scheme (water). But more will be coming and this helps set the groundwork for implementing base classes that allow us to start hiding some of the issues with the existing DB.

So, we move the existing models into a new `models/water` folder and we add a new `LegacyModel` which all our existing classes will inherit from.
With all the movement we need to update all our references.
This means adding 2 new base models, one extending from the other with `BaseModel` as the root parent.

This also means we can move out of BaseModel functionality we only added to support working with the legacy service and it's various schemas. When we get to add our own models, they won't need to inherit this cruft.

Whilst doing this we were able to make some changes to the whole declaring the schema name solution. The original was made in 2016, so for example `RelatedQueryBuilder` is defunct (should have spotted that before 🤦). And as we only need this in the `LegacyBaseModel` we no longer assign our custom QueryBuilder to Objection's root Model `QueryBuilder` property.

Finally, we added some documentation around all this so if we ever have to look at it again we'll have a clue what what it's all about.
@Cruikshanks Cruikshanks changed the base branch from rewrite-migrations to main January 5, 2023 19:11
@Cruikshanks Cruikshanks marked this pull request as ready for review January 6, 2023 08:30
@Cruikshanks Cruikshanks requested a review from StuAA78 January 6, 2023 08:31
@Cruikshanks Cruikshanks merged commit 8d0d134 into main Jan 6, 2023
@Cruikshanks Cruikshanks deleted the restructure-models branch January 6, 2023 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
housekeeping Refactoring, tidying up or other work which supports the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants