Skip to content

Commit

Permalink
bump HAF: contexts use schema for HAF views
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ickiewicz authored and vogel76 committed May 7, 2024
1 parent 0b7dda8 commit 322bde8
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ variables:
include:
- template: Workflows/Branch-Pipelines.gitlab-ci.yml
- project: hive/haf
ref: 3a7456f280d6eefbd7f47240cbd1fa5e0a6251d3
ref: 988f804191708ad83812851f9d6f0790b18fc608
file: /scripts/ci-helpers/prepare_data_image_job.yml # implicitly pulls base.gitlab-ci.yml from common-ci-configuration


Expand Down
2 changes: 1 addition & 1 deletion haf
Submodule haf updated 261 files
2 changes: 1 addition & 1 deletion hive/db/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ def setup(db, admin_db):
if table.name in ('hive_db_patch_level',):
continue

sql = f'ALTER TABLE {SCHEMA_NAME}.{table.name} INHERIT hive.{SCHEMA_NAME};'
sql = f'ALTER TABLE {SCHEMA_NAME}.{table.name} INHERIT {SCHEMA_NAME}.{SCHEMA_NAME};'
db.query(sql)

context_detach(db=db)
Expand Down
4 changes: 2 additions & 2 deletions hive/db/sql_scripts/hafapp_api.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ BEGIN

