-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normalize sp_name and res_type columns from hfj_spidx_* tables - adde…
…d sql migration scripts
- Loading branch information
1 parent
58b6d93
commit ac39d4d
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...rate/src/main/resources/ca/uhn/fhir/jpa/migrate/taskdef/populate_spidx_identity/mssql.sql
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,31 @@ | ||
WITH cte_min_id AS ( | ||
SELECT | ||
hash_identity, | ||
MIN(sp_id) AS min_sp_id | ||
FROM {0} -- replace {0} with hfj_spidx_* table | ||
WHERE hash_identity NOT IN ( | ||
SELECT hash_identity | ||
FROM hfj_spidx_identity | ||
) | ||
GROUP BY hash_identity | ||
) | ||
INSERT INTO HFJ_SPIDX_IDENTITY ( | ||
sp_identity_id, | ||
hash_identity, | ||
res_type, | ||
sp_name | ||
) | ||
SELECT | ||
NEXT VALUE FOR seq_spidx_identity OVER (ORDER BY src.res_type, src.sp_name) AS sp_identity_id, | ||
src.hash_identity, | ||
src.res_type, | ||
src.sp_name | ||
FROM {0} AS src -- replace {0} with hfj_spidx_* table | ||
JOIN cte_min_id AS cm | ||
ON src.hash_identity = cm.hash_identity | ||
AND src.sp_id = cm.min_sp_id | ||
ORDER BY | ||
src.res_type, | ||
src.sp_name; | ||
|
||
|
6 changes: 6 additions & 0 deletions
6
...ate/src/main/resources/ca/uhn/fhir/jpa/migrate/taskdef/populate_spidx_identity/oracle.sql
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,6 @@ | ||
SELECT | ||
hash_identity, | ||
MAX(sp_name) KEEP (DENSE_RANK FIRST ORDER BY sp_id) AS sp_name, | ||
MAX(res_type) KEEP (DENSE_RANK FIRST ORDER BY sp_id) AS res_type | ||
FROM hfj_spidx_token | ||
GROUP BY hash_identity; |
31 changes: 31 additions & 0 deletions
31
...e/src/main/resources/ca/uhn/fhir/jpa/migrate/taskdef/populate_spidx_identity/postgres.sql
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,31 @@ | ||
INSERT INTO HFJ_SPIDX_IDENTITY ( | ||
sp_identity_id, | ||
hash_identity, | ||
res_type, | ||
sp_name | ||
) | ||
WITH cte_min_id AS ( | ||
SELECT | ||
hash_identity, | ||
MIN(sp_id) AS min_sp_id | ||
FROM {0} -- replace {0} with hfj_spidx_* table | ||
WHERE hash_identity NOT IN ( | ||
SELECT hash_identity | ||
FROM hfj_spidx_identity | ||
) | ||
GROUP BY hash_identity | ||
) | ||
SELECT | ||
nextval(''SEQ_SPIDX_IDENTITY'') AS sp_identity_id, | ||
src.hash_identity, | ||
src.res_type, | ||
src.sp_name | ||
FROM {0} AS src -- replace {0} with hfj_spidx_* table | ||
JOIN cte_min_id AS cm | ||
ON src.hash_identity = cm.hash_identity | ||
AND src.sp_id = cm.min_sp_id | ||
ORDER BY src.res_type, src.sp_name; | ||
|
||
SELECT DISTINCT on (hash_identity) | ||
hash_identity | ||
FROM hfj_spidx_token |