sistemata migration
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good

This commit is contained in:
2025-10-07 14:56:34 +02:00
parent 3c79fb6745
commit 63cf1920a9
2 changed files with 204 additions and 43 deletions

View File

@@ -1,7 +1,12 @@
package it.integry.ems.migration.model;
import it.integry.ems.migration._base.BaseMigration;
import it.integry.ems.migration._base.IntegryCustomer;
import it.integry.ems.migration._base.MigrationModelInterface;
import it.integry.ems_model.utility.dto.IndexTableDTO;
import java.util.ArrayList;
import java.util.List;
public class Migration_20250929172222 extends BaseMigration implements MigrationModelInterface {
@@ -10,11 +15,148 @@ public class Migration_20250929172222 extends BaseMigration implements Migration
if (isHistoryDB())
return;
executeStatement("DROP INDEX [ix_stb_activity_raplav] ON [dbo].[stb_activity] ",
"DROP INDEX [ix[stb_activity_effective_date] ON [dbo].[stb_activity] ",
"DROP INDEX [ix_activity_effective] ON [dbo].[stb_activity] ",
"DROP INDEX [ix_activity_estimate] ON [dbo].[stb_activity] ",
"DROP INDEX [ix_stb_activity_alarm] ON [dbo].[stb_activity] ",
if (isCustomer(IntegryCustomer.Idrotecnica) || isCustomer(IntegryCustomer.Sabato) || isCustomer(IntegryCustomer.Ime) || isCustomer(IntegryCustomer.Materica)) {
executeStatement("CREATE TABLE dbo.stb_activity_new\n" +
"(\n" +
" activity_id VARCHAR(15) NOT NULL\n" +
" CONSTRAINT pk_stb_activity_new\n" +
" PRIMARY KEY NONCLUSTERED\n" +
" WITH (FILLFACTOR = 90),\n" +
" data_ins_act DATETIME NOT NULL,\n" +
" activity_type_id VARCHAR(40) NOT NULL,\n" +
" activity_description VARCHAR(1024),\n" +
" parent_activity_id VARCHAR(15),\n" +
" user_name VARCHAR(40) NOT NULL\n" +
" CONSTRAINT fk_stb_activity_new_stb_user\n" +
" REFERENCES dbo.stb_user,\n" +
" tipo_anag VARCHAR,\n" +
" cod_anag VARCHAR(15),\n" +
" estimated_date DATETIME,\n" +
" estimated_time DATETIME,\n" +
" alarm_date DATETIME,\n" +
" alarm_time DATETIME,\n" +
" effective_date DATETIME,\n" +
" effective_time DATETIME,\n" +
" activity_result_id VARCHAR(15)\n" +
" CONSTRAINT fk_stb_activity_new_stb_activity_new_res\n" +
" REFERENCES dbo.stb_activity_result,\n" +
" result_description VARCHAR(1024),\n" +
" estimated_enddate DATETIME,\n" +
" estimated_endtime DATETIME,\n" +
" effective_enddate DATETIME,\n" +
" effective_endtime DATETIME,\n" +
" cod_jcom VARCHAR(10)\n" +
" CONSTRAINT fk_stb_activity_new_jtb_comt\n" +
" REFERENCES dbo.jtb_comt,\n" +
" user_creator VARCHAR(40),\n" +
" cod_jfas VARCHAR(5) DEFAULT NULL\n" +
" CONSTRAINT fk_stb_activity_new_jtb_fasi\n" +
" REFERENCES dbo.jtb_fasi,\n" +
" perc_comp NUMERIC(15, 5)\n" +
" DEFAULT 0 NOT NULL,\n" +
" estimated_hours NUMERIC(15, 5)\n" +
" DEFAULT 0 NOT NULL,\n" +
" cod_mart VARCHAR(15)\n" +
" CONSTRAINT fk_stb_activity_new_mtb_aart\n" +
" REFERENCES dbo.mtb_aart,\n" +
" matricola VARCHAR(20)\n" +
" CONSTRAINT fk_stb_activity_new_matricola\n" +
" REFERENCES dbo.vtb_amac,\n" +
" priorita INT,\n" +
" activity_play_counter NUMERIC(20, 5) DEFAULT 0 NOT NULL,\n" +
" flag_tipologia VARCHAR NOT NULL,\n" +
" activity_event VARCHAR(1024),\n" +
" guarantee VARCHAR,\n" +
" note VARCHAR(1024),\n" +
" rfid VARCHAR(40),\n" +
" id_lotto INT,\n" +
" persona_rif VARCHAR(40),\n" +
" hr_num INT,\n" +
" gestione VARCHAR,\n" +
" data_ord DATETIME,\n" +
" num_ord INT,\n" +
" id_step INT,\n" +
" id_riga INT,\n" +
" ora_ins_act DATETIME,\n" +
" indice_gradimento NUMERIC(20, 5) DEFAULT 0,\n" +
" note_gradimento VARCHAR(8000),\n" +
" flag_risolto VARCHAR DEFAULT 'N',\n" +
" user_modifier VARCHAR(40),\n" +
" ora_mod_act DATETIME,\n" +
" ora_view_act DATETIME,\n" +
" cod_vdes VARCHAR(5),\n" +
" partita_mag VARCHAR(20),\n" +
" cod_cmac VARCHAR(20),\n" +
" wrike_id VARCHAR(8000),\n" +
" cod_mgrp VARCHAR(5)\n" +
" CONSTRAINT stb_activity_new_mtb_grup_cod_mgrp_fk\n" +
" REFERENCES dbo.mtb_grup,\n" +
" plan_id BIGINT\n" +
" CONSTRAINT fk_stb_activity_new_stb_activity_new_plan\n" +
" REFERENCES dbo.stb_activity_plan,\n" +
" id_posizione BIGINT\n" +
" CONSTRAINT fk_stb_activity_new_stb_posizioni\n" +
" REFERENCES dbo.stb_posizioni,\n" +
" CONSTRAINT fk_stb_activity_new_tipologia\n" +
" FOREIGN KEY (activity_type_id, flag_tipologia) REFERENCES dbo.stb_activity_type\n" +
")\n"
,
"CREATE INDEX ix_activity_effective\n" +
" ON dbo.stb_activity_new (activity_id, effective_date, effective_time, effective_enddate, effective_endtime)\n" +
" WITH (FILLFACTOR = 90)\n" ,
"CREATE INDEX ix_activity_estimate\n" +
" ON dbo.stb_activity_new (activity_id, estimated_date, estimated_time, estimated_enddate, estimated_endtime)\n" +
" WITH (FILLFACTOR = 90)\n" ,
"CREATE INDEX ix_activity_result_id\n" +
" ON dbo.stb_activity_new (activity_result_id)\n" +
" WITH (FILLFACTOR = 90)\n" ,
"CREATE INDEX ix_activity_type_id\n" +
" ON dbo.stb_activity_new (activity_type_id, flag_tipologia)\n" +
" WITH (FILLFACTOR = 90)\n" ,
"CREATE INDEX ix_stb_activity_new_cod_jcom\n" +
" ON dbo.stb_activity_new (cod_jcom)\n" +
" WITH (FILLFACTOR = 90)\n",
"CREATE INDEX ix_stb_activity_new_cod_jfas\n" +
" ON dbo.stb_activity_new (cod_jfas)\n" +
" WITH (FILLFACTOR = 90)\n" ,
"CREATE INDEX ix_stb_activity_new_cod_mart\n" +
" ON dbo.stb_activity_new (cod_mart)\n" +
" WITH (FILLFACTOR = 90)\n",
"CREATE INDEX ix_stb_activity_new_parent_activity_id\n" +
" ON dbo.stb_activity_new (parent_activity_id)\n" +
" WITH (FILLFACTOR = 90)\n",
"CREATE INDEX ix_stb_activity_new_stb_activity_new\n" +
" ON dbo.stb_activity_new (parent_activity_id)\n" +
" WITH (FILLFACTOR = 90)\n" ,
"CREATE INDEX ix_stb_activity_new_stb_activity_new_res\n" +
" ON dbo.stb_activity_new (activity_result_id)\n" +
" WITH (FILLFACTOR = 90)\n",
"CREATE INDEX ix_stb_activity_new_stb_user\n" +
" ON dbo.stb_activity_new (user_name)\n" +
" WITH (FILLFACTOR = 90)\n" ,
"CREATE INDEX ix_stb_activity_new_user_name\n" +
" ON dbo.stb_activity_new (user_name)\n" +
" WITH (FILLFACTOR = 90)\n" ,
"CREATE INDEX ix_stb_activivty_priorita\n" +
" ON dbo.stb_activity_new (priorita)\n" +
" WITH (FILLFACTOR = 90)\n" ,
"CREATE INDEX stb_activity_new\n" +
" ON dbo.stb_activity_new (activity_type_id)\n" +
" WITH (FILLFACTOR = 90)\n" ,
"insert into stb_activity_new " +
"select * from stb_activity",
"EXEC sp_rename 'dbo.stb_activity', 'stb_activity_old';",
"EXEC sp_rename 'dbo.stb_activity_new', 'stb_activity';"
);
}
dropIndex("stb_activity", "ix_stb_activity_raplav");
dropIndex("stb_activity", "ix_stb_activity_effective_date");
dropIndex("stb_activity", "ix_activity_effective");
dropIndex("stb_activity", "ix_activity_estimate");
dropIndex("stb_activity", "ix_stb_activity_alarm");
executeStatement(
"alter table stb_activity drop column data_ins_act ",
"alter table stb_activity drop column estimated_date ",
"alter table stb_activity drop column alarm_date ",
@@ -26,42 +168,62 @@ public class Migration_20250929172222 extends BaseMigration implements Migration
"alter table stb_activity add alarm_date as cast(alarm_time as date) ",
"alter table stb_activity add effective_date as cast(effective_time as date) ",
"alter table stb_activity add estimated_enddate as cast(estimated_endtime as date) ",
"alter table stb_activity add effective_enddate as cast(effective_endtime as date) ",
"CREATE NONCLUSTERED INDEX [ix_stb_activity_alarm] ON [dbo].[stb_activity] " +
"( " +
" " +
" [alarm_time] ASC, " +
" [alarm_date] ASC " +
") " ,
"CREATE NONCLUSTERED INDEX [ix_activity_estimate] ON [dbo].[stb_activity] " +
"( " +
" [activity_id] ASC, " +
" [estimated_date] ASC, " +
" [estimated_time] ASC, " +
" [estimated_enddate] ASC, " +
" [estimated_endtime] ASC " +
") " ,
"CREATE NONCLUSTERED INDEX [ix_activity_effective] ON [dbo].[stb_activity] " +
"( " +
" [activity_id] ASC, " +
" [effective_date] ASC, " +
" [effective_enddate] ASC, " +
" [effective_time] ASC, " +
" [effective_endtime] ASC " +
") " ,
"CREATE NONCLUSTERED INDEX [ix_stb_activity_raplav] ON [dbo].[stb_activity] " +
"( " +
" [data_ins_act] ASC, " +
" [flag_tipologia] ASC, " +
" [activity_type_id] ASC, " +
" [cod_jcom] ASC, " +
" [cod_jfas] ASC " +
") " ,
"CREATE NONCLUSTERED INDEX [ix[stb_activity_effective_date] ON [dbo].[stb_activity] " +
"( " +
" [effective_date] ASC " +
") "
);
"alter table stb_activity add effective_enddate as cast(effective_endtime as date) ");
List<IndexTableDTO.ColumnIndex> columnsIndex = new ArrayList<>();
columnsIndex.add(new IndexTableDTO.ColumnIndex().setColumnName("alarm_time"));
columnsIndex.add(new IndexTableDTO.ColumnIndex().setColumnName("alarm_date"));
createIndex(new IndexTableDTO()
.setTableName("stb_activity")
.setIndexName("ix_stb_activity_alarm")
.setColumnsIndex(columnsIndex));
columnsIndex = new ArrayList<>();
columnsIndex.add(new IndexTableDTO.ColumnIndex().setColumnName("activity_id"));
columnsIndex.add(new IndexTableDTO.ColumnIndex().setColumnName("estimated_date"));
columnsIndex.add(new IndexTableDTO.ColumnIndex().setColumnName("estimated_time"));
columnsIndex.add(new IndexTableDTO.ColumnIndex().setColumnName("estimated_enddate"));
columnsIndex.add(new IndexTableDTO.ColumnIndex().setColumnName("estimated_endtime"));
createIndex(new IndexTableDTO()
.setTableName("stb_activity")
.setIndexName("ix_activity_estimate")
.setColumnsIndex(columnsIndex));
columnsIndex = new ArrayList<>();
columnsIndex.add(new IndexTableDTO.ColumnIndex().setColumnName("activity_id"));
columnsIndex.add(new IndexTableDTO.ColumnIndex().setColumnName("effective_date"));
columnsIndex.add(new IndexTableDTO.ColumnIndex().setColumnName("effective_enddate"));
columnsIndex.add(new IndexTableDTO.ColumnIndex().setColumnName("effective_time"));
columnsIndex.add(new IndexTableDTO.ColumnIndex().setColumnName("effective_endtime"));
createIndex(new IndexTableDTO()
.setTableName("stb_activity")
.setIndexName("ix_activity_effective")
.setColumnsIndex(columnsIndex));
columnsIndex = new ArrayList<>();
columnsIndex.add(new IndexTableDTO.ColumnIndex().setColumnName("data_ins_act"));
columnsIndex.add(new IndexTableDTO.ColumnIndex().setColumnName("flag_tipologia"));
columnsIndex.add(new IndexTableDTO.ColumnIndex().setColumnName("activity_type_id"));
columnsIndex.add(new IndexTableDTO.ColumnIndex().setColumnName("cod_jcom"));
columnsIndex.add(new IndexTableDTO.ColumnIndex().setColumnName("cod_jfas"));
createIndex(new IndexTableDTO()
.setTableName("stb_activity")
.setIndexName("ix_stb_activity_raplav")
.setColumnsIndex(columnsIndex));
columnsIndex = new ArrayList<>();
columnsIndex.add(new IndexTableDTO.ColumnIndex().setColumnName("effective_date"));
createIndex(new IndexTableDTO()
.setTableName("stb_activity")
.setIndexName("stb_activity_effective_date")
.setColumnsIndex(columnsIndex));
}
@Override

View File

@@ -48,11 +48,10 @@ public class UtilityDB {
public static void dropIndex(Connection conn, String tableName, String indexName ) throws SQLException {
String sql = Query.format("SELECT CAST(Count(*) as bit) from sys.sysindexes where name = %s", indexName);
String sql = Query.format("SELECT CAST(Count(*) as bit) from sys.sysindexes where name = %s and object_name(id) = %s", indexName, tableName);
boolean existIndex = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql);
if (existIndex) {
sql = String.format("DROP INDEX %s ON dbo.%s", indexName, tableName);
Statement statement = conn.createStatement();