[Bug] Add at start the entity columns SubQuery does not migrate (validators.delegator_shares) - #97
Merged
Conversation
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.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 comparesschema.graphqlwith 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 newdelegationstable but never added the column, and the beta indexer crash-looped withcolumn "delegator_shares" does not existuntil the column was added by hand. Mainnet has the same table.Testing
yarn test:unit:entityColumns.spec.tsreads 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 avalidatorstable 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.