-- Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute -- Copyright [2016-2021] EMBL-European Bioinformatics Institute -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- --------------------------------------------------------------------------------------------------- \set expected_version 86 \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; -- ---------------------------------- ------------------------------------------------- ALTER TABLE analysis_base ADD COLUMN hive_capacity INTEGER DEFAULT NULL; UPDATE analysis_base SET hive_capacity = analysis_stats.hive_capacity FROM analysis_stats WHERE analysis_base.analysis_id = analysis_stats.analysis_id; ALTER TABLE analysis_stats DROP COLUMN hive_capacity; ALTER TABLE analysis_stats_monitor DROP COLUMN hive_capacity; -- ---------------------------------- ------------------------------------------------- -- 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';