Skip to content

Provide path_to_schema to SchemaArtifactManager - #1316

Open
jwils wants to merge 1 commit into
mainfrom
joshuaw/artifact-manager-schema-path
Open

Provide path_to_schema to SchemaArtifactManager#1316
jwils wants to merge 1 commit into
mainfrom
joshuaw/artifact-manager-schema-path

Conversation

@jwils

@jwils jwils commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

Today, every schema artifact is a pure function of the schema definition: the schema artifacts directory can safely be deleted and regenerated at any time. In #1304 (comment), @myronmarston pointed out that proto_field_numbers.yaml doesn't fit that model--it's an input to schema.proto generation, not a pure output--and suggested treating it as part of the schema definition, stored as a sibling of path_to_schema, rather than as a schema artifact.

For an extension to maintain a file there, the SchemaArtifactManager needs to know where the schema definition lives. RakeTasks already knows (it's how the schema gets loaded) but never passed it along. This PR plumbs path_to_schema through Factory#new_schema_artifact_manager into the manager so that extensions which maintain schema-definition-adjacent files can use it.

Nothing in core uses the value yet, so there are no behavior changes to the core artifacts. #1304 will build on this to relocate proto_field_numbers.yaml.

The schema artifacts directory is safe to delete and regenerate: every
artifact is a pure function of the schema definition. Some extensions
need to maintain a file that doesn't fit that model--one that is an
*input* to artifact generation and therefore belongs alongside the
schema definition itself rather than in the artifacts directory. The
manager previously had no way to know where the schema definition
lives, so give it `path_to_schema`, which `RakeTasks` already knows.
@schema_artifacts_directory = schema_artifacts_directory
# Supports extensions that need to maintain files alongside the schema definition, rather
# than in the schema artifacts directory.
@path_to_schema = path_to_schema

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems weird to store it on SchemaArtifactManager when it's not used by SchemaArtifactManager. And instance variables are in general a more brittle extension mechanism because if of how Ruby treats ivars: they spring into existence when first referenced, so if you mispell the name of the ivar, Ruby will just make a new one.

An alternate suggestion:

  • Store path_to_schema on SchemaDefinitition::State
  • Change SchemaArtifactManager to accept schema_def_api (which has access to state) rather than schema_definition_results--it can call schema_def_api.results to get the results, and that way an extension has access to schema_def_api.state.path_to_schema.

Separately, it's worth considering if it's best to have SchemaArtifactManager generate the proto numbers file. If we're saying it's not a schema artifact, it seems odd to have the SchemaArtifactManager dump it!

That said:

  • Apart from the slight naming mismatch, I don't see a reason to not have SchemaArtifactManager dump it.
  • I'd only consider having it generated somewhere else if it was just as simple. If it's much more complex to dump it from somewhere else then I'd rather do it in a SchemaArtifactManager extension in spite of the name mis-match.
  • One concrete thing the SchemaArtifactManager does is checks all the artifacts (when you run be rake schema_artifacts:check). It's not clear to me if that's meaningful and useful for the proto numbers file or not. (I'm guessing it is, becaues that's probably how you'd ensure every field and enum value is in the file.)

Thoughts?

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.

2 participants