Skip to content

Commit

Permalink
PO-642-646 Add new columns to 4 tables
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-readman committed Aug 23, 2024
1 parent 7b6883e commit d03e2b6
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
*
* OPAL Program
*
* MODULE : parties_new_columns.sql
*
* DESCRIPTION : Add new columns to the PARTIES table.
*
* VERSION HISTORY:
*
* Date Author Version Nature of Change
* ---------- -------- -------- ---------------------------------------------------------------------------------------------------------
* 22/08/2024 I Readman 1.0 PO-642 Add new columns to the PARTIES table
*
**/
-- Add new columns but keep last_changed_date as the final column in the table
ALTER TABLE parties DROP COLUMN last_changed_date;
ALTER TABLE parties ADD COLUMN telephone_home varchar(35);
ALTER TABLE parties ADD COLUMN telephone_business varchar(35);
ALTER TABLE parties ADD COLUMN telephone_mobile varchar(35);
ALTER TABLE parties ADD COLUMN email_1 varchar(80);
ALTER TABLE parties ADD COLUMN email_2 varchar(80);
ALTER TABLE parties ADD COLUMN last_changed_date timestamp;

COMMENT ON COLUMN parties.telephone_home IS 'Home telephone number';
COMMENT ON COLUMN parties.telephone_business IS 'Business telephone number';
COMMENT ON COLUMN parties.telephone_mobile IS 'Mobile telephone number';
COMMENT ON COLUMN parties.email_1 IS 'Primary e-mail address';
COMMENT ON COLUMN parties.email_2 IS 'Secondary e-mail address';
COMMENT ON COLUMN parties.last_changed_date IS 'Date this party was last changed in Account Maintenance.';

-- Restore data that was lost when the column was dropped
UPDATE parties set last_changed_date = '2020-10-11' where party_id = 500000007;
UPDATE parties set last_changed_date = '2023-03-12' where party_id = 500000009;
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
*
* OPAL Program
*
* MODULE : impositions_new_columns.sql
*
* DESCRIPTION : Add new columns to the IMPOSITIONS table.
*
* VERSION HISTORY:
*
* Date Author Version Nature of Change
* ---------- -------- -------- ---------------------------------------------------------------------------------------------------------
* 22/08/2024 I Readman 1.0 PO-643 Add new columns to the IMPOSITIONS table
*
**/
-- Add new columns but preserve order in the data model spreadsheet
-- Impositions table is currently empty so no data loss
ALTER TABLE impositions DROP COLUMN creditor_account_id;
ALTER TABLE impositions DROP COLUMN unit_fine_adjusted;
ALTER TABLE impositions DROP COLUMN unit_fine_units;
ALTER TABLE impositions DROP COLUMN completed;
ALTER TABLE impositions ADD COLUMN offence_title varchar(120);
ALTER TABLE impositions ADD COLUMN offence_code varchar(10);
ALTER TABLE impositions ADD COLUMN creditor_account_id bigint NOT NULL;
ALTER TABLE impositions ADD COLUMN unit_fine_adjusted boolean;
ALTER TABLE impositions ADD COLUMN unit_fine_units smallint;
ALTER TABLE impositions ADD COLUMN completed boolean;
ALTER TABLE impositions ALTER COLUMN offence_id DROP NOT NULL;

ALTER TABLE impositions ADD CONSTRAINT imp_creditor_account_id_fk FOREIGN KEY (creditor_account_id) REFERENCES creditor_accounts (creditor_account_id);

COMMENT ON COLUMN impositions.offence_title IS 'Offence title where id unavailable (local offences TFO''d)';
COMMENT ON COLUMN impositions.offence_code IS 'Offence code where id unavailable (local offences TFO''d)';
COMMENT ON COLUMN impositions.creditor_account_id IS 'ID of the creditor account to be allocated payments received against this imposition';
COMMENT ON COLUMN impositions.unit_fine_adjusted IS 'Whether a "Unit Fine Adjustment under s.18(7) CJA 1991" was made';
COMMENT ON COLUMN impositions.unit_fine_units IS 'Number of units';
COMMENT ON COLUMN impositions.completed IS 'If the imposition has been paid in full';
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
*
* OPAL Program
*
* MODULE : enforcement_new_column.sql
*
* DESCRIPTION : Add new column to the ENFORCEMENT table.
*
* VERSION HISTORY:
*
* Date Author Version Nature of Change
* ---------- -------- -------- ---------------------------------------------------------------------------------------------------------
* 23/08/2024 I Readman 1.0 PO-644 Add new column to the ENFORCEMENT table
*
**/
-- Create temporary table to hold enforcement data
CREATE TEMP TABLE enforcements_tmp AS SELECT * FROM enforcements;

