Vote Plan Tables

These Tables represent the on-chain vote plan for an event.

Vote Plan Table Diagram



erd

Catalyst Event Database - Vote Plans


proposal_voteplan


proposal_voteplan

Column

Type

Description


row_id


integer+


Synthetic ID of this Voteplan/Proposal
M-M relationship.

proposal_id

integer

The link to the Proposal primary key
that links to this voteplan.

voteplan_id

integer

The link to the Voteplan primary key
that links to this proposal.

bb_proposal_index

bigint

The Index with the voteplan used by
the voting ledger/bulletin board that
references this proposal.


Table to link Proposals to Vote plans in a Many to Many relationship.



voteplan


voteplan

Column

Type

Description


row_id


integer+


Synthetic Unique Key

objective_id

integer

none

id

varchar

The ID of the Vote plan in the voting
ledger/bulletin board.
A Binary value encoded as hex.

category

text

The kind of vote which can be cast on
this vote plan.

encryption_key

varchar

The public encryption key used.
ONLY if required by the voteplan
category.

group_id

text

The identifier of voting power token
used withing this plan.

token_id

text

none


All Vote plans.



proposal_voteplan:voteplan_id_out->voteplan:row_id





proposal


proposal

Column

row_id


ABRIDGED



proposal_voteplan:proposal_id_out->proposal:row_id





voteplan_category


voteplan_category

Column

Type

Description


name


text


The UNIQUE name of this voteplan
category.

public_key

boolean

Does this vote plan category require a
public key.


The category of vote plan currently supported.



voteplan:category_out->voteplan_category:name





voting_group


voting_group

Column

Type

Description


name


text


The ID of this voting group.


All Groups.



voteplan:group_id_out->voting_group:name





objective


objective

Column

row_id


ABRIDGED



voteplan:objective_id_out->objective:row_id





LEGEND


LEGEND

Type

Example


Primary Key


integer+

Standard Field

bytea

Nullable Field

text

Sized Field

varchar(32)

Autoincrement Field

integer+



Schema

-- Catalyst Event Database

-- Vote Plan Categories

CREATE TABLE voteplan_category
(
    name TEXT PRIMARY KEY,
    public_key BOOL
);


INSERT INTO voteplan_category (name, public_key)
VALUES
    ('public', false), -- Fully public votes only
    ('private', true), -- Fully private votes only.
    ('cast-private', true); -- Private until tally, then decrypted.

COMMENT ON TABLE voteplan_category IS 'The category of vote plan currently supported.';
COMMENT ON COLUMN voteplan_category.name IS 'The UNIQUE name of this voteplan category.';
COMMENT ON COLUMN voteplan_category.public_key IS 'Does this vote plan category require a public key.';


-- groups

CREATE TABLE voting_group (
    name TEXT PRIMARY KEY
);

INSERT INTO voting_group (name)
VALUES
    ('direct'), -- Direct Voters
    ('rep'); -- Delegated Voter (Check what is the real name for this group we already use in snapshot)

COMMENT ON TABLE voting_group IS 'All Groups.';
COMMENT ON COLUMN voting_group.name IS 'The ID of this voting group.';

-- Vote Plans

CREATE TABLE voteplan
(
    row_id SERIAL PRIMARY KEY,
    objective_id INTEGER NOT NULL,

    id VARCHAR NOT NULL,
    category TEXT NOT NULL,
    encryption_key VARCHAR,
    group_id TEXT,
    token_id TEXT,

    FOREIGN KEY(objective_id) REFERENCES objective(row_id)  ON DELETE CASCADE,
    FOREIGN KEY(category) REFERENCES voteplan_category(name)  ON DELETE CASCADE,
    FOREIGN KEY(group_id) REFERENCES voting_group(name)  ON DELETE CASCADE
);

COMMENT ON TABLE voteplan IS 'All Vote plans.';

COMMENT ON COLUMN voteplan.row_id IS 'Synthetic Unique Key';
COMMENT ON COLUMN voteplan.id IS
'The ID of the Vote plan in the voting ledger/bulletin board.
A Binary value encoded as hex.';
COMMENT ON COLUMN voteplan.category IS 'The kind of vote which can be cast on this vote plan.';
COMMENT ON COLUMN voteplan.encryption_key IS
'The public encryption key used.
ONLY if required by the voteplan category.';
COMMENT ON COLUMN voteplan.group_id IS 'The identifier of voting power token used withing this plan.';

-- Table to link Proposals to Vote plans in a many-many relationship.
-- This Many-Many relationship arises because:
--  in the vote ledger/bulletin board,
--      one proposal may be within multiple different vote plans,
--      and each voteplan can contain multiple proposals.
CREATE TABLE proposal_voteplan
(
    row_id SERIAL PRIMARY KEY,
    proposal_id INTEGER,
    voteplan_id INTEGER,
    bb_proposal_index BIGINT,

    FOREIGN KEY(proposal_id) REFERENCES proposal(row_id) ON DELETE CASCADE,
    FOREIGN KEY(voteplan_id) REFERENCES voteplan(row_id) ON DELETE CASCADE
);

CREATE UNIQUE INDEX proposal_voteplan_idx ON proposal_voteplan(proposal_id,voteplan_id,bb_proposal_index);

COMMENT ON TABLE proposal_voteplan IS 'Table to link Proposals to Vote plans in a Many to Many relationship.';
COMMENT ON COLUMN proposal_voteplan.row_id IS 'Synthetic ID of this Voteplan/Proposal M-M relationship.';
COMMENT ON COLUMN proposal_voteplan.proposal_id IS 'The link to the Proposal primary key that links to this voteplan.';
COMMENT ON COLUMN proposal_voteplan.voteplan_id IS 'The link to the Voteplan primary key that links to this proposal.';
COMMENT ON COLUMN proposal_voteplan.bb_proposal_index IS 'The Index with the voteplan used by the voting ledger/bulletin board that references this proposal.';