Skip to content
Snippets Groups Projects
Commit 3ab5ca75 authored by Michal Zander's avatar Michal Zander
Browse files

Adjusted code for linter compliance on CI

parent e79042b6
No related branches found
No related tags found
2 merge requests!168Update return types: VEST balances should be returned as strings to address JSON limitations,!160Add daily and monthly aggregations for balances
[sqlfluff] [sqlfluff]
dialect = postgres dialect = postgres
max_line_length = 150 max_line_length = 150
exclude_rules = CP03, LT01, CP05, CP04 exclude_rules = CP03
warnings = LT01, CP05, PRS
-- noqa: disable=AL01, AM05
SET ROLE btracker_owner; SET ROLE btracker_owner;
DROP TYPE IF EXISTS balance_history_aggregation CASCADE; DROP TYPE IF EXISTS balance_history_aggregation CASCADE;
...@@ -10,38 +12,41 @@ CREATE TYPE balance_history_aggregation AS ( ...@@ -10,38 +12,41 @@ CREATE TYPE balance_history_aggregation AS (
CREATE OR REPLACE VIEW balance_history_by_year AS CREATE OR REPLACE VIEW balance_history_by_year AS
WITH get_year AS ( WITH get_year AS (
SELECT SELECT
account, account,
nai, nai,
balance, balance,
min_balance, min_balance,
max_balance, max_balance,
source_op_block, source_op_block,
date_trunc('year', updated_at) AS by_year, updated_at,
updated_at DATE_TRUNC('year', updated_at) AS by_year
FROM balance_history_by_month FROM balance_history_by_month
), ),
get_latest_updates AS ( get_latest_updates AS (
SELECT SELECT
account, account,
nai, nai,
balance, balance,
source_op_block, source_op_block,
by_year, by_year,
ROW_NUMBER() OVER (PARTITION BY account, nai, by_year ORDER BY updated_at DESC) AS rn_by_year ROW_NUMBER() OVER (PARTITION BY account, nai, by_year ORDER BY updated_at DESC) AS rn_by_year
FROM get_year bh FROM get_year
), ),
get_min_max_balances_by_year AS ( get_min_max_balances_by_year AS (
SELECT SELECT
account, account,
nai, nai,
by_year, by_year,
MAX(max_balance) AS max_balance, MAX(max_balance) AS max_balance,
MIN(min_balance) AS min_balance MIN(min_balance) AS min_balance
FROM get_year FROM get_year
GROUP BY account, nai, by_year GROUP BY account, nai, by_year
) )
SELECT
SELECT
gl.account, gl.account,
gl.nai, gl.nai,
gl.balance, gl.balance,
...@@ -49,17 +54,17 @@ get_min_max_balances_by_year AS ( ...@@ -49,17 +54,17 @@ get_min_max_balances_by_year AS (
gm.max_balance, gm.max_balance,
gl.source_op_block, gl.source_op_block,
gl.by_year AS updated_at gl.by_year AS updated_at
FROM get_latest_updates gl FROM get_latest_updates gl
JOIN get_min_max_balances_by_year gm ON gl.account = gm.account AND gl.nai = gm.nai AND gl.by_year = gm.by_year JOIN get_min_max_balances_by_year gm ON gl.account = gm.account AND gl.nai = gm.nai AND gl.by_year = gm.by_year
WHERE rn_by_year = 1; WHERE gl.rn_by_year = 1;
CREATE OR REPLACE FUNCTION get_balance_history_aggregation( CREATE OR REPLACE FUNCTION get_balance_history_aggregation(
_account_id INT, _account_id INT,
_coin_type INT, _coin_type INT,
_granularity btracker_endpoints.granularity, _granularity btracker_endpoints.granularity,
_direction btracker_endpoints.sort_direction, _direction btracker_endpoints.sort_direction,
_from_block INT, _from_block INT,
_to_block INT _to_block INT
) )
RETURNS SETOF balance_history_aggregation -- noqa: LT01, CP05 RETURNS SETOF balance_history_aggregation -- noqa: LT01, CP05
LANGUAGE 'plpgsql' LANGUAGE 'plpgsql'
...@@ -127,11 +132,11 @@ END ...@@ -127,11 +132,11 @@ END
$$; $$;
CREATE OR REPLACE FUNCTION get_balance_history_by_day( CREATE OR REPLACE FUNCTION get_balance_history_by_day(
_account_id INT, _account_id INT,
_coin_type INT, _coin_type INT,
_direction btracker_endpoints.sort_direction, _direction btracker_endpoints.sort_direction,
_from_block INT, _from_block INT,
_to_block INT _to_block INT
) )
RETURNS SETOF balance_history_aggregation -- noqa: LT01, CP05 RETURNS SETOF balance_history_aggregation -- noqa: LT01, CP05
LANGUAGE 'plpgsql' LANGUAGE 'plpgsql'
...@@ -139,8 +144,8 @@ STABLE ...@@ -139,8 +144,8 @@ STABLE
AS AS
$$ $$
DECLARE DECLARE
_from_timestamp TIMESTAMP := date_trunc('day',(SELECT b.created_at FROM hive.blocks_view b WHERE b.num = _from_block)::TIMESTAMP); _from_timestamp TIMESTAMP := DATE_TRUNC('day',(SELECT b.created_at FROM hive.blocks_view b WHERE b.num = _from_block)::TIMESTAMP);
_to_timestamp TIMESTAMP := date_trunc('day', (SELECT b.created_at FROM hive.blocks_view b WHERE b.num = _to_block)::TIMESTAMP); _to_timestamp TIMESTAMP := DATE_TRUNC('day', (SELECT b.created_at FROM hive.blocks_view b WHERE b.num = _to_block)::TIMESTAMP);
BEGIN BEGIN
RETURN QUERY ( RETURN QUERY (
...@@ -221,11 +226,11 @@ END ...@@ -221,11 +226,11 @@ END
$$; $$;
CREATE OR REPLACE FUNCTION get_balance_history_by_month( CREATE OR REPLACE FUNCTION get_balance_history_by_month(
_account_id INT, _account_id INT,
_coin_type INT, _coin_type INT,
_direction btracker_endpoints.sort_direction, _direction btracker_endpoints.sort_direction,
_from_block INT, _from_block INT,
_to_block INT _to_block INT
) )
RETURNS SETOF balance_history_aggregation -- noqa: LT01, CP05 RETURNS SETOF balance_history_aggregation -- noqa: LT01, CP05
LANGUAGE 'plpgsql' LANGUAGE 'plpgsql'
...@@ -233,8 +238,8 @@ STABLE ...@@ -233,8 +238,8 @@ STABLE
AS AS
$$ $$
DECLARE DECLARE
_from_timestamp TIMESTAMP := date_trunc('month',(SELECT b.created_at FROM hive.blocks_view b WHERE b.num = _from_block)::TIMESTAMP); _from_timestamp TIMESTAMP := DATE_TRUNC('month',(SELECT b.created_at FROM hive.blocks_view b WHERE b.num = _from_block)::TIMESTAMP);
_to_timestamp TIMESTAMP := date_trunc('month', (SELECT b.created_at FROM hive.blocks_view b WHERE b.num = _to_block)::TIMESTAMP); _to_timestamp TIMESTAMP := DATE_TRUNC('month', (SELECT b.created_at FROM hive.blocks_view b WHERE b.num = _to_block)::TIMESTAMP);
BEGIN BEGIN
RETURN QUERY ( RETURN QUERY (
WITH date_series AS ( WITH date_series AS (
...@@ -314,11 +319,11 @@ END ...@@ -314,11 +319,11 @@ END
$$; $$;
CREATE OR REPLACE FUNCTION get_balance_history_by_year( CREATE OR REPLACE FUNCTION get_balance_history_by_year(
_account_id INT, _account_id INT,
_coin_type INT, _coin_type INT,
_direction btracker_endpoints.sort_direction, _direction btracker_endpoints.sort_direction,
_from_block INT, _from_block INT,
_to_block INT _to_block INT
) )
RETURNS SETOF balance_history_aggregation -- noqa: LT01, CP05 RETURNS SETOF balance_history_aggregation -- noqa: LT01, CP05
LANGUAGE 'plpgsql' LANGUAGE 'plpgsql'
...@@ -326,8 +331,8 @@ STABLE ...@@ -326,8 +331,8 @@ STABLE
AS AS
$$ $$
DECLARE DECLARE
_from_timestamp TIMESTAMP := date_trunc('year',(SELECT b.created_at FROM hive.blocks_view b WHERE b.num = _from_block)::TIMESTAMP); _from_timestamp TIMESTAMP := DATE_TRUNC('year',(SELECT b.created_at FROM hive.blocks_view b WHERE b.num = _from_block)::TIMESTAMP);
_to_timestamp TIMESTAMP := date_trunc('year', (SELECT b.created_at FROM hive.blocks_view b WHERE b.num = _to_block)::TIMESTAMP); _to_timestamp TIMESTAMP := DATE_TRUNC('year', (SELECT b.created_at FROM hive.blocks_view b WHERE b.num = _to_block)::TIMESTAMP);
BEGIN BEGIN
RETURN QUERY ( RETURN QUERY (
WITH date_series AS ( WITH date_series AS (
......
-- noqa: disable=CP03
SET ROLE btracker_owner; SET ROLE btracker_owner;
DO $$ DO $$
...@@ -402,7 +400,7 @@ $$; ...@@ -402,7 +400,7 @@ $$;
*/ */
CREATE OR REPLACE PROCEDURE main( CREATE OR REPLACE PROCEDURE main(
IN _appContext hive.context_name, IN _appContext hive.context_name,
IN _maxBlockLimit INT = NULL IN _maxBlockLimit INT = null
) )
LANGUAGE 'plpgsql' LANGUAGE 'plpgsql'
AS AS
......
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