Commit 28ec8bff authored by Matthieu Muffato's avatar Matthieu Muffato
Browse files

Schema change to allow alphanumeric beekeeper process_ids

Needed for Docker swarm
parent 2311bf6c
-- ---------------------------------------------------------------------------------------------------
SET @expected_version = 92;
-- 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> -------------------------------------------------
ALTER TABLE beekeeper MODIFY COLUMN process_id VARCHAR(255) NOT NULL;
-- ----------------------------------</actual_patch> -------------------------------------------------
-- increase the schema version by one and register the patch:
UPDATE hive_meta SET meta_value=meta_value+1 WHERE meta_key='hive_sql_schema_version';
INSERT INTO hive_meta (meta_key, meta_value) SELECT CONCAT("patched_to_", meta_value), CURRENT_TIMESTAMP FROM hive_meta WHERE meta_key = "hive_sql_schema_version";
-- ---------------------------------------------------------------------------------------------------
\set expected_version 92
\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> -------------------------------------------------
ALTER TABLE beekeeper ALTER COLUMN process_id SET DATA TYPE VARCHAR(255);
-- ----------------------------------</actual_patch> -------------------------------------------------
-- increase the schema version by one and register the patch:
UPDATE hive_meta SET meta_value= (CAST(meta_value AS INTEGER) + 1) WHERE meta_key='hive_sql_schema_version';
INSERT INTO hive_meta (meta_key, meta_value) SELECT 'patched_to_' || meta_value, CURRENT_TIMESTAMP FROM hive_meta WHERE meta_key = 'hive_sql_schema_version';
......@@ -549,7 +549,7 @@ CREATE TABLE beekeeper (
beekeeper_id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
meadow_host VARCHAR(255) NOT NULL,
meadow_user VARCHAR(255) NOT NULL,
process_id INTEGER NOT NULL,
process_id VARCHAR(255) NOT NULL,
is_blocked SMALLINT NOT NULL DEFAULT 0,
cause_of_death ENUM('ANALYSIS_FAILED', 'DISAPPEARED', 'JOB_FAILED', 'LOOP_LIMIT', 'NO_WORK', 'TASK_FAILED') NULL,
sleep_minutes REAL NULL,
......
......@@ -562,7 +562,7 @@ CREATE TABLE beekeeper (
beekeeper_id SERIAL PRIMARY KEY,
meadow_host VARCHAR(255) NOT NULL,
meadow_user VARCHAR(255) NOT NULL,
process_id INTEGER NOT NULL,
process_id VARCHAR(255) NOT NULL,
is_blocked SMALLINT NOT NULL DEFAULT 0,
cause_of_death beekeeper_cod NULL,
sleep_minutes REAL NULL,
......
......@@ -542,7 +542,7 @@ CREATE TABLE beekeeper (
beekeeper_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
meadow_host VARCHAR(255) NOT NULL,
meadow_user VARCHAR(255) NOT NULL,
process_id INTEGER NOT NULL,
process_id VARCHAR(255) NOT NULL,
is_blocked SMALLINT NOT NULL DEFAULT 0,
cause_of_death VARCHAR(255) NULL, /* enum('ANALYSIS_FAILED', 'DISAPPEARED', 'JOB_FAILED', 'LOOP_LIMIT', 'NO_WORK', 'TASK_FAILED') NOT NULL */
sleep_minutes REAL NULL,
......
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