diff --git a/community/go-engines-community/database/postgres_migrations/21_alter_instruction_execution_by_modified_on_table.down.sql b/community/go-engines-community/database/postgres_migrations/21_alter_instruction_execution_by_modified_on_table.down.sql new file mode 100644 index 0000000000..e44cd81919 --- /dev/null +++ b/community/go-engines-community/database/postgres_migrations/21_alter_instruction_execution_by_modified_on_table.down.sql @@ -0,0 +1,58 @@ +BEGIN; + +DROP INDEX IF EXISTS instruction_execution_by_modified_on_instruction_updated_time_idx; +ALTER TABLE instruction_execution_by_modified_on RENAME TO instruction_execution_by_modified_on_to_remove; + +CREATE TABLE IF NOT EXISTS instruction_execution_by_modified_on +( + time TIMESTAMP NOT NULL, + instruction VARCHAR(500) NOT NULL, + execution_count INT NOT NULL, + successful INT NOT NULL, + avg_complete_time INT NOT NULL, + init_critical INT NOT NULL DEFAULT 0, + init_major INT NOT NULL DEFAULT 0, + init_minor INT NOT NULL DEFAULT 0, + res_critical INT NOT NULL DEFAULT 0, + res_major INT NOT NULL DEFAULT 0, + res_minor INT NOT NULL DEFAULT 0, + res_ok INT NOT NULL DEFAULT 0 +); +SELECT create_hypertable('instruction_execution_by_modified_on', 'time', if_not_exists => TRUE); + +INSERT INTO instruction_execution_by_modified_on +( + time, + instruction, + execution_count, + successful, + avg_complete_time, + init_critical, + init_major, + init_minor, + res_critical, + res_major, + res_minor, + res_ok +) +SELECT + instruction_updated as time, + instruction, + SUM(execution_count), + SUM(successful), + AVG(avg_complete_time), + SUM(init_critical), + SUM(init_major), + SUM(init_minor), + SUM(res_critical), + SUM(res_major), + SUM(res_minor), + SUM(res_ok) +FROM instruction_execution_by_modified_on_to_remove +GROUP BY instruction, instruction_updated; + +CREATE UNIQUE INDEX idx_instruction_time ON instruction_execution_by_modified_on (instruction, time); + +DROP TABLE instruction_execution_by_modified_on_to_remove; + +COMMIT; diff --git a/community/go-engines-community/database/postgres_migrations/21_alter_instruction_execution_by_modified_on_table.up.sql b/community/go-engines-community/database/postgres_migrations/21_alter_instruction_execution_by_modified_on_table.up.sql new file mode 100644 index 0000000000..35ebcda5c0 --- /dev/null +++ b/community/go-engines-community/database/postgres_migrations/21_alter_instruction_execution_by_modified_on_table.up.sql @@ -0,0 +1,60 @@ +BEGIN; + +DROP INDEX IF EXISTS idx_instruction_time; +ALTER TABLE instruction_execution_by_modified_on RENAME TO instruction_execution_by_modified_on_to_remove; + +CREATE TABLE IF NOT EXISTS instruction_execution_by_modified_on +( + time TIMESTAMP NOT NULL, + instruction_updated TIMESTAMP NOT NULL, + instruction VARCHAR(500) NOT NULL, + execution_count INT NOT NULL, + successful INT NOT NULL, + avg_complete_time INT NOT NULL, + init_critical INT NOT NULL DEFAULT 0, + init_major INT NOT NULL DEFAULT 0, + init_minor INT NOT NULL DEFAULT 0, + res_critical INT NOT NULL DEFAULT 0, + res_major INT NOT NULL DEFAULT 0, + res_minor INT NOT NULL DEFAULT 0, + res_ok INT NOT NULL DEFAULT 0 +); +SELECT create_hypertable('instruction_execution_by_modified_on', 'time', if_not_exists => TRUE); + +INSERT INTO instruction_execution_by_modified_on +( + time, + instruction_updated, + instruction, + execution_count, + successful, + avg_complete_time, + init_critical, + init_major, + init_minor, + res_critical, + res_major, + res_minor, + res_ok +) +SELECT + NOW()::date as time, + time as instruction_updated, + instruction, + execution_count, + successful, + avg_complete_time, + init_critical, + init_major, + init_minor, + res_critical, + res_major, + res_minor, + res_ok +FROM instruction_execution_by_modified_on_to_remove; + +CREATE UNIQUE INDEX instruction_execution_by_modified_on_instruction_updated_time_idx ON instruction_execution_by_modified_on (instruction, instruction_updated, time); + +DROP TABLE instruction_execution_by_modified_on_to_remove; + +COMMIT; diff --git a/community/go-engines-community/database/postgres_migrations/21_serial_name_table.down.sql b/community/go-engines-community/database/postgres_migrations/22_serial_name_table.down.sql similarity index 100% rename from community/go-engines-community/database/postgres_migrations/21_serial_name_table.down.sql rename to community/go-engines-community/database/postgres_migrations/22_serial_name_table.down.sql diff --git a/community/go-engines-community/database/postgres_migrations/21_serial_name_table.up.sql b/community/go-engines-community/database/postgres_migrations/22_serial_name_table.up.sql similarity index 100% rename from community/go-engines-community/database/postgres_migrations/21_serial_name_table.up.sql rename to community/go-engines-community/database/postgres_migrations/22_serial_name_table.up.sql diff --git a/community/go-engines-community/database/postgres_migrations/22_create_action_log_table.down.sql b/community/go-engines-community/database/postgres_migrations/23_create_action_log_table.down.sql similarity index 100% rename from community/go-engines-community/database/postgres_migrations/22_create_action_log_table.down.sql rename to community/go-engines-community/database/postgres_migrations/23_create_action_log_table.down.sql diff --git a/community/go-engines-community/database/postgres_migrations/22_create_action_log_table.up.sql b/community/go-engines-community/database/postgres_migrations/23_create_action_log_table.up.sql similarity index 100% rename from community/go-engines-community/database/postgres_migrations/22_create_action_log_table.up.sql rename to community/go-engines-community/database/postgres_migrations/23_create_action_log_table.up.sql