RETURN QUERY -- enum_operations4hivemind
SELECT ho.id, ho.block_num, ho.op_type_id, ho.op_type_id >= 50 AS is_virtual, ho.body::VARCHAR
FROM hive.hivemind_app_operations_view ho
FROM hivemind_app.operations_view ho
WHERE ho.block_num BETWEEN _first_block AND _last_block
AND (ho.op_type_id < 50
OR ho.op_type_id in (51, 53, 61, 72, 73)
Expand Down Expand Up @@ -56,7 +56,7 @@ SELECT -- hivemind_app.hive_api_hivemind_blocks
, hb.hash
, hb.prev as prev
, to_char( created_at, 'YYYY-MM-DDThh24:MI:SS' ) as date
FROM hive.hivemind_app_blocks_view hb
FROM hivemind_app.blocks_view hb
WHERE hb.num BETWEEN _first_block AND _last_block
ORDER by hb.num
;
Expand Down
2 changes: 1 addition & 1 deletion hive/db/sql_scripts/head_block_time.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $BODY$

DROP FUNCTION IF EXISTS hivemind_app.block_before_head CASCADE;
CREATE OR REPLACE FUNCTION hivemind_app.block_before_head( in _time INTERVAL )
RETURNS hive.hivemind_app_blocks_view.num%TYPE
RETURNS hivemind_app.blocks_view.num%TYPE
LANGUAGE 'sql' STABLE
AS
$BODY$
Expand Down
2 changes: 1 addition & 1 deletion hive/db/sql_scripts/hive_post_operations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ DROP FUNCTION IF EXISTS hivemind_app.delete_hive_post(character varying,characte
CREATE OR REPLACE FUNCTION hivemind_app.delete_hive_post(
in _author hivemind_app.hive_accounts.name%TYPE,
in _permlink hivemind_app.hive_permlink_data.permlink%TYPE,
in _block_num hive.hivemind_app_blocks_view.num%TYPE,
in _block_num hivemind_app.blocks_view.num%TYPE,
in _date hivemind_app.hive_posts.active%TYPE)
RETURNS VOID
LANGUAGE plpgsql
Expand Down
10 changes: 5 additions & 5 deletions hive/db/sql_scripts/notifications_api.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ $BODY$
DECLARE
__account_id INT := 0;
__last_read_at TIMESTAMP;
__last_read_at_block hive.hivemind_app_blocks_view.num%TYPE;
__limit_block hive.hivemind_app_blocks_view.num%TYPE = hivemind_app.block_before_head( '90 days' );
__last_read_at_block hivemind_app.blocks_view.num%TYPE;
__limit_block hivemind_app.blocks_view.num%TYPE = hivemind_app.block_before_head( '90 days' );
BEGIN
__account_id = hivemind_app.find_account_id( _account, True );

Expand Down Expand Up @@ -79,7 +79,7 @@ CREATE OR REPLACE FUNCTION hivemind_app.account_notifications(
AS $BODY$
DECLARE
__account_id INT;
__limit_block hive.hivemind_app_blocks_view.num%TYPE = hivemind_app.block_before_head( '90 days' );
__limit_block hivemind_app.blocks_view.num%TYPE = hivemind_app.block_before_head( '90 days' );
BEGIN
__account_id = hivemind_app.find_account_id( _account, True );
RETURN QUERY SELECT
Expand Down Expand Up @@ -127,7 +127,7 @@ AS
$function$
DECLARE
__post_id INT;
__limit_block hive.hivemind_app_blocks_view.num%TYPE = hivemind_app.block_before_head( '90 days' );
__limit_block hivemind_app.blocks_view.num%TYPE = hivemind_app.block_before_head( '90 days' );
BEGIN
__post_id = hivemind_app.find_comment_id(_author, _permlink, True);
RETURN QUERY SELECT
Expand Down Expand Up @@ -176,7 +176,7 @@ RETURNS VOID
AS
$function$
DECLARE
__limit_block hive.hivemind_app_blocks_view.num%TYPE = hivemind_app.block_before_head( '90 days' );
__limit_block hivemind_app.blocks_view.num%TYPE = hivemind_app.block_before_head( '90 days' );
BEGIN
IF _first_block_num IS NULL THEN
TRUNCATE TABLE hivemind_app.hive_notification_cache;
Expand Down
4 changes: 2 additions & 2 deletions hive/db/sql_scripts/notifications_view.sql
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ UNION ALL
hivemind_app.notification_id(hf.block_num, 15, hf.id) AS id,
0 AS post_id,
15 AS type_id,
(select hb.created_at from hive.hivemind_app_blocks_view hb where hb.num = (hf.block_num - 1)) as created_at, -- use time of previous block to match head_block_time behavior at given block
(select hb.created_at from hivemind_app.blocks_view hb where hb.num = (hf.block_num - 1)) as created_at, -- use time of previous block to match head_block_time behavior at given block
hf.follower AS src,
hf.following AS dst,
0 as dst_post_id,
Expand Down Expand Up @@ -159,7 +159,7 @@ UNION ALL
hivemind_app.notification_id(hm.block_num, 16, hm.id) AS id,
hm.post_id,
16 AS type_id,
(select hb.created_at from hive.hivemind_app_blocks_view hb where hb.num = (hm.block_num - 1)) as created_at, -- use time of previous block to match head_block_time behavior at given block
(select hb.created_at from hivemind_app.blocks_view hb where hb.num = (hm.block_num - 1)) as created_at, -- use time of previous block to match head_block_time behavior at given block
hp.author_id AS src,
hm.account_id AS dst,
hm.post_id as dst_post_id,
Expand Down
6 changes: 3 additions & 3 deletions hive/db/sql_scripts/update_follow_count.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DROP FUNCTION IF EXISTS hivemind_app.update_follow_count(hive.hivemind_app_blocks_view.num%TYPE, hive.hivemind_app_blocks_view.num%TYPE);
DROP FUNCTION IF EXISTS hivemind_app.update_follow_count(hivemind_app.blocks_view.num%TYPE, hivemind_app.blocks_view.num%TYPE);
CREATE OR REPLACE FUNCTION hivemind_app.update_follow_count(
in _first_block hive.hivemind_app_blocks_view.num%TYPE,
in _last_block hive.hivemind_app_blocks_view.num%TYPE
in _first_block hivemind_app.blocks_view.num%TYPE,
in _last_block hivemind_app.blocks_view.num%TYPE
)
RETURNS VOID
LANGUAGE 'plpgsql'
Expand Down
4 changes: 2 additions & 2 deletions hive/db/sql_scripts/update_posts_rshares.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DROP FUNCTION IF EXISTS hivemind_app.update_posts_rshares;
CREATE OR REPLACE FUNCTION hivemind_app.update_posts_rshares(
_first_block hive.hivemind_app_blocks_view.num%TYPE
, _last_block hive.hivemind_app_blocks_view.num%TYPE
_first_block hivemind_app.blocks_view.num%TYPE
, _last_block hivemind_app.blocks_view.num%TYPE
)
RETURNS VOID
LANGUAGE 'plpgsql'
Expand Down
9 changes: 2 additions & 7 deletions hive/db/sql_scripts/utility_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ CREATE OR REPLACE FUNCTION hivemind_app.find_comment_id(
in _check boolean)
RETURNS INT
LANGUAGE 'plpgsql'
SET log_min_messages=FATAL
AS
$function$
DECLARE
Expand Down Expand Up @@ -62,7 +61,6 @@ CREATE OR REPLACE FUNCTION hivemind_app.find_account_id(
in _check boolean)
RETURNS INT
LANGUAGE 'plpgsql'
SET log_min_messages=FATAL
AS
$function$
DECLARE
Expand All @@ -87,7 +85,6 @@ CREATE OR REPLACE FUNCTION hivemind_app.find_tag_id(
)
RETURNS INTEGER
LANGUAGE 'plpgsql' STABLE
SET log_min_messages=FATAL
AS
$function$
DECLARE
Expand All @@ -112,7 +109,6 @@ CREATE OR REPLACE FUNCTION hivemind_app.find_category_id(
)
RETURNS INTEGER
LANGUAGE 'plpgsql' STABLE
SET log_min_messages=FATAL
AS
$function$
DECLARE
Expand All @@ -137,7 +133,6 @@ CREATE OR REPLACE FUNCTION hivemind_app.find_community_id(
)
RETURNS INTEGER
LANGUAGE 'plpgsql' STABLE
SET log_min_messages=FATAL
AS
$function$
DECLARE
Expand Down Expand Up @@ -239,9 +234,9 @@ DECLARE
__created_at timestamp := '1970-01-01 00:00:00'::timestamp;
__record hivemind_app.head_state;
BEGIN
SELECT current_block_num INTO __num FROM hive.hivemind_app_context_data_view;
SELECT current_block_num INTO __num FROM hivemind_app.context_data_view;
IF __num > 0 THEN
SELECT created_at INTO __created_at FROM hive.hivemind_app_blocks_view WHERE num = __num;
SELECT created_at INTO __created_at FROM hivemind_app.blocks_view WHERE num = __num;
ELSE
-- MIGHT BE NULL
__num = 0;
Expand Down
2 changes: 1 addition & 1 deletion hive/indexer/hive_db/haf_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def prepare_app_context(db: Db) -> None:
ctx_present = db.query_one(f"SELECT hive.app_context_exists('{SCHEMA_NAME}') as ctx_present;")
if not ctx_present:
log.info(f"No application context present. Attempting to create a '{SCHEMA_NAME}' context...")
db.query_no_return(f"SELECT hive.app_create_context('{SCHEMA_NAME}',FALSE);") #is-forking=FALSE, only process irreversible blocks
db.query_no_return(f"SELECT hive.app_create_context('{SCHEMA_NAME}', '{SCHEMA_NAME}', FALSE);") #is-forking=FALSE, only process irreversible blocks
log.info("Application context creation done.")
else:
log.info(f"Found existing context, set to non-forking.")
Expand Down
2 changes: 1 addition & 1 deletion scripts/setup_postgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ fi

"$SCRIPTPATH/../haf/scripts/create_haf_app_role.sh" --postgres-url="$POSTGRES_ACCESS" --haf-app-account="hivemind"

psql "$POSTGRES_ACCESS" -c "GRANT SET ON PARAMETER log_min_messages TO hivemind;"
#psql "$POSTGRES_ACCESS" -c "GRANT SET ON PARAMETER log_min_messages TO hivemind;"

supplement_builtin_roles "$POSTGRES_ACCESS"

0 comments on commit 322bde8

Please sign in to comment.