Join core.Documents rows to parent details #7319
Open
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.
Rationale
Improve the
core.Documentsquery by joining to each document's parent and providingParent DescriptionandOrphanedcolumn. This makes it easier to find the parent document and highlights attachments that have been orphaned. https://github.com/LabKey/internal-issues/issues/711Also, fix the extraction of entity IDs from data class LSIDs. At some point, the extraction method got out-of-sync with the LSIDs we produce, which resulted in data class attachment rows not getting correctly populated with their parent type. Once we've tested this PR, I'll add a new SQL script to re-run the upgrade code that populates the
ParentTypecolumn.Some notes and caveats:
nullparent description, so filtering on ParentDescription IS BLANK is a reasonable way to find orphans. However, it may be possible for a parent to have a null description (e.g., a parent document with a null title); the hidden boolean fieldOrphanedprovides a definitive check.<Root>).Changes
AttachmentParentType.getSelectEntityIdAndDescriptionSql()that returns SQL that selects the parents' EntityId and a Description that identifies that parent. ReworkgetSelectParentEntityIdsSql()to simply wrap the new method, selecting only EntityId (to allow use within an IN clause).null.Lsid.getSqlExpressionToExtractObjectId()so it correctly extracts EntityIds from data class LSIDs. Add a junit test to keep this working.LabKeyCollectors.joining(SQLFragment)that joins aString<SQLFragment>into a single SQLFragment.SQLFragment.join()to correctly handle corner cases like CTEs and temp tokens.Tasks 📍
UPDATE core.Documents SET ParentType = NULL)core.Documentsto ensure all attachments of that type are tagged with the appropriateParentTypeand show a reasonableParentDescriptioncore.DocumentsGroupedByParentType, which allows querying specific projects and folders with a container filter applied.