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

Replace mod_logs columns with a table - for real! #2615

Merged
merged 5 commits into from
Aug 19, 2024

Conversation

Cruikshanks
Copy link
Member

https://eaflood.atlassian.net/browse/WATER-4563
https://eaflood.atlassian.net/browse/WATER-4564
https://eaflood.atlassian.net/browse/WATER-4565

We foolishly merged Replace mod_logs columns with a table as an empty commit hence doing it for real this time!

Part of the work to display a licence's history to users (mod log)

It's a trap!

We have made the same mistake as the previous team. When we believed that a version (charge, licence, or return) had a one-to-one relationship with NALD mod log records, a JSONB field in each was a suitable solution to capturing just the information we needed. After all, it's only the historical records we have to worry about.

But when we learned that a version record could be linked to multiple mod logs, we should have taken a different approach. Instead, we ploughed on with our JSON column altering its name and default to match. 🤦😬

Once you've started down the JSONB road, it is easy to get trapped!

Thankfully, we've come to our senses before this saw the light of day in production. The mod log data we are importing needs to go into its own table, and we will link our version records accordingly. A 'standard' relationship database solution.

We could just add a migration that drops the columns and adds the new table. But because of the interaction between the views water-abstraction-system creates, it's no longer possible.

Because the mod log column migrations have not been run in production yet, we're just going to delete them. This might be a bit messy for our local environments, but it avoids leaving a 'dead' field in the database.

So, in this change, we delete the old migrations and then add our new table migration.

https://eaflood.atlassian.net/browse/WATER-4563
https://eaflood.atlassian.net/browse/WATER-4564
https://eaflood.atlassian.net/browse/WATER-4565

> We foolishly merged [Replace mod_logs columns with a table](#2613) as an empty commit hence doing it for real this time!

> Part of the work to display a licence's history to users (mod log)

**It's a trap!**

We have made the same mistake as the previous team. When we believed that a version (charge, licence, or return) had a one-to-one relationship with NALD mod log records, a JSONB field in each was a suitable solution to capturing just the information we needed. After all, it's only the historical records we have to worry about.

But when we learned that a version record could be linked to multiple mod logs, we should have taken a different approach. Instead, we ploughed on with our JSON column [altering its name and default](#2612) to match. 🤦😬

Once you've started down the JSONB road, it is easy to get trapped!

Thankfully, we've come to our senses before this saw the light of day in production. The mod log data we are importing needs to go into its own table, and we will link our version records accordingly. A 'standard' relationship database solution.

We could just add a migration that drops the columns and adds the new table. But because of the interaction between the views [water-abstraction-system](https://github.com/DEFRA/water-abstraction-system) creates, it's no longer possible.

Because the mod log column migrations have not been run in production yet, we're just going to delete them. This might be a bit messy for our local environments, but it avoids leaving a 'dead' field in the database.

So, in this change, we delete the old migrations and then add our new table migration.
@Cruikshanks Cruikshanks added the enhancement New feature or request label Aug 19, 2024
@Cruikshanks Cruikshanks self-assigned this Aug 19, 2024
@Cruikshanks Cruikshanks marked this pull request as ready for review August 19, 2024 09:11
@Cruikshanks Cruikshanks merged commit 62567b3 into main Aug 19, 2024
4 checks passed
@Cruikshanks Cruikshanks deleted the replace-mod-log-column-with-table-2 branch August 19, 2024 09:11
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