Skip to content

Commit

Permalink
chore: [PAGOPA-1814] Global index tables (#2122)
Browse files Browse the repository at this point in the history
* improvements

* Revert "improvements"

This reverts commit 367d041.

* added new tables to manage global indexes

* fix liquibase

* fix liquibase

* updated procedure
  • Loading branch information
aomegax authored Jun 21, 2024
1 parent f43b168 commit 64c7c21
Show file tree
Hide file tree
Showing 6 changed files with 293 additions and 63 deletions.
150 changes: 87 additions & 63 deletions .devops/nodo-db-schema-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,80 +248,104 @@ stages:
l_exist text;
l_var_exist integer;
loop_counter INTEGER;
tab_cursor CURSOR FOR
SELECT lower(tabella) as tabella, lower(schema) as schema, lower(prefisso_nome_indice) as prefisso_indice, lower(campi_indice) as campi_indice
FROM $PARTITION_SCHEMA.TAB_PART;
start_partition date;
ptDataInizio timestamp := clock_timestamp();
ptDataInizioStep timestamp;
iIdTrace NUMERIC;
sUtente TEXT := USER;
tLabelStep TEXT;
tProcedureName TEXT:= 'modify_partition';
tab_cursor CURSOR FOR
SELECT lower(tabella) as tabella, lower(schema) as schema, lower(prefisso_nome_indice) as prefisso_indice, lower(campi_indice) as campi_indice
FROM partition.TAB_PART;
tab_record TEXT;
tab_schema TEXT;
BEGIN
BEGIN
tLabelStep := 'Init';
iIdTrace := nextval('seq_log'::regclass);
INSERT INTO PG_LOG values (iIdTrace,sUtente, tProcedureName, ptDataInizio, clock_timestamp(), (clock_timestamp()- ptDataInizio) ,'OK','INIZIO',tLabelStep);
IF A is null
THEN A=1;
END IF;
IF A is null
THEN A=1;
END IF;
FOR loop_counter in 0..a
LOOP
for loop_counter in 0..a loop
OPEN tab_cursor;
LOOP
FETCH NEXT FROM tab_cursor INTO tab_record, tab_schema,l_prefisso_indice, l_campi_indice;
EXIT WHEN NOT FOUND;
------------------------------------------------------------------------------------------------------
IF loop_counter=0 THEN
L_PART_LIST = DATE_TRUNC('DAY', CURRENT_DATE+loop_counter-1500)::DATE;
L_PART_LISTB = DATE_TRUNC('DAY', CURRENT_DATE+loop_counter+1)::DATE;
L_PARTNAME := TAB_RECORD||'_PMINVALUE';
ELSE
L_PART_LIST = date_trunc('day', CURRENT_DATE+loop_counter)::date;
L_PART_LISTB = date_trunc('day', CURRENT_DATE+loop_counter+1)::date;
L_PARTNAME := tab_record||'_P'||to_char(CURRENT_DATE+loop_counter, 'yyyymmdd');
END IF;
L_INDEX_NAME := l_prefisso_indice||'_'||L_PARTNAME;
IF NOT EXISTS
( SELECT 1
FROM information_schema.tables
WHERE table_name=l_partname and table_schema=tab_schema
union all
SELECT 1
FROM pg_inherits
JOIN pg_class parent ON pg_inherits.inhparent = parent.oid
JOIN pg_class child ON pg_inherits.inhrelid = child.oid
JOIN pg_namespace nmsp_parent ON nmsp_parent.oid = parent.relnamespace
JOIN pg_namespace nmsp_child ON nmsp_child.oid = child.relnamespace
WHERE child.relname=l_partname and nmsp_child.nspname =tab_schema
)
THEN
l_sql := format('CREATE TABLE %I.%I PARTITION OF %I.%I FOR VALUES FROM (%L) TO (%L)', tab_schema, l_partname, tab_schema, tab_record, l_part_list, l_part_listb);
execute l_sql;
END IF;
IF NOT EXISTS
(SELECT *
FROM pg_stat_all_indexes
WHERE indexrelname=L_INDEX_NAME and schemaname=tab_schema)
THEN
if l_campi_indice is not null then
l_sql := format('CREATE UNIQUE INDEX %I ON %I.%I USING BTREE(%s)', L_INDEX_NAME, tab_schema, l_partname, l_campi_indice);
execute l_sql;
END IF;
END IF;
------------------------------------------------------------------------------------------------------
END LOOP;
CLOSE tab_cursor;
LOOP
FETCH NEXT FROM tab_cursor INTO tab_record, tab_schema,l_prefisso_indice, l_campi_indice;
EXIT WHEN NOT FOUND;
------------------------------------------------------------------------------------------------------
IF loop_counter=0 THEN
L_PART_LIST = DATE_TRUNC('DAY', CURRENT_DATE+loop_counter-1500)::DATE;
L_PART_LISTB = DATE_TRUNC('DAY', CURRENT_DATE+loop_counter+1)::DATE;
L_PARTNAME := TAB_RECORD||'_PMINVALUE';
ELSE
L_PART_LIST = date_trunc('day', CURRENT_DATE+loop_counter)::date;
L_PART_LISTB = date_trunc('day', CURRENT_DATE+loop_counter+1)::date;
L_PARTNAME := tab_record||'_P'||to_char(CURRENT_DATE+loop_counter, 'yyyymmdd');
END IF;
L_INDEX_NAME := l_prefisso_indice||'_'||L_PARTNAME;
IF NOT EXISTS
( SELECT 1
FROM information_schema.tables
WHERE table_name=l_partname and table_schema=tab_schema
union all
SELECT
1
FROM pg_inherits
JOIN pg_class parent ON pg_inherits.inhparent = parent.oid
JOIN pg_class child ON pg_inherits.inhrelid = child.oid
JOIN pg_namespace nmsp_parent ON nmsp_parent.oid = parent.relnamespace
JOIN pg_namespace nmsp_child ON nmsp_child.oid = child.relnamespace
WHERE child.relname=l_partname and nmsp_child.nspname =tab_schema
)
THEN
l_sql := format('CREATE TABLE %I.%I PARTITION OF %I.%I FOR VALUES FROM (%L) TO (%L)', tab_schema, l_partname, tab_schema, tab_record, l_part_list, l_part_listb);
execute l_sql;
END IF;
IF NOT EXISTS
(SELECT *
FROM pg_stat_all_indexes
WHERE indexrelname=L_INDEX_NAME and schemaname=tab_schema)
THEN
if l_campi_indice is not null then
l_sql := format('CREATE UNIQUE INDEX %I ON %I.%I USING BTREE(%s)', L_INDEX_NAME, tab_schema, l_partname, l_campi_indice);
execute l_sql;
end if;
END IF;
------------------------------------------------------------------------------------------------------
END LOOP;
CLOSE tab_cursor;
END LOOP;
l_sql := format('GRANT SELECT ON ALL TABLES IN SCHEMA online TO offline;');
execute l_sql;
iIdTrace := nextval('seq_log'::regclass);
INSERT INTO PG_LOG values (iIdTrace,sUtente, tProcedureName, ptDataInizio, clock_timestamp(), (clock_timestamp()- ptDataInizio) ,'OK','FINE','Procedura eseguita con successo');
EXCEPTION
WHEN OTHERS THEN
iIdTrace := nextval('seq_log'::regclass);
INSERT INTO PG_LOG values (iIdTrace,sUtente, tProcedureName, ptDataInizio, clock_timestamp(), ( clock_timestamp()- ptDataInizio) ,'KO','FINE',
CONCAT('Step:',tLabelStep,' , sqlerrm : ',sqlerrm));
END;
\$BODY\$;
ALTER PROCEDURE $PARTITION_SCHEMA.modify_partition(integer) OWNER TO $PARTITION_USERNAME;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd
http://www.liquibase.org/xml/ns/pro
http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.1.xsd">

<!-- <changeSet author="liquibase" id="20240610000000-1">-->
<!-- <createTable tableName="ELENCO_SERVIZI_PSP_GI">-->
<!-- <column name="ID" type="NUMBER">-->
<!-- <constraints nullable="false" primaryKey="true" primaryKeyName="esp_gi_pk"/>-->
<!-- </column>-->
<!-- <column name="FK_SNAPSHOT_VERSION" type="NUMBER(19, 0)">-->
<!-- <constraints nullable="false" primaryKey="true" primaryKeyName="esp_gi_pk"/>-->
<!-- </column>-->
<!-- </createTable>-->
<!-- </changeSet>-->

<!-- <changeSet author="liquibase" id="20240610000000-2">-->
<!-- <createTable tableName="ELENCO_SERVIZI_PSP_SYNC_STATUS_GI">-->
<!-- <column name="SNAPSHOT_VERSION" type="NUMBER(19, 0)">-->
<!-- <constraints nullable="false" primaryKey="true" primaryKeyName="espss_gi_pk"/>-->
<!-- </column>-->
<!-- </createTable>-->
<!-- </changeSet>-->

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
<include file="./db.changelog-master-3.25.0.xml"/>

<include file="./${version}/db.changelog-20240318000000_partizionamento.xml" labels="${version}"/>
<include file="./${version}/db.changelog-20240610000000_global_index.xml" labels="${version}"/>

</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd
http://www.liquibase.org/xml/ns/pro
http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.1.xsd">

<!-- <changeSet author="liquibase" id="20240610000000-1">-->
<!-- <createTable tableName="VERIFICA_BOLLETTINO_GI">-->
<!-- <column name="NOTICE_ID" type="VARCHAR2(50)">-->
<!-- <constraints nullable="false" primaryKey="true" primaryKeyName="vb_gi_pk"/>-->
<!-- </column>-->
<!-- <column name="PA_FISCAL_CODE" type="VARCHAR2(50)">-->
<!-- <constraints nullable="false" primaryKey="true" primaryKeyName="vb_gi_pk"/>-->
<!-- </column>-->
<!-- </createTable>-->
<!-- </changeSet>-->

<changeSet author="liquibase" id="20240610000000-1">
<createTable tableName="STATI_CARRELLO_SNAPSHOT_GI">
<column name="ID_CARRELLO" type="VARCHAR2(35)">
<constraints nullable="false" primaryKey="true" primaryKeyName="scs_gi_pk"/>
</column>
<column name="INSERTED_TIMESTAMP" type="TIMESTAMP(6)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>

<changeSet author="liquibase" id="20240610000000-2">
<createTable tableName="RPT_GI">
<column name="IDENT_DOMINIO" type="VARCHAR2(35)">
<constraints nullable="false" primaryKey="true" primaryKeyName="rpt_gi_pk"/>
</column>
<column name="IUV" type="VARCHAR2(35)">
<constraints nullable="false" primaryKey="true" primaryKeyName="rpt_gi_pk"/>
</column>
<column name="CCP" type="VARCHAR2(35)">
<constraints nullable="false" primaryKey="true" primaryKeyName="rpt_gi_pk"/>
</column>
<column name="INSERTED_TIMESTAMP" type="TIMESTAMP(6)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>

<changeSet author="liquibase" id="20240610000000-3">
<createTable tableName="RT_GI">
<column name="IDENT_DOMINIO" type="VARCHAR2(35)">
<constraints nullable="false" primaryKey="true" primaryKeyName="rt_gi_pk"/>
</column>
<column name="IUV" type="VARCHAR2(35)">
<constraints nullable="false" primaryKey="true" primaryKeyName="rt_gi_pk"/>
</column>
<column name="CCP" type="VARCHAR2(35)">
<constraints nullable="false" primaryKey="true" primaryKeyName="rt_gi_pk"/>
</column>
<column name="INSERTED_TIMESTAMP" type="TIMESTAMP(6)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>

<changeSet author="liquibase" id="20240610000000-4">
<createTable tableName="POSITION_SERVICE_GI">
<column name="PA_FISCAL_CODE" type="VARCHAR2(50)">
<constraints nullable="true" primaryKey="true" primaryKeyName="ps_gi_pk"/>
</column>
<column name="NOTICE_ID" type="VARCHAR2(50)">
<constraints nullable="true" primaryKey="true" primaryKeyName="ps_gi_pk"/>
</column>
<column name="INSERTED_TIMESTAMP" type="TIMESTAMP(6)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>

<changeSet author="liquibase" id="20240610000000-5">
<createTable tableName="STATI_RPT_SNAPSHOT_GI">
<column name="ID_DOMINIO" type="VARCHAR2(35)">
<constraints nullable="false" primaryKey="true" primaryKeyName="sps_gi_pk"/>
</column>
<column name="IUV" type="VARCHAR2(35)">
<constraints nullable="false" primaryKey="true" primaryKeyName="sps_gi_pk"/>
</column>
<column name="CCP" type="VARCHAR2(35)">
<constraints nullable="false" primaryKey="true" primaryKeyName="sps_gi_pk"/>
</column>
<column name="INSERTED_TIMESTAMP" type="TIMESTAMP(6)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>

<!-- <changeSet author="liquibase" id="20240610000000-6">-->
<!-- <createTable tableName="RPT_SOGGETTI_GI">-->
<!-- <column name="RPT_ID" type="NUMBER(19, 0)">-->
<!-- <constraints nullable="false" primaryKey="true" primaryKeyName="rs_gi_pk"/>-->
<!-- </column>-->
<!-- <column name="TIPO_SOGGETTO" type="CHAR(1)">-->
<!-- <constraints nullable="false" primaryKey="true" primaryKeyName="rs_gi_pk"/>-->
<!-- </column>-->
<!-- <column name="INSERTED_TIMESTAMP" type="TIMESTAMP(6)">-->
<!-- <constraints nullable="false"/>-->
<!-- </column>-->
<!-- </createTable>-->
<!-- </changeSet>-->

<changeSet author="liquibase" id="20240610000000-7">
<createTable tableName="RETRY_PA_INVIA_RT_GI">
<column name="ID_DOMINIO" type="VARCHAR2(35)">
<constraints nullable="false" primaryKey="true" primaryKeyName="rpir_gi_pk"/>
</column>
<column name="IUV" type="VARCHAR2(35)">
<constraints nullable="false" primaryKey="true" primaryKeyName="rpir_gi_pk"/>
</column>
<column name="CCP" type="VARCHAR2(35)">
<constraints nullable="false" primaryKey="true" primaryKeyName="rpir_gi_pk"/>
</column>
<column name="INSERTED_TIMESTAMP" type="TIMESTAMP(6)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
<include file="./db.changelog-master-3.25.0.xml"/>

<include file="./${version}/db.changelog-20240318000000_partizionamento.xml" labels="${version}"/>
<include file="./${version}/db.changelog-20240610000000_global_index.xml" labels="${version}"/>

</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd
http://www.liquibase.org/xml/ns/pro
http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.1.xsd">

<changeSet author="liquibase" id="20240610000000-1">
<createTable tableName="RPT_GI">
<column name="CODICE_CARRELLO" type="VARCHAR2(128)">
<constraints nullable="false" primaryKey="true" primaryKeyName="r_gi_pk"/>
</column>
<column name="PSP" type="VARCHAR2(35)">
<constraints nullable="false" primaryKey="true" primaryKeyName="r_gi_pk"/>
</column>
<column name="PARAMETRI_PAGAMENTO_IMMEDIATO" type="VARCHAR2(255)">
<constraints nullable="false" primaryKey="true" primaryKeyName="r_gi_pk"/>
</column>
<column name="INSERTED_TIMESTAMP" type="TIMESTAMP(6)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>

<changeSet author="liquibase" id="20240610000000-2">
<createTable tableName="CARRELLO_RPT_GI">
<column name="CODICE_CARRELLO" type="VARCHAR2(128 )">
<constraints nullable="false" primaryKey="true" primaryKeyName="cr_gi_pk"/>
</column>
<column name="PSP" type="VARCHAR2(35 )">
<constraints nullable="false" primaryKey="true" primaryKeyName="cr_gi_pk"/>
</column>
<column name="PARAMETRI_PAGAMENTO_IMMEDIATO" type="VARCHAR2(255)">
<constraints nullable="false" primaryKey="true" primaryKeyName="cr_gi_pk"/>
</column>
<column name="INSERTED_TIMESTAMP" type="TIMESTAMP(6)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>

</databaseChangeLog>

0 comments on commit 64c7c21

Please sign in to comment.