-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zarina Yakubova
authored and
Zarina Yakubova
committed
Oct 22, 2024
1 parent
8cab026
commit 7c26a8a
Showing
6 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...database/postgres_migrations/21_alter_instruction_execution_by_modified_on_table.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
60 changes: 60 additions & 0 deletions
60
...y/database/postgres_migrations/21_alter_instruction_execution_by_modified_on_table.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.