Skip to content

Commit 3cfbdc9

Browse files
committed
Extend and fix schema docs
1 parent 990ba21 commit 3cfbdc9

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed

cardano-db/src/Cardano/Db/Schema.hs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ share
559559
UniqueCostModel hash
560560

561561
PoolStat
562-
poolHashId PoolHashId
562+
poolHashId PoolHashId noreference
563563
epochNo Word64 sqltype=word31type
564564
numberOfBlocks Word64 sqltype=word31type
565565
numberOfDelegators Word64 sqltype=word31type
@@ -1034,7 +1034,7 @@ schemaDocs =
10341034
WithdrawalRedeemerId # "The Redeemer table index that is related with this withdrawal."
10351035

10361036
EpochStake --^ do
1037-
"A table containing the epoch stake distribution for each epoch. This is inserted incrementally in the first blocks of the epoch.\
1037+
"A table containing the epoch stake distribution for each epoch. This is inserted incrementally in the first blocks of the previous epoch.\
10381038
\ The stake distribution is extracted from the `set` snapshot of the ledger. See Shelley specs Sec. 11.2 for more details."
10391039
EpochStakeAddrId # "The StakeAddress table index for the stake address for this EpochStake entry."
10401040
EpochStakePoolId # "The PoolHash table index for the pool this entry is delegated to."
@@ -1259,6 +1259,22 @@ schemaDocs =
12591259
CostModelHash # "The hash of cost model. It ensures uniqueness of entries. New in v13."
12601260
CostModelCosts # "The actual costs formatted as json."
12611261

1262+
PoolStat --^ do
1263+
"Stats per pool and per epoch."
1264+
PoolStatPoolHashId # "The pool_hash_id reference."
1265+
PoolStatEpochNo # "The epoch number."
1266+
PoolStatNumberOfBlocks # "Number of blocks created on the previous epoch."
1267+
PoolStatNumberOfDelegators # "Number of delegators in the mark snapshot."
1268+
PoolStatStake # "Total stake in the mark snapshot."
1269+
PoolStatVotingPower # "Voting power of the SPO."
1270+
1271+
EpochState --^ do
1272+
"Table with governance (and in the future other) stats per epoch."
1273+
EpochStateCommitteeId # "The reference to the current committee."
1274+
EpochStateNoConfidenceId # "The reference to the current gov_action_proposal of no confidence. TODO: This remains NULL."
1275+
EpochStateConstitutionId # "The reference to the current constitution. Should never be null."
1276+
EpochStateEpochNo # "The epoch in question."
1277+
12621278
ExtraMigrations --^ do
12631279
"Extra optional migrations. New in 13.2."
12641280
ExtraMigrationsDescription # "A description of the migration"

doc/schema.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Schema Documentation for cardano-db-sync
22

3+
Schema version: 13.3.0.0 (from branch **kderme/prepare-release-13.3** which may not accurately reflect the version number)
34
**Note:** This file is auto-generated from the documentation in cardano-db/src/Cardano/Db/Schema.hs by the command `cabal run -- gen-schema-docs doc/schema.md`. This document should only be updated during the release process and updated on the release branch.
45

56
### `schema_version`
@@ -441,7 +442,7 @@ A table for withdrawals from a reward account.
441442

442443
### `epoch_stake`
443444

444-
A table containing the epoch stake distribution for each epoch. This is inserted incrementally in the first blocks of the epoch. The stake distribution is extracted from the `set` snapshot of the ledger. See Shelley specs Sec. 11.2 for more details.
445+
A table containing the epoch stake distribution for each epoch. This is inserted incrementally in the first blocks of the previous epoch. The stake distribution is extracted from the `set` snapshot of the ledger. See Shelley specs Sec. 11.2 for more details.
445446

446447
* Primary Id: `id`
447448

@@ -773,6 +774,22 @@ CostModel for EpochParam and ParamProposal.
773774
| `hash` | hash32type | The hash of cost model. It ensures uniqueness of entries. New in v13. |
774775
| `costs` | jsonb | The actual costs formatted as json. |
775776

777+
### `pool_stat`
778+
779+
Stats per pool and per epoch.
780+
781+
* Primary Id: `id`
782+
783+
| Column name | Type | Description |
784+
|-|-|-|
785+
| `id` | integer (64) | |
786+
| `pool_hash_id` | integer (64) | The pool_hash_id reference. |
787+
| `epoch_no` | word31type | The epoch number. |
788+
| `number_of_blocks` | word31type | Number of blocks created on the previous epoch. |
789+
| `number_of_delegators` | word31type | Number of delegators in the mark snapshot. |
790+
| `stake` | word31type | Total stake in the mark snapshot. |
791+
| `voting_power` | word31type | Voting power of the SPO. |
792+
776793
### `extra_migrations`
777794

778795
Extra optional migrations. New in 13.2.
@@ -993,15 +1010,17 @@ The table for the distribution of voting power per DRep per. Currently this has
9931010

9941011
### `epoch_state`
9951012

1013+
Table with governance (and in the future other) stats per epoch.
1014+
9961015
* Primary Id: `id`
9971016

9981017
| Column name | Type | Description |
9991018
|-|-|-|
10001019
| `id` | integer (64) | |
1001-
| `committee_id` | integer (64) | |
1002-
| `no_confidence_id` | integer (64) | |
1003-
| `constitution_id` | integer (64) | |
1004-
| `epoch_no` | word31type | |
1020+
| `committee_id` | integer (64) | The reference to the current committee. |
1021+
| `no_confidence_id` | integer (64) | The reference to the current gov_action_proposal of no confidence. TODO: This remains NULL. |
1022+
| `constitution_id` | integer (64) | The reference to the current constitution. Should never be null. |
1023+
| `epoch_no` | word31type | The epoch in question. |
10051024

10061025
### `off_chain_pool_data`
10071026

schema/migration-2-0041-20240711.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- Persistent generated migration.
2+
3+
CREATE FUNCTION migrate() RETURNS void AS $$
4+
DECLARE
5+
next_version int ;
6+
BEGIN
7+
SELECT stage_two + 1 INTO next_version FROM schema_version ;
8+
IF next_version = 41 THEN
9+
EXECUTE 'CREATe TABLE "pool_stat"("id" SERIAL8 PRIMARY KEY UNIQUE,"pool_hash_id" INT8 NOT NULL,"epoch_no" word31type NOT NULL,"number_of_blocks" word31type NOT NULL,"number_of_delegators" word31type NOT NULL,"stake" word31type NOT NULL,"voting_power" word31type NULL)' ;
10+
-- Hand written SQL statements can be added here.
11+
UPDATE schema_version SET stage_two = next_version ;
12+
RAISE NOTICE 'DB has been migrated to stage_two version %', next_version ;
13+
END IF ;
14+
END ;
15+
$$ LANGUAGE plpgsql ;
16+
17+
SELECT migrate() ;
18+
19+
DROP FUNCTION migrate() ;

0 commit comments

Comments
 (0)