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

PO-970 Alter the REPORTS related, DOCUMENTS, DOCUMENT_INSTANCES, RESU… #703

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* OPAL Program
*
* MODULE : drop_document_tables.sql
*
* DESCRIPTION : Drop document related tables so they can be recreated after reference data work done by Capita
*
* VERSION HISTORY:
*
* Date Author Version Nature of Change
* ---------- ------- -------- -------------------------------------------------------------------------------------------------------
* 14/01/2025 A Dennis 1.0 PO-970 Drop document related tables so they can be recreated after reference data work done by Capita
*
**/

ALTER TABLE account_transfers
DROP constraint IF EXISTS at_document_instance_id_fk;

DROP TABLE IF EXISTS document_instances;
DROP SEQUENCE IF EXISTS result_document_id_seq;
DROP TABLE IF EXISTS result_documents;
DROP TABLE IF EXISTS documents;
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* OPAL Program
*
* MODULE : documents.sql
*
* DESCRIPTION : Recreate the DOCUMENTS table and check constraints after reference data work done by Capita
*
* VERSION HISTORY:
*
* Date Author Version Nature of Change
* ---------- ------- -------- --------------------------------------------------------------------------------------------------
* 14/01/2025 A Dennis 1.0 PO-970 Recreate the DOCUMENTS table and check constraints after reference data work done by Capita
*
**/

CREATE TABLE documents(
document_id varchar(12) NOT NULL,
recipient varchar(4) NOT NULL,
document_language varchar(2) NOT NULL,
priority smallint NOT NULL,
header_type varchar(2),
signature_source varchar(4),
document_template varchar(30),
document_elements json,
print_parameters json
);

ALTER TABLE documents
ADD CONSTRAINT documents_pk
PRIMARY KEY (document_id),
ADD CONSTRAINT d_recipient_cc
CHECK (recipient IN ('BENA','CLAC','CRED','DEF','EMP','FRA','OTHC','PRIS')),
ADD CONSTRAINT d_document_language_cc
CHECK (document_language IN ('EN','CY')),
ADD CONSTRAINT d_priority_cc
CHECK (priority IN (0,1,2)),
ADD CONSTRAINT d_header_type_cc
CHECK (COALESCE(header_type) IN ('A','AP','EO')),
ADD CONSTRAINT d_signature_source_cc
CHECK (COALESCE(signature_source) IN ('Area','LJA'));

COMMENT ON COLUMN public.documents.document_id IS 'Unique ID of this record';

COMMENT ON COLUMN public.documents.recipient IS 'The type of party that this document will be addressed to';

COMMENT ON COLUMN public.documents.document_language IS 'the language the document is written in';

COMMENT ON COLUMN public.documents.priority IS 'Determines the order of printing with respect to other documents in the same batch';

COMMENT ON COLUMN public.documents.header_type IS 'The type of header output on the document (EO, A, MC, ME, MA, MF, AP or null)';

COMMENT ON COLUMN public.documents.signature_source IS 'Source of the document signature (Area, LJA or null)';

COMMENT ON COLUMN public.documents.document_elements IS 'Details of the structured data items to be included in the document content';
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* OPAL Program
*
* MODULE : document_instances.sql
*
* DESCRIPTION : Recreate the DOCUMENT_INSTANCES table after reference data work done by Capita
*
* VERSION HISTORY:
*
* Date Author Version Nature of Change
* ---------- ------- -------- --------------------------------------------------------------------------------------
* 14/01/2025 A Dennis 1.0 PO-970 Recreate the DOCUMENT_INSTANCES table after reference data work done by Capita
*
**/

CREATE TABLE document_instances(
document_instance_id bigint NOT NULL,
document_id varchar(10) NOT NULL,
business_unit_id smallint NOT NULL,
generated_date timestamp NOT NULL,
generated_by varchar(20) NOT NULL,
associated_record_type varchar(30) NOT NULL,
associated_record_id varchar(30) NOT NULL,
status varchar(10) NOT NULL,
printed_date timestamp,
document_content xml NOT NULL);

ALTER TABLE document_instances
ADD CONSTRAINT document_instances_pk
PRIMARY KEY (document_instance_id),
ADD CONSTRAINT di_document_id_fk
FOREIGN KEY (document_id)
REFERENCES documents (document_id),
ADD CONSTRAINT di_business_unit_fk
FOREIGN KEY (business_unit_id)
REFERENCES business_units (business_unit_id);

CREATE INDEX IF NOT EXISTS di_bu_document_status_date_idx ON document_instances(business_unit_id, document_id, status, generated_date);

