Skip to content
Snippets Groups Projects
Commit 5666a453 authored by Marcin's avatar Marcin
Browse files

use drop function if exists instead create or replace fior hash functions

parent 55a57360
No related branches found
No related tags found
6 merge requests!627merge in fix for get_current_block_age,!626Fix get_current_block_age function to avoid healthcheck fails,!622merge develop to master,!599merge ( with merge commit) develop to master,!597Merge develop to master for release,!590issue #259 automaticly get tables to db hash computation
......@@ -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
......
......@@ -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()
......
......@@ -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()")
......
......@@ -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$
;
......
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
......
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment