Skip to content

Commit

Permalink
feat: add computed fields to gov sql
Browse files Browse the repository at this point in the history
  • Loading branch information
clockworkgr committed Apr 8, 2024
1 parent 66c9582 commit 3fddf98
Showing 1 changed file with 65 additions and 1 deletion.
66 changes: 65 additions & 1 deletion database/schema/08-gov.sql
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,68 @@ CREATE TABLE proposal_validator_status_snapshot
height BIGINT NOT NULL
);
CREATE INDEX proposal_validator_status_snapshot_proposal_id_index ON proposal_validator_status_snapshot (proposal_id);
CREATE INDEX proposal_validator_status_snapshot_validator_address_index ON proposal_validator_status_snapshot (validator_address);
CREATE INDEX proposal_validator_status_snapshot_validator_address_index ON proposal_validator_status_snapshot (validator_address);

CREATE OR REPLACE FUNCTION public.active_first(proposal_row proposal)
RETURNS integer
LANGUAGE sql
STABLE
AS $function$
SELECT
CASE WHEN proposal_row.status='PROPOSAL_STATUS_PASSED' THEN 3
WHEN proposal_row.status='PROPOSAL_STATUS_DEPOSIT_PERIOD' THEN 1
WHEN proposal_row.status='PROPOSAL_STATUS_VOTING_PERIOD' THEN 2
WHEN proposal_row.status='PROPOSAL_STATUS_REJECTED' THEN 4
WHEN proposal_row.status='PROPOSAL_STATUS_FAILED' THEN 5
WHEN proposal_row.status='PROPOSAL_STATUS_INVALID' THEN 6
ELSE 7
END
$function$

CREATE OR REPLACE FUNCTION public.failed_first(proposal_row proposal)
RETURNS integer
LANGUAGE sql
STABLE
AS $function$
SELECT
CASE WHEN proposal_row.status='PROPOSAL_STATUS_PASSED' THEN 4
WHEN proposal_row.status='PROPOSAL_STATUS_DEPOSIT_PERIOD' THEN 2
WHEN proposal_row.status='PROPOSAL_STATUS_VOTING_PERIOD' THEN 3
WHEN proposal_row.status='PROPOSAL_STATUS_REJECTED' THEN 5
WHEN proposal_row.status='PROPOSAL_STATUS_FAILED' THEN 1
WHEN proposal_row.status='PROPOSAL_STATUS_INVALID' THEN 6
ELSE 7
END
$function$

CREATE OR REPLACE FUNCTION public.passed_first(proposal_row proposal)
RETURNS integer
LANGUAGE sql
STABLE
AS $function$
SELECT
CASE WHEN proposal_row.status='PROPOSAL_STATUS_PASSED' THEN 1
WHEN proposal_row.status='PROPOSAL_STATUS_DEPOSIT_PERIOD' THEN 2
WHEN proposal_row.status='PROPOSAL_STATUS_VOTING_PERIOD' THEN 3
WHEN proposal_row.status='PROPOSAL_STATUS_REJECTED' THEN 4
WHEN proposal_row.status='PROPOSAL_STATUS_FAILED' THEN 5
WHEN proposal_row.status='PROPOSAL_STATUS_INVALID' THEN 6
ELSE 7
END
$function$

CREATE OR REPLACE FUNCTION public.rejected_first(proposal_row proposal)
RETURNS integer
LANGUAGE sql
STABLE
AS $function$
SELECT
CASE WHEN proposal_row.status='PROPOSAL_STATUS_PASSED' THEN 4
WHEN proposal_row.status='PROPOSAL_STATUS_DEPOSIT_PERIOD' THEN 2
WHEN proposal_row.status='PROPOSAL_STATUS_VOTING_PERIOD' THEN 3
WHEN proposal_row.status='PROPOSAL_STATUS_REJECTED' THEN 1
WHEN proposal_row.status='PROPOSAL_STATUS_FAILED' THEN 5
WHEN proposal_row.status='PROPOSAL_STATUS_INVALID' THEN 6
ELSE 7
END
$function$

0 comments on commit 3fddf98

Please sign in to comment.