COMMENT ON COLUMN document_instances.document_instance_id IS 'Unique ID for this record';

COMMENT ON COLUMN document_instances.document_id IS 'ID of the report being generated';

COMMENT ON COLUMN document_instances.business_unit_id IS 'ID of the business unit this report instance was generated for';

COMMENT ON COLUMN document_instances.generated_date IS 'The date the document was generated';

COMMENT ON COLUMN document_instances.generated_by IS 'ID of the user that generated this instance of the document';

COMMENT ON COLUMN document_instances.document_content IS 'The structured document content';
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* OPAL Program
*
* MODULE : restore_account_transfers_fk.sql
*
* DESCRIPTION : Restore foreign key in ACCOUNT_TRANSFERS table after DOCUMENT_INSTANCES table was recreated
*
* VERSION HISTORY:
*
* Date Author Version Nature of Change
* ---------- ------- -------- ---------------------------------------------------------------------------------------------------
* 14/01/2025 A Dennis 1.0 PO-970 Restore foreign key in ACCOUNT_TRANSFERS table after DOCUMENT_INSTANCES table was recreated
*
**/

ALTER TABLE account_transfers
ADD CONSTRAINT at_document_instance_id_fk FOREIGN KEY
(
document_instance_id
)
REFERENCES document_instances
(
document_instance_id
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* OPAL Program
*
* MODULE : result_documents.sql
*
* DESCRIPTION : Recreate the RESULT_DOCUMENTS table and sequence and unique index after reference data work done by Capita
*
* VERSION HISTORY:
*
* Date Author Version Nature of Change
* ---------- ------- -------- -----------------------------------------------------------------------------------------------------------------
* 14/01/2025 A Dennis 1.0 PO-970 Recreate the RESULT_DOCUMENTS table and sequence and unique index after reference data work done by Capita
*
**/

CREATE SEQUENCE IF NOT EXISTS result_document_id_seq
INCREMENT 1
START 1
MINVALUE 1
NO MAXVALUE
CACHE 1;

CREATE TABLE result_documents(
result_document_id bigint NOT NULL DEFAULT nextval('result_document_id_seq'),
result_id varchar(6) NOT NULL,
document_id varchar(10) NOT NULL,
cy_document_id varchar(13));

ALTER SEQUENCE result_document_id_seq
OWNED BY result_documents.result_document_id;

ALTER TABLE result_documents
ADD CONSTRAINT result_documents_pk
PRIMARY KEY (result_document_id),
ADD CONSTRAINT rd_result_id_fk
FOREIGN KEY (result_id)
REFERENCES results (result_id),
ADD CONSTRAINT rd_document_id_fk
FOREIGN KEY (document_id)
REFERENCES documents (document_id),
ADD CONSTRAINT rd_cy_document_id_fk
FOREIGN KEY (cy_document_id)
REFERENCES documents (document_id);

CREATE UNIQUE INDEX rd_result_document_idx
ON result_documents (result_id, document_id);
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* OPAL Program
*
* MODULE : modify_report_tables.sql
*
* DESCRIPTION : Changes to the REPORTS, REPORT_INSTANCE and REPORT_ENTRIES tables after reference data work done by Capita
*
* VERSION HISTORY:
*
* Date Author Version Nature of Change
* ---------- ------- -------- -----------------------------------------------------------------------------------------------------------------
* 14/01/2025 A Dennis 1.0 PO-970 Changes to the REPORTS, REPORT_INSTANCE and REPORT_ENTRIES tables after reference data work done by Capita
*
**/

ALTER TABLE reports
ALTER COLUMN report_id TYPE varchar(30),
DROP COLUMN IF EXISTS user_entries,
DROP COLUMN IF EXISTS report_parameters,
ADD COLUMN report_parameters json;

ALTER TABLE report_instances
ALTER COLUMN report_id TYPE varchar(30),
ALTER COLUMN report_parameters DROP NOT NULL,
ADD CONSTRAINT ri_report_id_fk
FOREIGN KEY (report_id)
REFERENCES reports (report_id);

ALTER TABLE report_entries
ALTER COLUMN report_id TYPE varchar(30),
DROP COLUMN IF EXISTS report_instances_id,
ADD COLUMN report_instance_id bigint,
ADD CONSTRAINT re_report_id_fk
FOREIGN KEY (report_id)
REFERENCES reports (report_id),
ADD CONSTRAINT re_report_instance_id_fk
FOREIGN KEY (report_instance_id)
REFERENCES report_instances (report_instance_id)
DEFERRABLE INITIALLY DEFERRED;

Loading