Declare the workflowVersion to workflow relation
workflowVersion.coreWorkflowId has pointed at core.workflow since 2.20 without ever being declared as a relation: no TypeORM ManyToOne, no entry in the metadata relation constants, and no database foreign key.
So the metadata graph treats workflowVersion as a root with no parent. That is why every place that derives "a child follows its root" from the graph gets view children for free and has to spell out workflow by hand.
What this declares
The relation is added in the three places the graph is derived from:
workflow-version.entity.ts: aManyToOnetoWorkflowEntityon the existingcoreWorkflowIdjoin column,ON DELETE CASCADE.ALL_MANY_TO_ONE_METADATA_FOREIGN_KEY:workflowVersion.coreWorkflow -> coreWorkflowId.ALL_MANY_TO_ONE_METADATA_RELATIONS: the same withmetadataName: 'workflow',isNullable: true(derived from the column),universalForeignKey: 'coreWorkflowUniversalIdentifier', andinverseOneToManyProperty: null(no inverseworkflowVersionscollection on the workflow entity, since nothing needs one and adding it widens the graph considerably).
ALL_METADATA_REQUIRED_METADATA_FOR_VALIDATION now requires workflow for workflowVersion, and the version cache loads the workflow rows it needs to resolve the universal identifier.
Three snapshots move as a result: workflowVersion now sorts before its parent in sortMetadataNamesChildrenFirst, reports workflow in getMetadataRelatedMetadataNames, and compares coreWorkflowUniversalIdentifier instead of coreWorkflowId in the universal properties.
Why the column, not the relation, carries the nullability
Based on #30630, which adds BrandedType and NullableUntilUpgrade.
The upgrade path needs a null parent. The 2.20 legacy mirror runs before 2.41 adds core.workflow's workspaceWorkflowId column, so it cannot resolve a core workflow for a legacy version and writes the row with a null parent on purpose; 2.42 relinks it, and only 2.43 sets the column NOT NULL. 2.42's relink predicate is literally v."coreWorkflowId" IS NULL, so those rows are data it rescues, not junk to skip.
I first declared the relation itself nullable, and the cross-version upgrade accepted it but it was the wrong place: the relation property would have carried | null forever to describe a window that closes. So coreWorkflowId is NullableUntilUpgrade<string> and coreWorkflow is a plain Relation<WorkflowEntity>. isNullable is still true for this relation, derived from the column rather than from the property, which is what #30630's change to ALL_MANY_TO_ONE_METADATA_RELATIONS makes possible.
What that buys: the two shared resolvers keep tolerating legacy rows, resolveUniversalRelationIdentifiersToIds in the runner and resolveManyToOneRelationIdsToUniversalIdentifiers on cache recompute, while nothing in the model claims a version's workflow is optional. The cleanup is a grep for the wrapper once 2.20 and 2.41 age out of TWENTY_CROSS_UPGRADE_SUPPORTED_VERSIONS.
One consequence worth a second opinion: the cache now resolves this foreign key, so a row pointing at a workflow that no longer exists makes cache recomputation throw, where today it is never read. The new command's data step deletes exactly those rows, but it only runs at 2.60.
Three things to look at
The workflow app manifest format changes. A version now references its workflow by coreWorkflowUniversalIdentifier rather than coreWorkflowId, because the universal shape replaces every declared foreign key with its universal identifier. That is not optional: with the relation declared, UniversalFlatWorkflowVersion omits the join column by construction. The runner's create handler resolves it back to an id with resolveUniversalRelationIdentifiersToIds, the same util the viewField handler uses.
While doing this I found that the kept-active-version path in fromWorkflowManifestToUniversalFlatWorkflowOrThrow was passing a flat version straight through as a universal one. It now translates the foreign key like the published path does.
The 2.20 legacy core upsert service had to be adapted. It is a committed upgrade command, so the change is the minimum the types force: it loads flatWorkflowMaps from the cache it already reads and resolves the universal identifier through resolve-core-workflow-universal-identifier.util.ts, kept in the 2-20 folder as a command-local helper. No logic changed, but it is an edit to a released command and worth a second pair of eyes.
The foreign key needs a data step. The new 2.60 slow instance command adds the constraint with ON DELETE CASCADE, matching the view children. Its data migration first deletes workflowVersion rows whose coreWorkflowId has no workflow: the column is already NOT NULL, so orphans cannot be nulled out and would block the constraint. There are none locally, but 2.20 backfilled that column from workspace schemas, so production data may differ.
Why now
This unblocks making children in the ownership index a plain list of child metadata names with the foreign key derived from ALL_MANY_TO_ONE_METADATA_RELATIONS, instead of a hand-written map with workflow as a standing exception.
Tests
npx jest --testPathPattern='(workflow|flat-entity|application-manifest)': 271 suites, 1970 tests pass. Typecheck adds no errors over main.