-- Drop columns to maintain column order from data model spreadsheet
ALTER TABLE enforcements DROP COLUMN warrant_reference;
ALTER TABLE enforcements DROP COLUMN case_reference;
ALTER TABLE enforcements DROP COLUMN hearing_date;
ALTER TABLE enforcements DROP COLUMN hearing_court_id;
ALTER TABLE enforcements DROP COLUMN account_type;
ALTER TABLE enforcements DROP COLUMN posted_by_user_id;

ALTER TABLE enforcements ADD COLUMN result_responses json;
ALTER TABLE enforcements ADD COLUMN warrant_reference varchar(20);
ALTER TABLE enforcements ADD COLUMN case_reference varchar(40);
ALTER TABLE enforcements ADD COLUMN hearing_date timestamp;
ALTER TABLE enforcements ADD COLUMN hearing_court_id bigint;
ALTER TABLE enforcements ADD COLUMN account_type varchar(20);
ALTER TABLE enforcements ADD COLUMN posted_by_user_id bigint;

ALTER TABLE enforcements ADD CONSTRAINT enf_hearing_court_id_fk FOREIGN KEY (hearing_court_id) REFERENCES courts (court_id);
ALTER TABLE enforcements ADD CONSTRAINT enf_posted_by_user_id_fk FOREIGN KEY (posted_by_user_id) REFERENCES users (user_id);

COMMENT ON COLUMN enforcements.result_responses IS 'Name value pairs for enforcement parameters';
COMMENT ON COLUMN enforcements.warrant_reference IS 'The reference number of the warrant generated from this action';
COMMENT ON COLUMN enforcements.case_reference IS 'The reference number of the case generated from this action';
COMMENT ON COLUMN enforcements.hearing_date IS 'The hearing date of the case generated from this action';
COMMENT ON COLUMN enforcements.hearing_court_id IS 'The hearing court of the case generated from this action';
COMMENT ON COLUMN enforcements.account_type IS 'The enforcement account type that auto-enforcement deemed this to be at the time of it applying this action';
COMMENT ON COLUMN enforcements.posted_by_user_id IS 'The user ID and is the foreign key to Users table but can be NULL, so if a not null value is put then it is enforced';

-- Update information from dropped columns
UPDATE enforcements e SET warrant_reference = (SELECT warrant_reference FROM enforcements_tmp et WHERE e.enforcement_id = et.enforcement_id),
case_reference = (SELECT case_reference FROM enforcements_tmp et WHERE e.enforcement_id = et.enforcement_id),
hearing_date = (SELECT hearing_date FROM enforcements_tmp et WHERE e.enforcement_id = et.enforcement_id),
hearing_court_id = (SELECT hearing_court_id FROM enforcements_tmp et WHERE e.enforcement_id = et.enforcement_id),
account_type = (SELECT account_type FROM enforcements_tmp et WHERE e.enforcement_id = et.enforcement_id),
posted_by_user_id = (SELECT posted_by_user_id FROM enforcements_tmp et WHERE e.enforcement_id = et.enforcement_id);
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
*
* OPAL Program
*
* MODULE : log_audit_details_new_columns.sql
*
* DESCRIPTION : Add new columns to the LOG_AUDIT_DETAILS table.
*
* VERSION HISTORY:
*
* Date Author Version Nature of Change
* ---------- -------- -------- ---------------------------------------------------------------------------------------------------------
- 23/08/2024 I Readman 1.0 PO-646 Add new columns to the LOG_AUDIT_DETAILS table
*
**/
-- Drop columns to maintain column order from data model spreadsheet
ALTER TABLE log_audit_details DROP COLUMN json_request;

ALTER TABLE log_audit_details ADD COLUMN associated_record_type varchar(30);
ALTER TABLE log_audit_details ADD COLUMN associated_record_id varchar(30);
ALTER TABLE log_audit_details ADD COLUMN json_request text;

COMMENT ON COLUMN log_audit_details.associated_record_type IS 'Type of record identified by associated_record_id. Could be transaction, account, suspense line etc';
COMMENT ON COLUMN log_audit_details.associated_record_id IS 'ID of the associated record. So ID of the record or transaction etc being logged';
COMMENT ON COLUMN log_audit_details.json_request IS 'The REST request information received that initiated this action and written in a json format but stored as TEXT';

0 comments on commit d03e2b6

Please sign in to comment.