-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace mod_logs columns with a table - for real! (#2615)
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.
- Loading branch information
1 parent
4076c3c
commit 62567b3
Showing
8 changed files
with
58 additions
and
116 deletions.
There are no files selected for viewing
45 changes: 0 additions & 45 deletions
45
migrations/20240809155344-water-versions-add-mod-log-column.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
migrations/sqls/20240809155344-water-versions-add-mod-log-column-down.sql
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
migrations/sqls/20240809155344-water-versions-add-mod-log-column-up.sql
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
migrations/sqls/20240816144249-alter-versions-mod-log-column-down.sql
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
migrations/sqls/20240816144249-alter-versions-mod-log-column-up.sql
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* Revert previous change */ | ||
|
||
BEGIN; | ||
|
||
DROP TABLE IF EXISTS water.mod_logs; | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
Add mod -logs table | ||
> Part of the work to display a licence's history to users (mod log) | ||
Adds a table to hold imported mod logs from NALD. | ||
NALD has a concept called 'mod log'. Essentially, when someone creates a new licence, charge or return version, they | ||
are required to provide a reason and can also add a note. | ||
Rather than this being stored against each record, the 'mod log' is stored in a single place. Users can then view a | ||
licence's 'mod logs' to get a sense of the history of the licence. | ||
When charging switched from NALD to WRLS, we (the previous team) built the ability to record a reason and note against | ||
a new charge version but didn't import any historic data. With return requirements also soon to switch from NALD to | ||
WRLS there is a concern that this view of changes made to a licence will be lost. | ||
Having reviewed how the information is held in NALD we've confirmed that we can extract this information and import it | ||
as part of the NALD import. | ||
*/ | ||
|
||
BEGIN; | ||
|
||
CREATE TABLE water.mod_logs ( | ||
id uuid PRIMARY KEY DEFAULT public.gen_random_uuid(), | ||
external_id varchar NOT NULL, | ||
event_code varchar NOT NULL, | ||
event_description varchar NOT NULL, | ||
reason_type varchar NULL, | ||
reason_code varchar NULL, | ||
reason_description varchar NULL, | ||
nald_date date NOT NULL, | ||
user_id varchar NOT NULL, | ||
note text NULL, | ||
licence_ref varchar NOT NULL, | ||
licence_external_id varchar NOT NULL, | ||
licence_id uuid NULL, | ||
licence_version_external_id varchar NULL, | ||
licence_version_id uuid NULL, | ||
charge_version_external_id varchar NULL, | ||
charge_version_id uuid NULL, | ||
return_version_external_id varchar NULL, | ||
return_version_id uuid NULL, | ||
created_at timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL, | ||
updated_at timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL, | ||
CONSTRAINT uniq_mod_log_external_id UNIQUE (external_id) | ||
); | ||
|
||
COMMIT; |