Skip to content

Only apply the schema definition prefix when explicitly specified - #715

Open
josephschorr wants to merge 1 commit into
authzed:mainfrom
josephschorr:no-auto-schema-prefix
Open

Only apply the schema definition prefix when explicitly specified#715
josephschorr wants to merge 1 commit into
authzed:mainfrom
josephschorr:no-auto-schema-prefix

Conversation

@josephschorr

Copy link
Copy Markdown
Member

Schema definition prefixes are currently auto-detected. zed schema write and zed import read the existing schema from the server, extract the common prefix from its definitions, and apply that prefix to the schema being written. This existed to support Serverless, which is gone, and it has a bad failure mode: writing an unprefixed schema to a permissions system that has a prefixed one silently rewrites your definitions.

This removes determinePrefixForSchema, so the prefix is applied only when --schema-definition-prefix is passed. The flag itself is unchanged and continues to work exactly as before when specified — prefixing is now opt-in rather than the default.

Per-command impact

  • schema write — the actual behavior change. An unprefixed schema now writes through as authored. Also drops a ReadSchema round-trip.
  • import — same, and likewise one fewer round-trip.
  • schema copy — no behavior change. The prefix it inferred came from the source schema, whose definitions already carry it, and compiler.ObjectTypePrefix does not re-prefix an already-prefixed definition. It just skips a redundant compile now.

commands.ReadSchema had no remaining callers once the inference was gone, so it is removed as well.

Tests

Added a TestSchemaWrite case asserting that an existing prefixed schema on the server does not cause the written schema to be prefixed; it fails against the previous behavior. The ReadSchema mock still serves the prefixed schema so that reintroducing inference fails the assertion rather than silently passing. TestDeterminePrefixForSchema is removed along with the function. TestRewriteSchema and the import prefix tests are untouched and still pass, covering the explicit-prefix paths.

Help text on all three commands notes that no prefix is added unless specified, and docs/zed.md is regenerated.

Schema definition prefixes were auto-detected: `schema write` and `import`
read the existing schema from the server, extracted the common prefix from
its definitions, and applied that prefix to the schema being written. This
existed to support Serverless, which is gone, and it means writing an
unprefixed schema to a permissions system with a prefixed one silently
rewrites the definitions.

Remove `determinePrefixForSchema` so the prefix is applied only when
`--schema-definition-prefix` is passed. The flag continues to work exactly
as before when specified.

`schema copy` is unaffected in behavior: the prefix it inferred came from
the source schema, whose definitions already carry it, and
`compiler.ObjectTypePrefix` does not re-prefix an already-prefixed
definition. It now skips a redundant compile. `schema write` and `import`
each drop a ReadSchema round-trip.

`commands.ReadSchema` had no remaining callers and is removed.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/cmd/import.go 50.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

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