diff --git a/common/src/main/resources/db/changelog/db.changelog-master.yaml b/common/src/main/resources/db/changelog/db.changelog-master.yaml index 5a08ce5549..39f178104a 100644 --- a/common/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/common/src/main/resources/db/changelog/db.changelog-master.yaml @@ -156,4 +156,10 @@ databaseChangeLog: - include: file: db/changelog/v2023/add_columns_to_coverage.sql - include: - file: db/changelog/v2023/add_optout_property.sql \ No newline at end of file + file: db/changelog/v2023/add_optout_property.sql + - include: + file: db/changelog/v2023/extend_coverage_partition.sql + - include: + file: db/changelog/v2023/create_current_mbi_table.sql + - include: + file: db/changelog/v2023/create_current_mbi_procedure.sql \ No newline at end of file diff --git a/common/src/main/resources/db/changelog/test_only/coverage-fake-partitions.sql b/common/src/main/resources/db/changelog/test_only/coverage-fake-partitions.sql index a77172e271..208486044a 100644 --- a/common/src/main/resources/db/changelog/test_only/coverage-fake-partitions.sql +++ b/common/src/main/resources/db/changelog/test_only/coverage-fake-partitions.sql @@ -19,4 +19,10 @@ create table if not exists tst_2022 partition of tst for values in (2022); create table if not exists tst_2023 partition of tst - for values in (2023); \ No newline at end of file + for values in (2023); + +create table if not exists tst_2023 partition of tst + for values in (2024); + +create table if not exists tst_2023 partition of tst + for values in (2025); \ No newline at end of file diff --git a/common/src/main/resources/db/changelog/v2023/create_current_mbi_procedure.sql b/common/src/main/resources/db/changelog/v2023/create_current_mbi_procedure.sql new file mode 100644 index 0000000000..fe2a333588 --- /dev/null +++ b/common/src/main/resources/db/changelog/v2023/create_current_mbi_procedure.sql @@ -0,0 +1,72 @@ +CREATE OR REPLACE PROCEDURE update_current_mbi_2023() +LANGUAGE plpgsql +AS $$ +begin +INSERT INTO current_mbi +SELECT DISTINCT current_mbi from coverage_anthem_united_2023 +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_bcbs_2023 +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_centene_2023 +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_cigna1_2023 +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_cigna2_2023 +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_cvs_2023 +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_centene_2023 +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_humana_2023 +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_misc_2023 +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_mutual_dean_clear_cambia_rite_2023 +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_united1_2023 +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_united_2023 +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_default +UNION DISTINCT +SELECT DISTINCT current_mbi from sandbox_2023 +ON CONFLICT DO NOTHING; +end; +$$; +-- +-- CREATE OR REPLACE PROCEDURE update_current_mbi_2024() +-- LANGUAGE plpgsql +-- AS $$ +-- begin +-- INSERT INTO current_mbi +-- SELECT DISTINCT current_mbi from coverage_anthem_united_2024 +-- UNION DISTINCT +-- SELECT DISTINCT current_mbi from coverage_bcbs_2024 +-- UNION DISTINCT +-- SELECT DISTINCT current_mbi from coverage_centene_2024 +-- UNION DISTINCT +-- SELECT DISTINCT current_mbi from coverage_cigna1_2024 +-- UNION DISTINCT +-- SELECT DISTINCT current_mbi from coverage_cigna2_2024 +-- UNION DISTINCT +-- SELECT DISTINCT current_mbi from coverage_cvs_2024 +-- UNION DISTINCT +-- SELECT DISTINCT current_mbi from coverage_centene_2024 +-- UNION DISTINCT +-- SELECT DISTINCT current_mbi from coverage_humana_2024 +-- UNION DISTINCT +-- SELECT DISTINCT current_mbi from coverage_misc_2024 +-- UNION DISTINCT +-- SELECT DISTINCT current_mbi from coverage_mutual_dean_clear_cambia_rite_2024 +-- UNION DISTINCT +-- SELECT DISTINCT current_mbi from coverage_united1_2024 +-- UNION DISTINCT +-- SELECT DISTINCT current_mbi from coverage_united_2024 +-- UNION DISTINCT +-- SELECT DISTINCT current_mbi from coverage_default +-- UNION DISTINCT +-- SELECT DISTINCT current_mbi from sandbox_2024 +-- ON CONFLICT DO NOTHING; +-- end; +-- $$; +-- \ No newline at end of file diff --git a/common/src/main/resources/db/changelog/v2023/create_current_mbi_table.sql b/common/src/main/resources/db/changelog/v2023/create_current_mbi_table.sql new file mode 100644 index 0000000000..f473f55b7d --- /dev/null +++ b/common/src/main/resources/db/changelog/v2023/create_current_mbi_table.sql @@ -0,0 +1,32 @@ +CREATE TABLE IF NOT EXISTS public.current_mbi (mbi VARCHAR(32) NOT NULL); +CREATE UNIQUE INDEX unique_mbi ON public.current_mbi(mbi); + +INSERT INTO public.current_mbi +SELECT DISTINCT current_mbi from coverage_anthem_united +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_bcbs +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_centene +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_cigna1 +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_cigna2 +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_cvs +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_centene +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_humana +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_misc +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_mutual_dean_clear_cambia_rite +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_united1 +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_united2 +UNION DISTINCT +SELECT DISTINCT current_mbi from coverage_default +UNION DISTINCT +SELECT DISTINCT current_mbi from sandbox +ON CONFLICT DO NOTHING \ No newline at end of file diff --git a/common/src/main/resources/db/changelog/v2023/extend_coverage_partition.sql b/common/src/main/resources/db/changelog/v2023/extend_coverage_partition.sql new file mode 100644 index 0000000000..4261514ad5 --- /dev/null +++ b/common/src/main/resources/db/changelog/v2023/extend_coverage_partition.sql @@ -0,0 +1,59 @@ +create table sandbox_2024 partition of sandbox + for values in (2024); +create table sandbox_2025 partition of sandbox + for values in (2025); + +create table coverage_anthem_united_2024 partition of coverage_anthem_united + for values in (2024); +create table coverage_anthem_united_2025 partition of coverage_anthem_united + for values in (2025); + +create table coverage_bcbs_2024 partition of coverage_bcbs + for values in (2024); +create table coverage_bcbs_2025 partition of coverage_bcbs + for values in (2025); + +create table coverage_centene_2024 partition of coverage_centene + for values in (2024); +create table coverage_centene_2025 partition of coverage_centene + for values in (2025); + +create table coverage_cigna1_2024 partition of coverage_cigna1 + for values in (2024); +create table coverage_cigna1_2025 partition of coverage_cigna1 + for values in (2025); + +create table coverage_cigna2_2024 partition of coverage_cigna2 + for values in (2024); +create table coverage_cigna2_2025 partition of coverage_cigna2 + for values in (2025); + +create table coverage_cvs_2024 partition of coverage_cvs + for values in (2024); +create table coverage_cvs_2025 partition of coverage_cvs + for values in (2025); + +create table coverage_humana_2024 partition of coverage_humana + for values in (2024); +create table coverage_humana_2025 partition of coverage_humana + for values in (2025); + +create table coverage_united1_2024 partition of coverage_united1 + for values in (2024); +create table coverage_united1_2025 partition of coverage_united1 + for values in (2025); + +create table coverage_united_2024 partition of coverage_united2 + for values in (2024); +create table coverage_united_2025 partition of coverage_united2 + for values in (2025); + +create table coverage_mutual_dean_clear_cambia_rite_2024 partition of coverage_mutual_dean_clear_cambia_rite + for values in (2024); +create table coverage_mutual_dean_clear_cambia_rite_2025 partition of coverage_mutual_dean_clear_cambia_rite + for values in (2025); + +create table coverage_misc_2024 partition of coverage_misc + for values in (2024); +create table coverage_misc_2025 partition of coverage_misc + for values in (2025); \ No newline at end of file