From 1ffc24deff4690876949cc9e73c0df0f468902dc Mon Sep 17 00:00:00 2001 From: uiro-bi Date: Mon, 27 May 2024 07:23:05 -0300 Subject: [PATCH 1/2] feat: re insert pre hook --- models/br_ms_cnes/br_ms_cnes__dados_complementares.sql | 5 +++++ models/br_ms_cnes/br_ms_cnes__equipamento.sql | 5 +++++ models/br_ms_cnes/br_ms_cnes__equipe.sql | 5 +++++ models/br_ms_cnes/br_ms_cnes__estabelecimento.sql | 5 +++++ .../br_ms_cnes/br_ms_cnes__estabelecimento_ensino.sql | 5 +++++ .../br_ms_cnes__estabelecimento_filantropico.sql | 10 ++++++++++ models/br_ms_cnes/br_ms_cnes__gestao_metas.sql | 5 +++++ models/br_ms_cnes/br_ms_cnes__habilitacao.sql | 5 +++++ models/br_ms_cnes/br_ms_cnes__incentivos.sql | 5 +++++ models/br_ms_cnes/br_ms_cnes__leito.sql | 5 +++++ models/br_ms_cnes/br_ms_cnes__profissional.sql | 5 +++++ models/br_ms_cnes/br_ms_cnes__regra_contratual.sql | 5 +++++ .../br_ms_cnes/br_ms_cnes__servico_especializado.sql | 5 +++++ 13 files changed, 70 insertions(+) diff --git a/models/br_ms_cnes/br_ms_cnes__dados_complementares.sql b/models/br_ms_cnes/br_ms_cnes__dados_complementares.sql index fe515868..ef4d4f54 100644 --- a/models/br_ms_cnes/br_ms_cnes__dados_complementares.sql +++ b/models/br_ms_cnes/br_ms_cnes__dados_complementares.sql @@ -8,6 +8,11 @@ "data_type": "int64", "range": {"start": 2005, "end": 2024, "interval": 1}, }, + pre_hook="DROP ALL ROW ACCESS POLICIES ON {{ this }}", + post_hook=[ + 'CREATE OR REPLACE ROW ACCESS POLICY allusers_filter ON {{this}} GRANT TO ("allUsers") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) > 6)', + 'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter ON {{this}} GRANT TO ("group:bd-pro@basedosdados.org", "group:sudo@basedosdados.org") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', + ], ) }} with diff --git a/models/br_ms_cnes/br_ms_cnes__equipamento.sql b/models/br_ms_cnes/br_ms_cnes__equipamento.sql index 6c0ccf88..b7bdaa73 100644 --- a/models/br_ms_cnes/br_ms_cnes__equipamento.sql +++ b/models/br_ms_cnes/br_ms_cnes__equipamento.sql @@ -8,6 +8,11 @@ "data_type": "int64", "range": {"start": 2005, "end": 2024, "interval": 1}, }, + pre_hook="DROP ALL ROW ACCESS POLICIES ON {{ this }}", + post_hook=[ + 'CREATE OR REPLACE ROW ACCESS POLICY allusers_filter ON {{this}} GRANT TO ("allUsers") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) > 6)', + 'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter ON {{this}} GRANT TO ("group:bd-pro@basedosdados.org", "group:sudo@basedosdados.org") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', + ], ) }} diff --git a/models/br_ms_cnes/br_ms_cnes__equipe.sql b/models/br_ms_cnes/br_ms_cnes__equipe.sql index bcb743bf..0a9a114d 100644 --- a/models/br_ms_cnes/br_ms_cnes__equipe.sql +++ b/models/br_ms_cnes/br_ms_cnes__equipe.sql @@ -8,6 +8,11 @@ "data_type": "int64", "range": {"start": 2005, "end": 2024, "interval": 1}, }, + pre_hook="DROP ALL ROW ACCESS POLICIES ON {{ this }}", + post_hook=[ + 'CREATE OR REPLACE ROW ACCESS POLICY allusers_filter ON {{this}} GRANT TO ("allUsers") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) > 6)', + 'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter ON {{this}} GRANT TO ("group:bd-pro@basedosdados.org", "group:sudo@basedosdados.org") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', + ], ) }} diff --git a/models/br_ms_cnes/br_ms_cnes__estabelecimento.sql b/models/br_ms_cnes/br_ms_cnes__estabelecimento.sql index 761eac6e..87066e6e 100644 --- a/models/br_ms_cnes/br_ms_cnes__estabelecimento.sql +++ b/models/br_ms_cnes/br_ms_cnes__estabelecimento.sql @@ -8,6 +8,11 @@ "data_type": "int64", "range": {"start": 2005, "end": 2024, "interval": 1}, }, + pre_hook="DROP ALL ROW ACCESS POLICIES ON {{ this }}", + post_hook=[ + 'CREATE OR REPLACE ROW ACCESS POLICY allusers_filter ON {{this}} GRANT TO ("allUsers") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) > 6)', + 'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter ON {{this}} GRANT TO ("group:bd-pro@basedosdados.org", "group:sudo@basedosdados.org") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', + ], ) }} with diff --git a/models/br_ms_cnes/br_ms_cnes__estabelecimento_ensino.sql b/models/br_ms_cnes/br_ms_cnes__estabelecimento_ensino.sql index 2f4b3dc4..df5900ec 100644 --- a/models/br_ms_cnes/br_ms_cnes__estabelecimento_ensino.sql +++ b/models/br_ms_cnes/br_ms_cnes__estabelecimento_ensino.sql @@ -8,6 +8,11 @@ "data_type": "int64", "range": {"start": 2005, "end": 2024, "interval": 1}, }, + pre_hook="DROP ALL ROW ACCESS POLICIES ON {{ this }}", + post_hook=[ + 'CREATE OR REPLACE ROW ACCESS POLICY allusers_filter ON {{this}} GRANT TO ("allUsers") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) > 6)', + 'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter ON {{this}} GRANT TO ("group:bd-pro@basedosdados.org", "group:sudo@basedosdados.org") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', + ], ) }} with diff --git a/models/br_ms_cnes/br_ms_cnes__estabelecimento_filantropico.sql b/models/br_ms_cnes/br_ms_cnes__estabelecimento_filantropico.sql index de2afec7..313a3b9a 100644 --- a/models/br_ms_cnes/br_ms_cnes__estabelecimento_filantropico.sql +++ b/models/br_ms_cnes/br_ms_cnes__estabelecimento_filantropico.sql @@ -8,6 +8,16 @@ "data_type": "int64", "range": {"start": 2005, "end": 2024, "interval": 1}, }, + pre_hook="DROP ALL ROW ACCESS POLICIES ON {{ this }}", + post_hook=[ + 'CREATE OR REPLACE ROW ACCESS POLICY allusers_filter ON {{this}} GRANT TO ("allUsers") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) > 6)', + 'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter ON {{this}} GRANT TO ("group:bd-pro@basedosdados.org", "group:sudo@basedosdados.org") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', + ], + pre_hook="DROP ALL ROW ACCESS POLICIES ON {{ this }}", + post_hook=[ + 'CREATE OR REPLACE ROW ACCESS POLICY allusers_filter ON {{this}} GRANT TO ("allUsers") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) > 6)', + 'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter ON {{this}} GRANT TO ("group:bd-pro@basedosdados.org", "group:sudo@basedosdados.org") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', + ], ) }} with diff --git a/models/br_ms_cnes/br_ms_cnes__gestao_metas.sql b/models/br_ms_cnes/br_ms_cnes__gestao_metas.sql index da4ebe60..14909c95 100644 --- a/models/br_ms_cnes/br_ms_cnes__gestao_metas.sql +++ b/models/br_ms_cnes/br_ms_cnes__gestao_metas.sql @@ -8,6 +8,11 @@ "data_type": "int64", "range": {"start": 2005, "end": 2024, "interval": 1}, }, + pre_hook="DROP ALL ROW ACCESS POLICIES ON {{ this }}", + post_hook=[ + 'CREATE OR REPLACE ROW ACCESS POLICY allusers_filter ON {{this}} GRANT TO ("allUsers") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) > 6)', + 'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter ON {{this}} GRANT TO ("group:bd-pro@basedosdados.org", "group:sudo@basedosdados.org") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', + ], ) }} with diff --git a/models/br_ms_cnes/br_ms_cnes__habilitacao.sql b/models/br_ms_cnes/br_ms_cnes__habilitacao.sql index 8ae30eb4..ded43aef 100644 --- a/models/br_ms_cnes/br_ms_cnes__habilitacao.sql +++ b/models/br_ms_cnes/br_ms_cnes__habilitacao.sql @@ -8,6 +8,11 @@ "data_type": "int64", "range": {"start": 2005, "end": 2024, "interval": 1}, }, + pre_hook="DROP ALL ROW ACCESS POLICIES ON {{ this }}", + post_hook=[ + 'CREATE OR REPLACE ROW ACCESS POLICY allusers_filter ON {{this}} GRANT TO ("allUsers") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) > 6)', + 'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter ON {{this}} GRANT TO ("group:bd-pro@basedosdados.org", "group:sudo@basedosdados.org") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', + ], ) }} with diff --git a/models/br_ms_cnes/br_ms_cnes__incentivos.sql b/models/br_ms_cnes/br_ms_cnes__incentivos.sql index 5ef1e14d..2742aaa8 100644 --- a/models/br_ms_cnes/br_ms_cnes__incentivos.sql +++ b/models/br_ms_cnes/br_ms_cnes__incentivos.sql @@ -8,6 +8,11 @@ "data_type": "int64", "range": {"start": 2005, "end": 2024, "interval": 1}, }, + pre_hook="DROP ALL ROW ACCESS POLICIES ON {{ this }}", + post_hook=[ + 'CREATE OR REPLACE ROW ACCESS POLICY allusers_filter ON {{this}} GRANT TO ("allUsers") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) > 6)', + 'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter ON {{this}} GRANT TO ("group:bd-pro@basedosdados.org", "group:sudo@basedosdados.org") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', + ], ) }} with diff --git a/models/br_ms_cnes/br_ms_cnes__leito.sql b/models/br_ms_cnes/br_ms_cnes__leito.sql index 87677429..eda01dbd 100644 --- a/models/br_ms_cnes/br_ms_cnes__leito.sql +++ b/models/br_ms_cnes/br_ms_cnes__leito.sql @@ -8,6 +8,11 @@ "data_type": "int64", "range": {"start": 2007, "end": 2024, "interval": 1}, }, + pre_hook="DROP ALL ROW ACCESS POLICIES ON {{ this }}", + post_hook=[ + 'CREATE OR REPLACE ROW ACCESS POLICY allusers_filter ON {{this}} GRANT TO ("allUsers") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) > 6)', + 'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter ON {{this}} GRANT TO ("group:bd-pro@basedosdados.org", "group:sudo@basedosdados.org") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', + ], ) }} diff --git a/models/br_ms_cnes/br_ms_cnes__profissional.sql b/models/br_ms_cnes/br_ms_cnes__profissional.sql index ddb3fcd9..ee4289c2 100644 --- a/models/br_ms_cnes/br_ms_cnes__profissional.sql +++ b/models/br_ms_cnes/br_ms_cnes__profissional.sql @@ -8,6 +8,11 @@ "data_type": "int64", "range": {"start": 2005, "end": 2024, "interval": 1}, }, + pre_hook="DROP ALL ROW ACCESS POLICIES ON {{ this }}", + post_hook=[ + 'CREATE OR REPLACE ROW ACCESS POLICY allusers_filter ON {{this}} GRANT TO ("allUsers") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) > 6)', + 'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter ON {{this}} GRANT TO ("group:bd-pro@basedosdados.org", "group:sudo@basedosdados.org") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', + ], ) }} with diff --git a/models/br_ms_cnes/br_ms_cnes__regra_contratual.sql b/models/br_ms_cnes/br_ms_cnes__regra_contratual.sql index e96282f7..026ffc5e 100644 --- a/models/br_ms_cnes/br_ms_cnes__regra_contratual.sql +++ b/models/br_ms_cnes/br_ms_cnes__regra_contratual.sql @@ -8,6 +8,11 @@ "data_type": "int64", "range": {"start": 2005, "end": 2024, "interval": 1}, }, + pre_hook="DROP ALL ROW ACCESS POLICIES ON {{ this }}", + post_hook=[ + 'CREATE OR REPLACE ROW ACCESS POLICY allusers_filter ON {{this}} GRANT TO ("allUsers") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) > 6)', + 'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter ON {{this}} GRANT TO ("group:bd-pro@basedosdados.org", "group:sudo@basedosdados.org") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', + ], ) }} with diff --git a/models/br_ms_cnes/br_ms_cnes__servico_especializado.sql b/models/br_ms_cnes/br_ms_cnes__servico_especializado.sql index 0aaecd4a..7001f75b 100644 --- a/models/br_ms_cnes/br_ms_cnes__servico_especializado.sql +++ b/models/br_ms_cnes/br_ms_cnes__servico_especializado.sql @@ -8,6 +8,11 @@ "data_type": "int64", "range": {"start": 2005, "end": 2024, "interval": 1}, }, + pre_hook="DROP ALL ROW ACCESS POLICIES ON {{ this }}", + post_hook=[ + 'CREATE OR REPLACE ROW ACCESS POLICY allusers_filter ON {{this}} GRANT TO ("allUsers") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) > 6)', + 'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter ON {{this}} GRANT TO ("group:bd-pro@basedosdados.org", "group:sudo@basedosdados.org") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', + ], ) }} with From 37e4c7e20a7f6c739bea85533a32abde6c999466 Mon Sep 17 00:00:00 2001 From: uiro-bi Date: Mon, 27 May 2024 08:13:00 -0300 Subject: [PATCH 2/2] feat: make requested changes --- .../br_ms_cnes/br_ms_cnes__estabelecimento_filantropico.sql | 6 ------ 1 file changed, 6 deletions(-) diff --git a/models/br_ms_cnes/br_ms_cnes__estabelecimento_filantropico.sql b/models/br_ms_cnes/br_ms_cnes__estabelecimento_filantropico.sql index 313a3b9a..ef7dfbd8 100644 --- a/models/br_ms_cnes/br_ms_cnes__estabelecimento_filantropico.sql +++ b/models/br_ms_cnes/br_ms_cnes__estabelecimento_filantropico.sql @@ -13,12 +13,6 @@ 'CREATE OR REPLACE ROW ACCESS POLICY allusers_filter ON {{this}} GRANT TO ("allUsers") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) > 6)', 'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter ON {{this}} GRANT TO ("group:bd-pro@basedosdados.org", "group:sudo@basedosdados.org") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', ], - pre_hook="DROP ALL ROW ACCESS POLICIES ON {{ this }}", - post_hook=[ - 'CREATE OR REPLACE ROW ACCESS POLICY allusers_filter ON {{this}} GRANT TO ("allUsers") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) > 6)', - 'CREATE OR REPLACE ROW ACCESS POLICY bdpro_filter ON {{this}} GRANT TO ("group:bd-pro@basedosdados.org", "group:sudo@basedosdados.org") FILTER USING (DATE_DIFF(DATE("{{ run_started_at.strftime("%Y-%m-%d") }}"),DATE(CAST(ano AS INT64),CAST(mes AS INT64),1), MONTH) <= 6)', - ], - ) }} with raw_cnes_estabelecimento_filantropico as (