API - Add upgrade-safe checks to ensure table exists before reading #18135
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.
Overview
This adds efficient checks into the api (v3 and v4) to ensure a DAO table exists before trying to read from it.
This prevents hard-crashes in the UI when there are pending updates (or during the upgrade process itself)
Before
Checks on fields but not the entire table.
After
Efficiently check if a table exists (without requiring an extra query) before trying to read from it.
Technical Details
Adds information to each DAO file about what extension it belongs to (
const EXT
is either 'civicrm' or the name of the extension). Avoids doing version checks on non-core tables as extension checks would have to be implemented differently (a good idea but not part of this PR).Comments
TODO: Add these checks for extensions' tables if there are pending extension upgrades.
Another TODO would be to also perform this check before attempting a join. Currently this check is limited to the primary table.