-
Notifications
You must be signed in to change notification settings - Fork 7
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
[TTAHUB-3451]format comlog comdate history #2467
[TTAHUB-3451]format comlog comdate history #2467
Conversation
Please also update src/queries/dataRequests/user/communication-logs.sql as its logic around the date is now not needed. |
SELECT | ||
id clid, | ||
data->>'communicationDate' orig, | ||
regexp_replace(data->>'communicationDate','[-. ]','/','g') reseparated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might not be a bad idea to add a comment to state the intention of each of these regex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I almost wonder if it could be simplified any, but I see you had to deal with weird cases. Like where you don't have the starting portion of the year ie 24 = 2024.
Some AI code:
-- Get all the bad cases. SELECT * FROM "CommunicationLogs" WHERE data->>'communicationDate' !~ '^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/([0-9]{4})$';
-- Sample update (obv we cant use as is) UPDATE "CommunicationLogs" SET data = jsonb_set(data, '{communicationDate}', '"01/01/1970"') WHERE data->>'communicationDate' !~ '^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/([0-9]{4})$';
Something like this might be used to handle the weird date cases (again AI generated) but might be what you have or close to it:
UPDATE "CommunicationLogs" SET data = jsonb_set( data, '{communicationDate}', to_jsonb( CASE WHEN data->>'communicationDate' ~ '^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/([0-9]{2})$' THEN regexp_replace(data->>'communicationDate', '/([0-9]{2})$', '/20\\1') ELSE data->>'communicationDate' END ) ) WHERE data->>'communicationDate' !~ '^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/([0-9]{4})$';
What you have is good, don't use the above as it makes this harder to follow that what you already have. This is a one and done migration not something that needs to be for preferment. |
This still needs to be addressed |
Description of change
Improperly formatted
communicationDate
values were making their way intoCommunicationLogs.data
. This fixes the history and produces all valid dates. There's one date in the year 3034, but that's the date that was input by the user.How to test
You can see what all the updates will be just by inspecting
SELECT * FROM comdate_corrections;
Issue(s)
Checklists
Every PR
Before merge to main
Production Deploy
After merge/deploy