Skip to content

Commit

Permalink
runtime config test fixes bespoke ll extract
Browse files Browse the repository at this point in the history
  • Loading branch information
robjharrison committed Sep 6, 2024
1 parent 3753e3e commit 1c12986
Show file tree
Hide file tree
Showing 6 changed files with 6,140 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ SET @TableName = N'ssd_version_log';
IF OBJECT_ID('ssd_development.ssd_version_log', 'U') IS NOT NULL DROP TABLE ssd_development.ssd_version_log;
IF OBJECT_ID('tempdb..#ssd_version_log', 'U') IS NOT NULL DROP TABLE #ssd_version_log;

-- META: {"type": "create_table", "name": "ssd_version_log"}
-- create versioning information object
CREATE TABLE ssd_development.ssd_version_log (
version_number NVARCHAR(10) NOT NULL, -- version num (e.g., "1.0.0")
Expand All @@ -138,7 +139,8 @@ CREATE TABLE ssd_development.ssd_version_log (
created_at DATETIME DEFAULT GETDATE(), -- timestamp when record was created
created_by NVARCHAR(10), -- which user created the record
impact_description NVARCHAR(255) -- additional notes on the impact of the release
);
);
-- META-END

-- ensure any previous current-version flag is set to 0 (not current), before adding new current version
UPDATE ssd_development.ssd_version_log SET is_current = 0 WHERE is_current = 1;
Expand All @@ -152,7 +154,7 @@ VALUES


-- HISTORIC versioning log data
INSERT INTO #ssd_version_log (version_number, release_date, description, is_current, created_by, impact_description)
INSERT INTO ssd_version_log (version_number, release_date, description, is_current, created_by, impact_description)
VALUES
('1.0.0', '2023-01-01', 'Initial alpha release (Phase 1 end)', 0, 'admin', ''),
('1.1.1', '2024-06-26', 'Minor updates with revised assessment_factors', 0, 'admin', 'Revised JSON Array structure implemented for CiN'),
Expand Down Expand Up @@ -209,7 +211,7 @@ SET @TableName = N'ssd_person';
IF OBJECT_ID('ssd_development.ssd_person') IS NOT NULL DROP TABLE ssd_development.ssd_person;
IF OBJECT_ID('tempdb..#ssd_person') IS NOT NULL DROP TABLE #ssd_person;


