Commit b5913796 authored by Leo Gordon's avatar Leo Gordon
Browse files

schema_change: added a view to count live roles by meadow_user, meadow_type,...

schema_change: added a view to count live roles by meadow_user, meadow_type, resource_class and analysis
parent 556d6367
-- ---------------------------------------------------------------------------------------------------
SET @expected_version = 69;
-- make MySQL stop immediately after it encounters division by zero:
SET SESSION sql_mode='TRADITIONAL';
-- warn that we detected the schema version mismatch:
SELECT CONCAT( 'The patch only applies to schema version ',
@expected_version,
', but the current schema version is ',
meta_value,
', so skipping the rest.') AS ''
FROM hive_meta WHERE meta_key='hive_sql_schema_version' AND meta_value<>@expected_version;
-- cause division by zero only if current version differs from the expected one:
INSERT INTO hive_meta (meta_key, meta_value)
SELECT 'this_should_never_be_inserted', 1 FROM hive_meta WHERE NOT 1/(meta_key<>'hive_sql_schema_version' OR meta_value=@expected_version);
SELECT CONCAT( 'The patch seems to be compatible with schema version ',
@expected_version,
', applying the patch...') AS '';
-- Now undo the change so that we could patch potentially non-TRADITIONAL schema:
SET SESSION sql_mode='';
-- ----------------------------------<actual_patch> -------------------------------------------------
CREATE OR REPLACE VIEW live_roles AS
SELECT w.meadow_user, w.meadow_type, w.resource_class_id, rc.name resource_class_name, r.analysis_id, a.logic_name, count(*)
FROM worker w
JOIN role r USING(worker_id)
LEFT JOIN resource_class rc ON w.resource_class_id=rc.resource_class_id
LEFT JOIN analysis_base a USING(analysis_id)
WHERE r.when_finished IS NULL
GROUP BY w.meadow_user, w.meadow_type, w.resource_class_id, rc.name, r.analysis_id, a.logic_name;
-- ----------------------------------</actual_patch> -------------------------------------------------
-- increase the schema version by one:
UPDATE hive_meta SET meta_value=meta_value+1 WHERE meta_key='hive_sql_schema_version';
-- ---------------------------------------------------------------------------------------------------
\set expected_version 69
\set ON_ERROR_STOP on
-- warn that we detected the schema version mismatch:
SELECT ('The patch only applies to schema version '
|| CAST(:expected_version AS VARCHAR)
|| ', but the current schema version is '
|| meta_value
|| ', so skipping the rest.') as incompatible_msg
FROM hive_meta WHERE meta_key='hive_sql_schema_version' AND meta_value!=CAST(:expected_version AS VARCHAR);
-- cause division by zero only if current version differs from the expected one:
INSERT INTO hive_meta (meta_key, meta_value)
SELECT 'this_should_never_be_inserted', 1 FROM hive_meta WHERE 1 != 1/CAST( (meta_key!='hive_sql_schema_version' OR meta_value=CAST(:expected_version AS VARCHAR)) AS INTEGER );
SELECT ('The patch seems to be compatible with schema version '
|| CAST(:expected_version AS VARCHAR)
|| ', applying the patch...') AS compatible_msg;
-- ----------------------------------<actual_patch> -------------------------------------------------
CREATE OR REPLACE VIEW live_roles AS
SELECT w.meadow_user, w.meadow_type, w.resource_class_id, rc.name resource_class_name, r.analysis_id, a.logic_name, count(*)
FROM worker w
JOIN role r USING(worker_id)
LEFT JOIN resource_class rc ON w.resource_class_id=rc.resource_class_id
LEFT JOIN analysis_base a USING(analysis_id)
WHERE r.when_finished IS NULL
GROUP BY w.meadow_user, w.meadow_type, w.resource_class_id, rc.name, r.analysis_id, a.logic_name;
-- ----------------------------------</actual_patch> -------------------------------------------------
-- increase the schema version by one:
UPDATE hive_meta SET meta_value= (CAST(meta_value AS INTEGER) + 1) WHERE meta_key='hive_sql_schema_version';
-- ---------------------------------------------------------------------------------------------------
CREATE TEMPORARY VIEW exp_ver AS SELECT "69" AS expected_version;
.bail ON
SELECT ('The patch only applies to schema version '
|| expected_version
|| ', but the current schema version is '
|| meta_value
|| ', skipping the rest.') AS ''
FROM hive_meta JOIN exp_ver WHERE meta_key='hive_sql_schema_version' AND meta_value<>expected_version;
INSERT INTO hive_meta (meta_key, meta_value)
SELECT hm.* FROM hive_meta AS hm JOIN exp_ver WHERE meta_key='hive_sql_schema_version' AND meta_value<>expected_version;
SELECT ('The patch seems to be compatible with schema version '
|| expected_version
|| ', applying the patch...') AS '' FROM exp_ver;
-- ----------------------------------<actual_patch> -------------------------------------------------
DROP VIEW IF EXISTS live_roles;
CREATE VIEW IF NOT EXISTS live_roles AS
SELECT w.meadow_user, w.meadow_type, w.resource_class_id, rc.name resource_class_name, r.analysis_id, a.logic_name, count(*)
FROM worker w
JOIN role r USING(worker_id)
LEFT JOIN resource_class rc ON w.resource_class_id=rc.resource_class_id
LEFT JOIN analysis_base a USING(analysis_id)
WHERE r.when_finished IS NULL
GROUP BY w.meadow_user, w.meadow_type, w.resource_class_id, rc.name, r.analysis_id, a.logic_name;
-- ----------------------------------</actual_patch> -------------------------------------------------
-- increase the schema version by one:
UPDATE hive_meta SET meta_value=meta_value+1 WHERE meta_key='hive_sql_schema_version';
......@@ -85,6 +85,22 @@ CREATE OR REPLACE VIEW resource_usage_stats AS
ORDER BY a.analysis_id, w.meadow_type, rc.resource_class_id, u.exit_status;
-- show the roles that are currently live (grouped by meadow_users, resource_classes and analyses) -------
--
-- Usage:
-- select * from live_roles;
-- select * from live_roles where resource_class_id=12;
CREATE OR REPLACE VIEW live_roles AS
SELECT w.meadow_user, w.meadow_type, w.resource_class_id, rc.name resource_class_name, r.analysis_id, a.logic_name, count(*)
FROM worker w
JOIN role r USING(worker_id)
LEFT JOIN resource_class rc ON w.resource_class_id=rc.resource_class_id
LEFT JOIN analysis_base a USING(analysis_id)
WHERE r.when_finished IS NULL
GROUP BY w.meadow_user, w.meadow_type, w.resource_class_id, rc.name, r.analysis_id, a.logic_name;
-- time an analysis or group of analyses (given by a name pattern) ----------------------------------------
--
-- Usage:
......
......@@ -85,6 +85,22 @@ CREATE OR REPLACE VIEW resource_usage_stats AS
ORDER BY a.analysis_id, w.meadow_type, rc.resource_class_id, u.exit_status;
-- show the roles that are currently live (grouped by meadow_users, resource_classes and analyses) -------
--
-- Usage:
-- select * from live_roles;
-- select * from live_roles where resource_class_id=12;
CREATE OR REPLACE VIEW live_roles AS
SELECT w.meadow_user, w.meadow_type, w.resource_class_id, rc.name resource_class_name, r.analysis_id, a.logic_name, count(*)
FROM worker w
JOIN role r USING(worker_id)
LEFT JOIN resource_class rc ON w.resource_class_id=rc.resource_class_id
LEFT JOIN analysis_base a USING(analysis_id)
WHERE r.when_finished IS NULL
GROUP BY w.meadow_user, w.meadow_type, w.resource_class_id, rc.name, r.analysis_id, a.logic_name;
-- time an analysis or group of analyses (given by a name pattern) ----------------------------------------
--
-- Usage:
......
......@@ -84,3 +84,20 @@ CREATE VIEW IF NOT EXISTS resource_usage_stats AS
GROUP BY a.analysis_id, w.meadow_type, rc.resource_class_id, u.exit_status
ORDER BY a.analysis_id, w.meadow_type, rc.resource_class_id, u.exit_status;
-- show the roles that are currently live (grouped by meadow_users, resource_classes and analyses) -------
--
-- Usage:
-- select * from live_roles;
-- select * from live_roles where resource_class_id=12;
CREATE VIEW IF NOT EXISTS live_roles AS
SELECT w.meadow_user, w.meadow_type, w.resource_class_id, rc.name resource_class_name, r.analysis_id, a.logic_name, count(*)
FROM worker w
JOIN role r USING(worker_id)
LEFT JOIN resource_class rc ON w.resource_class_id=rc.resource_class_id
LEFT JOIN analysis_base a USING(analysis_id)
WHERE r.when_finished IS NULL
GROUP BY w.meadow_user, w.meadow_type, w.resource_class_id, rc.name, r.analysis_id, a.logic_name;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment