diff --git a/src/hive_fork_manager/CMakeLists.txt b/src/hive_fork_manager/CMakeLists.txt index da737dd5cc0673d7e76865fbe43a01061c3def42..d103c0c30e17f3ba69736e9783446b20f2be646d 100644 --- a/src/hive_fork_manager/CMakeLists.txt +++ b/src/hive_fork_manager/CMakeLists.txt @@ -53,7 +53,6 @@ ADD_PSQL_EXTENSION( app_api_impl.sql hived_api.sql app_api.sql - table_schema_verification.sql api_helpers/block_api_support.sql authorization.sql get_impacted_accounts.sql diff --git a/src/hive_fork_manager/authorization.sql b/src/hive_fork_manager/authorization.sql index bb4dd37017afce626eaef1c75c4ea5fa8801e8d5..eabef59f64ff1b7f08805d15b31f8fe304816870 100644 --- a/src/hive_fork_manager/authorization.sql +++ b/src/hive_fork_manager/authorization.sql @@ -194,12 +194,12 @@ GRANT EXECUTE ON FUNCTION , hafd._operation_from_jsonb(jsonb) , hafd.operation_to_jsontext(hafd.operation) , hafd.operation_from_jsontext(TEXT) - , hive.create_database_hash() - , hive.calculate_schema_hash() + --, hive.create_database_hash() + --, hive.calculate_schema_hash() , hive.all_indexes_have_status(_status hafd.index_status) - , hive.calculate_table_schema_hash(schema_name TEXT,_table_name TEXT) - , hive.calculate_state_provider_hash(_provider hafd.state_providers ) - , hive.calculate_state_provider_hashes() + --, hive.calculate_table_schema_hash(schema_name TEXT,_table_name TEXT) + --, hive.calculate_state_provider_hash(_provider hafd.state_providers ) + --, hive.calculate_state_provider_hashes() , hive.are_any_indexes_missing() , hive.are_indexes_restored() , hive.are_fk_dropped() diff --git a/src/hive_fork_manager/hive_fork_manager_update_script_generator.sh.in b/src/hive_fork_manager/hive_fork_manager_update_script_generator.sh.in index 11a740c954089d203c4b006376cd74fce050dbc5..a091517b141321e262a4bde52e4e402f2f4cc738 100755 --- a/src/hive_fork_manager/hive_fork_manager_update_script_generator.sh.in +++ b/src/hive_fork_manager/hive_fork_manager_update_script_generator.sh.in @@ -96,6 +96,7 @@ verify_table_schema() { echo "Attempting to verify if existing table schema is correct..." psql_do -a -d postgres -c "CREATE DATABASE $DB_NAME_AFTER_UPDATE WITH OWNER $DB_ADMIN;" psql_do -a -d "$DB_NAME_AFTER_UPDATE" -c 'CREATE EXTENSION hive_fork_manager CASCADE;' + psql_do -d "$DB_NAME_AFTER_UPDATE" -q -t -A -f "$SCRIPTPATH/table_schema_verification.sql" BEFORE_UPDATE=$(psql_do -d "$DB_NAME" -t -A -c "SELECT schema_hash FROM hive.create_database_hash()") AFTER_UPDATE=$(psql_do -d "$DB_NAME_AFTER_UPDATE" -t -A -c "SELECT schema_hash FROM hive.create_database_hash()") diff --git a/src/hive_fork_manager/hived_api.sql b/src/hive_fork_manager/hived_api.sql index 578515a1e4f8d6b9d6b1c8d7e3f4d16a28781312..0f6374743de357c3f976a868b894fe9b88447e9c 100644 --- a/src/hive_fork_manager/hived_api.sql +++ b/src/hive_fork_manager/hived_api.sql @@ -451,7 +451,7 @@ BEGIN IF EXISTS ( SELECT 1 FROM hafd.events_queue WHERE id = hive.unreachable_event_id() LIMIT 1 ) THEN SELECT MAX(eq.id) + 1 FROM hafd.events_queue eq WHERE eq.id != hive.unreachable_event_id() INTO __events_id; PERFORM SETVAL( 'hafd.events_queue_id_seq', __events_id, false ); - PERFORM hive.create_database_hash(); + -- PERFORM hive.create_database_hash(); RETURN; END IF; @@ -463,7 +463,7 @@ BEGIN INSERT INTO hafd.fork(block_num, time_of_fork) VALUES( 1, '2016-03-24 16:05:00'::timestamp ) ON CONFLICT DO NOTHING; - PERFORM hive.create_database_hash(); + -- PERFORM hive.create_database_hash(); END; $BODY$ ; diff --git a/src/hive_fork_manager/table_schema_verification.sql b/src/hive_fork_manager/table_schema_verification.sql index b7db0eef2a0f2ac21ce487921f275ff3f503d711..2c0358f61d5d513aae305a51a675475cc83b9b87 100644 --- a/src/hive_fork_manager/table_schema_verification.sql +++ b/src/hive_fork_manager/table_schema_verification.sql @@ -1,4 +1,5 @@ -CREATE OR REPLACE FUNCTION hive.calculate_table_schema_hash(schema_name TEXT,_table_name TEXT) +DROP FUNCTION IF EXISTS hive.calculate_table_schema_hash; +CREATE FUNCTION hive.calculate_table_schema_hash(schema_name TEXT,_table_name TEXT) RETURNS hafd.verify_table_schema LANGUAGE plpgsql STABLE @@ -90,7 +91,8 @@ BEGIN END; $BODY$; -CREATE OR REPLACE FUNCTION hive.calculate_state_provider_hash(_provider hafd.state_providers ) +DROP FUNCTION IF EXISTS hive.calculate_state_provider_hash; +CREATE FUNCTION hive.calculate_state_provider_hash(_provider hafd.state_providers ) RETURNS TEXT --md5 of start_provider function LANGUAGE plpgsql STABLE @@ -108,7 +110,8 @@ BEGIN END; $BODY$; -CREATE OR REPLACE FUNCTION hive.calculate_state_provider_hashes() +DROP FUNCTION IF EXISTS hive.calculate_state_provider_hashes; +CREATE FUNCTION hive.calculate_state_provider_hashes() RETURNS SETOF hafd.state_provider_and_hash LANGUAGE plpgsql STABLE @@ -126,7 +129,8 @@ $BODY$; -- calculate hafd schema hash -CREATE OR REPLACE FUNCTION hive.calculate_schema_hash() +DROP FUNCTION IF EXISTS hive.calculate_schema_hash; +CREATE FUNCTION hive.calculate_schema_hash() RETURNS SETOF hafd.verify_table_schema LANGUAGE plpgsql STABLE @@ -142,7 +146,8 @@ END; $BODY$ ; -CREATE OR REPLACE FUNCTION hive.create_database_hash() +DROP FUNCTION IF EXISTS hive.create_database_hash(); +CREATE FUNCTION hive.create_database_hash() RETURNS SETOF hafd.table_schema LANGUAGE plpgsql VOLATILE diff --git a/tests/integration/functional/tools/common.sh b/tests/integration/functional/tools/common.sh index f16ede693c324a3d316e5198f109e1c09203dafb..846db08a27ce50125180ecfebf50d6dad3afa591 100755 --- a/tests/integration/functional/tools/common.sh +++ b/tests/integration/functional/tools/common.sh @@ -39,6 +39,7 @@ setup_test_database() { setup_scripts_dir_path="$1" postgres_port="$2" test_path="$3" + extension_path="$4" test_directory=$(dirname "${test_path}"); sql_setup_fixture="./${test_directory}/fixture.sql"; @@ -58,6 +59,10 @@ setup_test_database() { exit 1 fi + # ATTENTION: normally the extension does not contain hash functions + # so the db is little different than production state, but these are functional tests so IMO it is acceptable + psql -p "${postgres_port}" -d "${DB_NAME}" -a -v ON_ERROR_STOP=on -f "${extension_path}/table_schema_verification.sql" + # TODO(mickiewicz@syncad.com): remove when releasing on pg16 where 'public' schema is not accessible by default if ! psql -p "${postgres_port}" -d "${DB_NAME}" -a -v ON_ERROR_STOP=on -c "REVOKE CREATE ON SCHEMA public FROM PUBLIC;"; then diff --git a/tests/integration/functional/tools/test.sh b/tests/integration/functional/tools/test.sh index a3f22a286c2c7a8d1a9b8a71ef89f2ec2ec22bcf..eefde30cad2a8c93dea7bccd36a6e80bb41d59f1 100755 --- a/tests/integration/functional/tools/test.sh +++ b/tests/integration/functional/tools/test.sh @@ -8,7 +8,7 @@ script_to_execute_after_testfun="$5" . ./tools/common.sh -setup_test_database "$setup_scripts_dir_path" "$postgres_port" "$test_path" +setup_test_database "$setup_scripts_dir_path" "$postgres_port" "$test_path" "$extension_path" trap on_exit EXIT; @@ -66,9 +66,11 @@ for testfun in ${tests}; do done if [ -n "${script_to_execute_after_testfun}" ]; then - pg_call="-p $postgres_port -d $DB_NAME -v ON_ERROR_STOP=on -c" - psql ${pg_call} "UPDATE pg_extension SET extversion = '1.0' WHERE extname = 'hive_fork_manager';" + pg_call="-p $postgres_port -d $DB_NAME -v ON_ERROR_STOP=on" + psql ${pg_call} -c "UPDATE pg_extension SET extversion = '1.0' WHERE extname = 'hive_fork_manager';" sudo "${script_to_execute_after_testfun}" --haf-db-name="$DB_NAME"; + # for testing hash functions we ned to add them after update which remove them + psql ${pg_call} -f "${extension_path}/table_schema_verification.sql" fi done