-- META: {"type": "create_table", "name": "ssd_person"}
-- Create structure
CREATE TABLE ssd_development.ssd_person (
pers_legacy_id NVARCHAR(48), -- metadata={"item_ref":"PERS014A"}
Expand All @@ -227,7 +229,7 @@ CREATE TABLE ssd_development.ssd_person (
pers_nationality NVARCHAR(48), -- metadata={"item_ref":"PERS012A"}
ssd_flag INT -- Non-core data flag for D2I filter testing [TESTING]
);

-- META-END

-- CTE to get a no_upn_code
-- (assumption here is that all codes will be the same/current)
Expand Down Expand Up @@ -355,10 +357,12 @@ BEGIN
-- Add constraint(s)
PRINT '' -- fail-safe entry for test runs where FK constraints are added/run seperately

-- META: {"type": "create_idx", "name": "ssd_person"}
-- Create index(es)
CREATE NONCLUSTERED INDEX idx_ssd_person_pers_dob ON ssd_development.ssd_person(pers_dob);
CREATE NONCLUSTERED INDEX idx_ssd_person_pers_common_child_id ON ssd_development.ssd_person(pers_common_child_id);
CREATE NONCLUSTERED INDEX idx_ssd_person_ethnicity_gender ON ssd_development.ssd_person(pers_ethnicity, pers_gender);
-- META-END
END


Expand Down Expand Up @@ -417,13 +421,15 @@ SET @TableName = N'ssd_family';
IF OBJECT_ID('ssd_development.ssd_family') IS NOT NULL DROP TABLE ssd_development.ssd_family;
IF OBJECT_ID('tempdb..#ssd_family') IS NOT NULL DROP TABLE #ssd_family;


-- META: {"type": "create_table", "name": "ssd_family"}
-- Create structure
CREATE TABLE ssd_development.ssd_family (
fami_table_id NVARCHAR(48) PRIMARY KEY, -- metadata={"item_ref":"FAMI003A"}
fami_family_id NVARCHAR(48), -- metadata={"item_ref":"FAMI001A"}
fami_person_id NVARCHAR(48) -- metadata={"item_ref":"FAMI002A"}
);
-- META-END


-- Insert data
INSERT INTO ssd_development.ssd_family (
Expand All @@ -449,14 +455,16 @@ IF @Run_SSD_As_Temporary_Tables = 0
BEGIN
PRINT '' -- fail-safe entry for test runs where FK constraints are added/run seperately

-- META: {"type": "create_fk", "name": "ssd_family"}
-- Add constraint(s)
ALTER TABLE ssd_development.ssd_family ADD CONSTRAINT FK_ssd_family_person
FOREIGN KEY (fami_person_id) REFERENCES ssd_development.ssd_person(pers_person_id);

-- META-END
-- META: {"type": "create_idx", "name": "ssd_family"}
-- Create index(es)
CREATE NONCLUSTERED INDEX idx_ssd_family_person_id ON ssd_development.ssd_family(fami_person_id);
CREATE NONCLUSTERED INDEX idx_ssd_family_fami_family_id ON ssd_development.ssd_family(fami_family_id);

-- META-END
END


Expand Down Expand Up @@ -491,7 +499,7 @@ SET @TableName = N'ssd_address';
IF OBJECT_ID('ssd_development.ssd_address') IS NOT NULL DROP TABLE ssd_development.ssd_address;
IF OBJECT_ID('tempdb..#ssd_address') IS NOT NULL DROP TABLE #ssd_address;


-- META: {"type": "create_table", "name": "ssd_address"}
-- Create structure
CREATE TABLE ssd_development.ssd_address (
addr_table_id NVARCHAR(48) PRIMARY KEY, -- metadata={"item_ref":"ADDR007A"}
Expand All @@ -502,7 +510,7 @@ CREATE TABLE ssd_development.ssd_address (
addr_address_postcode NVARCHAR(15), -- metadata={"item_ref":"ADDR006A"}
addr_address_json NVARCHAR(1000) -- metadata={"item_ref":"ADDR001A"}
);

-- META-END

-- insert data
INSERT INTO ssd_development.ssd_address (
Expand Down Expand Up @@ -555,16 +563,19 @@ WHERE EXISTS
IF @Run_SSD_As_Temporary_Tables = 0
BEGIN
PRINT '' -- fail-safe entry for test runs where FK constraints are added/run seperately


-- META: {"type": "create_fk", "name": "ssd_address"}
-- Add constraint(s)
ALTER TABLE ssd_development.ssd_address ADD CONSTRAINT FK_ssd_address_person
FOREIGN KEY (addr_person_id) REFERENCES ssd_development.ssd_person(pers_person_id);

-- META-END
-- META: {"type": "create_idx", "name": "ssd_address"}
-- Create index(es)
CREATE NONCLUSTERED INDEX idx_ssd_address_person ON ssd_development.ssd_address(addr_person_id);
CREATE NONCLUSTERED INDEX idx_ssd_address_start ON ssd_development.ssd_address(addr_address_start_date);
CREATE NONCLUSTERED INDEX idx_ssd_address_end ON ssd_development.ssd_address(addr_address_end_date);
CREATE NONCLUSTERED INDEX idx_ssd_ssd_address_postcode ON ssd_development.ssd_address(addr_address_postcode);
-- META-END
END


Expand Down Expand Up @@ -598,14 +609,15 @@ SET @TableName = N'ssd_disability';
IF OBJECT_ID('ssd_development.ssd_disability') IS NOT NULL DROP TABLE ssd_development.ssd_disability;
IF OBJECT_ID('tempdb..#ssd_disability') IS NOT NULL DROP TABLE #ssd_disability;

-- META: {"type": "create_table", "name": "ssd_disability"}
-- Create the structure
CREATE TABLE ssd_development.ssd_disability
(
disa_table_id NVARCHAR(48) PRIMARY KEY, -- metadata={"item_ref":"DISA003A"}
disa_person_id NVARCHAR(48) NOT NULL, -- metadata={"item_ref":"DISA001A"}
disa_disability_code NVARCHAR(48) NOT NULL -- metadata={"item_ref":"DISA002A"}
);

-- META-END

-- Insert data
INSERT INTO ssd_development.ssd_disability (
Expand All @@ -630,14 +642,17 @@ WHERE EXISTS
IF @Run_SSD_As_Temporary_Tables = 0
BEGIN
PRINT '' -- fail-safe entry for test runs where FK constraints are added/run seperately


-- META: {"type": "create_fk", "name": "ssd_disability"}
-- Add constraint(s)
ALTER TABLE ssd_development.ssd_disability ADD CONSTRAINT FK_ssd_disability_person
FOREIGN KEY (disa_person_id) REFERENCES ssd_development.ssd_person(pers_person_id);

-- META-END
-- META: {"type": "create_idx", "name": "ssd_disability"}
-- Create index(es)
CREATE NONCLUSTERED INDEX idx_ssd_disability_person_id ON ssd_development.ssd_disability(disa_person_id);
CREATE NONCLUSTERED INDEX idx_ssd_disability_code ON ssd_development.ssd_disability(disa_disability_code);
-- META-END
END


Expand Down Expand Up @@ -674,7 +689,7 @@ SET @TableName = N'ssd_immigration_status';
IF OBJECT_ID('ssd_development.ssd_immigration_status') IS NOT NULL DROP TABLE ssd_development.ssd_immigration_status;
IF OBJECT_ID('tempdb..#ssd_immigration_status') IS NOT NULL DROP TABLE #ssd_immigration_status;


-- META: {"type": "create_table", "name": "ssd_immigration_status"}
-- Create structure
CREATE TABLE ssd_development.ssd_immigration_status (
immi_immigration_status_id NVARCHAR(48) PRIMARY KEY, -- metadata={"item_ref":"IMMI005A"}
Expand All @@ -683,7 +698,7 @@ CREATE TABLE ssd_development.ssd_immigration_status (
immi_immigration_status_end_date DATETIME, -- metadata={"item_ref":"IMMI004A"}
immi_immigration_status NVARCHAR(100) -- metadata={"item_ref":"IMMI002A"}
);
-- META-END

-- insert data
INSERT INTO ssd_development.ssd_immigration_status (
Expand Down Expand Up @@ -715,14 +730,17 @@ IF @Run_SSD_As_Temporary_Tables = 0
BEGIN
PRINT '' -- fail-safe entry for test runs where FK constraints are added/run seperately

-- META: {"type": "create_fk", "name": "ssd_immigration_status"}
-- Add constraint(s)
ALTER TABLE ssd_development.ssd_immigration_status ADD CONSTRAINT FK_ssd_immigration_status_person
FOREIGN KEY (immi_person_id) REFERENCES ssd_development.ssd_person(pers_person_id);

-- META-END
-- META: {"type": "create_idx", "name": "ssd_immigration_status"}
-- Create index(es)
CREATE NONCLUSTERED INDEX idx_ssd_immigration_status_immi_person_id ON ssd_development.ssd_immigration_status(immi_person_id);
CREATE NONCLUSTERED INDEX idx_ssd_immigration_status_start ON ssd_development.ssd_immigration_status(immi_immigration_status_start_date);
CREATE NONCLUSTERED INDEX idx_ssd_immigration_status_end ON ssd_development.ssd_immigration_status(immi_immigration_status_end_date);
-- META-END
END


Expand Down Expand Up @@ -763,6 +781,7 @@ SET @TableName = N'ssd_cin_episodes';
IF OBJECT_ID('ssd_development.ssd_cin_episodes') IS NOT NULL DROP TABLE ssd_development.ssd_cin_episodes;
IF OBJECT_ID('tempdb..#ssd_cin_episodes') IS NOT NULL DROP TABLE #ssd_cin_episodes;

-- META: {"type": "create_table", "name": "ssd_cin_episodes"}
-- Create structure
CREATE TABLE ssd_development.ssd_cin_episodes
(
Expand All @@ -778,8 +797,9 @@ CREATE TABLE ssd_development.ssd_cin_episodes
cine_close_date DATETIME, -- metadata={"item_ref":"CINE007A"}
cine_referral_team NVARCHAR(48), -- metadata={"item_ref":"CINE008A"}
cine_referral_worker_id NVARCHAR(100), -- metadata={"item_ref":"CINE009A"}
);

);
-- META-END

-- Insert data
INSERT INTO ssd_development.ssd_cin_episodes
(
Expand Down Expand Up @@ -1270,7 +1290,8 @@ PRINT 'Table created: ' + @TableName;
Object Name: ssd_cin_assessments
Description:
Author: D2I
Version: 1.3
Version: 1.4
1.3 COMPLETED_BY_USER_STAFF_ID swap to COMPLETED_BY_USER_ID #DtoI-1823 060924 RH
1.2 replace -1 vals _team_id and _worker_id with NULL #DtoI-1824 050924 RH
1.1: Roll-back to use of worker_id #DtoI-1755 040624 RH
1.0: Fix Aggr warnings use of isnull() 310524 RH
Expand Down Expand Up @@ -1306,7 +1327,7 @@ CREATE TABLE ssd_development.ssd_cin_assessments
cina_assessment_auth_date DATETIME, -- metadata={"item_ref":"CINA005A"}
cina_assessment_outcome_json NVARCHAR(1000), -- metadata={"item_ref":"CINA006A"}
cina_assessment_outcome_nfa NCHAR(1), -- metadata={"item_ref":"CINA009A"}
cina_assessment_team NVARCHAR(48), -- metadata={"item_ref":"CINA007A"}
cina_assessment_team NVARCHAR(48), -- metadata={"item_ref":"CINA007A"}
cina_assessment_worker_id NVARCHAR(100) -- metadata={"item_ref":"CINA008A"}
);

Expand Down Expand Up @@ -1383,8 +1404,8 @@ SELECT
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER
) AS cina_assessment_outcome_json,
fa.OUTCOME_NFA_FLAG AS cina_assessment_outcome_nfa,
NULLIF(fa.COMPLETED_BY_DEPT_ID, -1) AS cina_assessment_team, -- replace -1 values with NULL _team_id
NULLIF(fa.COMPLETED_BY_USER_STAFF_ID, -1) AS cina_assessment_worker_id -- replace -1 values with NULL for _worker_id
NULLIF(fa.COMPLETED_BY_DEPT_ID, -1) AS cina_assessment_team, -- replace -1 values with NULL _team_id
NULLIF(fa.COMPLETED_BY_USER_ID, -1) AS cina_assessment_worker_id -- replace -1 values with NULL for _worker_id

FROM
HDM.Child_Social.FACT_SINGLE_ASSESSMENT fa
Expand Down
Loading

0 comments on commit 1c12986

Please sign in to comment.