Skip to content

[Bug] Add at start the entity columns SubQuery does not migrate (validators.delegator_shares) - #97

Merged
jorgecuesta merged 1 commit into
mainfrom
fix/validator-delegator-shares-column
Oct 4, 2026
Merged

jorgecuesta merged 1 commit into
mainfrom
fix/validator-delegator-shares-column

Conversation

@jorgecuesta

Copy link
Copy Markdown
Collaborator

Summary

pocketdex now adds, at start, the columns of fields added to entities that already existed: ALTER TABLE validators ADD COLUMN delegator_shares text, run only when the column is missing (an ALTER takes an exclusive lock even when it has nothing to do). A unit test compares schema.graphql with the entity fields deployed before #96 and fails when an existing entity gains a field that is not in that list.

Issue

#96 added Validator.delegatorShares. SubQuery (node-core 16.2.2) migrates the schema only when the project deployment changes, even with --allow-schema-migration: redeploying the same project created the new delegations table but never added the column, and the beta indexer crash-looped with column "delegator_shares" does not exist until the column was added by hand. Mainnet has the same table.

Testing

  • yarn test:unit: entityColumns.spec.ts reads every entity of both schemas, requires the list to match the fields added since the deployed version (it fails without the entry, and with a new field on an existing entity), and checks the column names.
  • yarn test:money (PostgreSQL): the statement adds the column to a validators table created without it, keeps its rows, and runs again as a no-op.

Deploy

Nothing beyond the image bump: on beta the column already exists (added by hand on 2026-10-03), so the check finds it and does nothing; on mainnet it adds the column before the first block is handled.

SubQuery migrates the database schema only when the project deployment changes, so redeploying with Validator.delegatorShares left databases indexed before #96 without the column and the indexer crash-looped on beta ("column delegator_shares does not exist"). The column is now added with ADD COLUMN IF NOT EXISTS before anything else at start, and a unit test compares schema.graphql with the fields deployed at 4227989, so a field added to an existing entity fails CI until it is listed there.
@jorgecuesta
jorgecuesta merged commit bc45ab8 into main Oct 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant