-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SQL Format updates as per SQLFluff guidelines (#226)
1. Fix Asset Info Cache (include mint/burn tx rather than sum for meta consideration) 2. Update SQLs as per SQLFluff linting guidelines: - [x] 00_blockchain - [x] 01_cached_tables - [x] 02_indexes - [x] account - [x] address - [x] assets - [x] blocks - [x] epoch - [x] pool - [x] script - [x] transactions - [x] views 3. Fix `_last_active_stake_validated_epoch` in active_stake_cache (#222) 4. Typo for `pool_history_cache.sql` as well as add a check to ensure epoch_info_cache has run at least once prior to pool_history_cache (#223) 5. Move control_table entry in cache tables to the end (instead of start). ## Where should the reviewer start? Not really sure, too big to drill down 🙁 , we shouldnt have added any functional changes as part of linting. I expect us to cover review as part of tests itself ## Motivation and context Across months, different folks added SQL updates using different patterns, making it difficult to align/scan/automate linting ## How has this been tested? Was tested on guildnet as per below: - [x] Run `./setup-grest.sh -r -b lint` - [x] Wait for cache to be re-populated - [x] Run schemathesis tests
- Loading branch information
Showing
72 changed files
with
2,983 additions
and
3,157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
tests/**/__pycache__ | ||
tests/**/.* | ||
.vscode | ||
.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[sqlfluff] | ||
dialect = postgres | ||
exclude_rules = structure.column_order, references.keywords | ||
max_line_length=260 | ||
recurse = 0 | ||
capitalisation_policy = upper | ||
extended_capitalisation_policy = upper | ||
idented_joins = True | ||
indented_using_on = False | ||
tab_space_size = 2 | ||
large_file_skip_byte_limit=35000 | ||
|
||
[sqlfluff:indentation] | ||
tab_space_size = 2 | ||
allow_implicit_indents = True | ||
|
||
[sqlfluff:rules:convention.count_rows] | ||
prefer_count_1 = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
CREATE FUNCTION grest.genesis () | ||
RETURNS TABLE ( | ||
NETWORKMAGIC varchar, | ||
NETWORKID varchar, | ||
ACTIVESLOTCOEFF varchar, | ||
UPDATEQUORUM varchar, | ||
MAXLOVELACESUPPLY varchar, | ||
EPOCHLENGTH varchar, | ||
SYSTEMSTART integer, | ||
SLOTSPERKESPERIOD varchar, | ||
SLOTLENGTH varchar, | ||
MAXKESREVOLUTIONS varchar, | ||
SECURITYPARAM varchar, | ||
ALONZOGENESIS varchar | ||
) | ||
LANGUAGE PLPGSQL | ||
AS $$ | ||
CREATE OR REPLACE FUNCTION grest.genesis() | ||
RETURNS TABLE ( | ||
networkmagic varchar, | ||
networkid varchar, | ||
activeslotcoeff varchar, | ||
updatequorum varchar, | ||
maxlovelacesupply varchar, | ||
epochlength varchar, | ||
systemstart integer, | ||
slotsperkesperiod varchar, | ||
slotlength varchar, | ||
maxkesrevolutions varchar, | ||
securityparam varchar, | ||
alonzogenesis varchar | ||
) | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
RETURN QUERY | ||
SELECT | ||
g.NETWORKMAGIC, | ||
g.NETWORKID, | ||
g.ACTIVESLOTCOEFF, | ||
g.UPDATEQUORUM, | ||
g.MAXLOVELACESUPPLY, | ||
g.EPOCHLENGTH, | ||
EXTRACT(epoch from g.SYSTEMSTART::timestamp)::integer, | ||
g.SLOTSPERKESPERIOD, | ||
g.SLOTLENGTH, | ||
g.MAXKESREVOLUTIONS, | ||
g.SECURITYPARAM, | ||
g.ALONZOGENESIS | ||
g.networkmagic, | ||
g.networkid, | ||
g.activeslotcoeff, | ||
g.updatequorum, | ||
g.maxlovelacesupply, | ||
g.epochlength, | ||
EXTRACT(EPOCH FROM g.systemstart::timestamp)::integer, | ||
g.slotsperkesperiod, | ||
g.slotlength, | ||
g.maxkesrevolutions, | ||
g.securityparam, | ||
g.alonzogenesis | ||
FROM | ||
grest.genesis g; | ||
grest.genesis AS g; | ||
END; | ||
$$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,29 @@ | ||
CREATE FUNCTION grest.tip () | ||
RETURNS TABLE ( | ||
hash text, | ||
epoch_no word31type, | ||
abs_slot word63type, | ||
epoch_slot word31type, | ||
block_no word31type, | ||
block_time integer | ||
) | ||
LANGUAGE PLPGSQL | ||
AS $$ | ||
CREATE OR REPLACE FUNCTION grest.tip() | ||
RETURNS TABLE ( | ||
hash text, | ||
epoch_no word31type, | ||
abs_slot word63type, | ||
epoch_slot word31type, | ||
block_no word31type, | ||
block_time integer | ||
) | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
RETURN QUERY | ||
SELECT | ||
ENCODE(B.HASH::bytea, 'hex') AS BLOCK_HASH, | ||
b.EPOCH_NO AS EPOCH_NO, | ||
b.SLOT_NO AS ABS_SLOT, | ||
b.EPOCH_SLOT_NO AS EPOCH_SLOT, | ||
b.BLOCK_NO, | ||
EXTRACT(EPOCH from b.TIME)::integer | ||
ENCODE(b.hash::bytea, 'hex') AS block_hash, | ||
b.epoch_no AS epoch_no, | ||
b.slot_no AS abs_slot, | ||
b.epoch_slot_no AS epoch_slot, | ||
b.block_no, | ||
EXTRACT(EPOCH FROM b.time)::integer | ||
FROM | ||
BLOCK B | ||
block b | ||
ORDER BY | ||
B.ID DESC | ||
b.id DESC | ||
LIMIT 1; | ||
END; | ||
$$; | ||
|
||
COMMENT ON FUNCTION grest.tip IS 'Get the tip info about the latest block seen by chain'; | ||
|
||
COMMENT ON FUNCTION grest.tip IS 'Get the tip info about the latest block seen by chain'; -- noqa: LT01 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,44 @@ | ||
CREATE FUNCTION grest.totals (_epoch_no numeric DEFAULT NULL) | ||
RETURNS TABLE ( | ||
epoch_no word31type, | ||
circulation text, | ||
treasury text, | ||
reward text, | ||
supply text, | ||
reserves text | ||
) | ||
LANGUAGE PLPGSQL | ||
AS $$ | ||
CREATE OR REPLACE FUNCTION grest.totals(_epoch_no numeric DEFAULT NULL) | ||
RETURNS TABLE ( | ||
epoch_no word31type, | ||
circulation text, | ||
treasury text, | ||
reward text, | ||
supply text, | ||
reserves text | ||
) | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
IF _epoch_no IS NULL THEN | ||
RETURN QUERY ( | ||
SELECT | ||
ap.epoch_no, ap.utxo::text, ap.treasury::text, ap.rewards::text, (ap.treasury + ap.rewards + ap.utxo + ap.deposits + ap.fees)::text as supply, ap.reserves::text | ||
FROM | ||
public.ada_pots as ap | ||
ORDER BY | ||
ap.epoch_no DESC) ; | ||
ap.epoch_no, | ||
ap.utxo::text, | ||
ap.treasury::text, | ||
ap.rewards::text, | ||
(ap.treasury + ap.rewards + ap.utxo + ap.deposits + ap.fees)::text AS supply, | ||
ap.reserves::text | ||
FROM | ||
public.ada_pots AS ap | ||
ORDER BY | ||
ap.epoch_no DESC); | ||
ELSE | ||
RETURN QUERY ( | ||
SELECT | ||
ap.epoch_no, ap.utxo::text, ap.treasury::text, ap.rewards::text, (ap.treasury + ap.rewards + ap.utxo + ap.deposits + ap.fees)::text as supply, ap.reserves::text | ||
FROM | ||
public.ada_pots as ap | ||
WHERE | ||
ap.epoch_no = _epoch_no | ||
ORDER BY | ||
ap.epoch_no DESC); | ||
ap.epoch_no, ap.utxo::text, | ||
ap.treasury::text, | ||
ap.rewards::text, | ||
(ap.treasury + ap.rewards + ap.utxo + ap.deposits + ap.fees)::text AS supply, | ||
ap.reserves::text | ||
FROM | ||
public.ada_pots AS ap | ||
WHERE | ||
ap.epoch_no = _epoch_no | ||
ORDER BY | ||
ap.epoch_no DESC); | ||
END IF; | ||
END; | ||
$$; | ||
|
||
COMMENT ON FUNCTION grest.totals IS 'Get the circulating utxo, treasury, rewards, supply and reserves in lovelace for specified epoch, all epochs if empty'; | ||
|
||
COMMENT ON FUNCTION grest.totals IS 'Get the circulating utxo, treasury, rewards, supply and reserves in lovelace for specified epoch, all epochs if empty'; -- noqa: LT01 |
Oops, something went wrong.