Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a way to compare schemas that is formatting agnostic #1804

Closed
theronic opened this issue Mar 15, 2024 · 12 comments · Fixed by #1885
Closed

Need a way to compare schemas that is formatting agnostic #1804

theronic opened this issue Mar 15, 2024 · 12 comments · Fixed by #1885
Assignees
Labels
kind/proposal Something fundamentally needs to change

Comments

@theronic
Copy link

theronic commented Mar 15, 2024

Problem Statement

If you call .readSchema after calling .writeSchema (via GRPC), Spice returns a schema string with reordered definitions that does not match the string that was written. I want to compare if my schema is up-to-date without writing a parser for the SpiceDB schema language.

Solution Brainstorm

Return the same schema text string that was written via .writeSchema.

Alternatively, is there a "compareSchema" function somewhere?

@theronic theronic added the kind/proposal Something fundamentally needs to change label Mar 15, 2024
@josephschorr
Copy link
Member

@theronic https://github.com/authzed/spicedb/tree/main/pkg/diff has a diff package which can be used after parsing the schema

SpiceDB always returns the normalized, ordered schema and that won't be changing; we don't store the actual text

@theronic
Copy link
Author

Thanks @josephschorr, but my application is not written in Golang. Can diff be exposed via gRPC? If it's part of zed CLI, would have to shell out, or add a Golang wrapper in my Clojure application.

@josephschorr
Copy link
Member

@theronic What, exactly, are you trying to do? What is your intention around if the schema has changed?

@theronic
Copy link
Author

I'm trying to compare if the schema in prod SpiceDB instance differs from the Spice schema I have on-disk, e.g. when deploying a new version of app. At this stage, just convenient to check that I know I'm querying the right schema.

I guess I'll need schema migrations anyway 🤔

@josephschorr
Copy link
Member

We could look into adding a SchemaDiff API, but you could just also call WriteSchema; if there are no changes, it'll no-op

@theronic
Copy link
Author

Thanks. How do you keep track of Spice schema versioning?

Practical example similar to mismatched database schema: given a set of schema migrations, prod might think it has v3 of Spice Schema, but since schema is stateful, a different schema could have been written to Spice, so I'd like to ensure that the current production schema matches the previous migration that was run before running additional migrations.

@josephschorr
Copy link
Member

We have our database migrations also call WriteSchema, so they move in sync

@josephschorr josephschorr changed the title GRPC .readSchema returns schemaText that differs from the schema that was written Need a way to compare schemas that is formatting agnostic Mar 15, 2024
@josephschorr josephschorr reopened this Mar 15, 2024
@josephschorr
Copy link
Member

We should look into exporting the diff library via the API

@theronic
Copy link
Author

Thanks. How do you keep track of which schema version was written to Spice? External hash / commit / version number in DB?

Would be nice if SchemaService took a DiffSchemaRequest and returned whatever the diff pkg would return.

@josephschorr
Copy link
Member

Thanks. How do you keep track of which schema version was written to Spice? External hash / commit / version number in DB?

Yep

Would be nice if SchemaService took a DiffSchemaRequest and returned whatever the diff pkg would return.

Yeah, I updated the issue for that and reopened it

@theronic
Copy link
Author

Is there a BNF syntax spec somewhere for the Schema language in the meantime so I can parse the schema text and compare the sorted parse tree?

@josephschorr
Copy link
Member

josephschorr commented Mar 25, 2024

Is there a BNF syntax spec somewhere for the Schema language in the meantime so I can parse the schema text and compare the sorted parse tree?

No. The implementation is considered the spec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/proposal Something fundamentally needs to change
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants