spicedb
spicedb copied to clipboard
Need a way to compare schemas that is formatting agnostic
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 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
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.
@theronic What, exactly, are you trying to do? What is your intention around if the schema has changed?
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 🤔
We could look into adding a SchemaDiff API, but you could just also call WriteSchema; if there are no changes, it'll no-op
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.
We have our database migrations also call WriteSchema, so they move in sync
We should look into exporting the diff library via the API
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.
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
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?
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