How to write schemas
# spicedb
y
yes
l
So there is no recommended "migration-like" pattern for managing updates to the spicedb schema, is that correct?
I setup spicedb the first time, write the schema, write initial relationships with a script, keep relationships up to date with application logic, and do backups via zed?
y
you can do backups at the datastore level as long as whatever mechanism is physical
otherwise yeah you can take backups with
zed backup
we keep our spicedb schema in the associated codebase and write the schema on app startup
what do you mean by "migration-like?"
l
> backups at the datastore level oh that makes sense. heh
migration-like: captured in repository, code-like source of truth of the changes over time, that can be applied to return to the current state
I don't anticipate schema updates in my project, but I also know better than to assume it will never happen.
In my usecase, such updates may need to be applied to instances that I don't exactly run, so I need to be able to vend the incremental change that should be applied to my clients
I can presumably handroll something in the application, but I like to check first that I'm not reinventing the wheel
y
yeah there isn't like a migration framework if that's what you're thinking
but part of that is that a
WriteSchema
call is always the entire schema
so there's no notion of incremental updates
l
What happens if the WriteSchema invalidates previous relationships? are those just left around and unreachable?
j
no
y
the only thing to pay attention to is that you can't do a destructive migration until all of the relations assocaited with the removed part of the schema have been removed
j
it fails withn an error
l
oh phew
j
you cannot write a schema that is inconsistent
you could, say, remove a permission
and then checks would fail on it
but you can't have data inconsistency
our recommendation is to have a CI/CD process that uses
zed validate
or the equivalent GitHub Action to validate the schema + the assertions
and then have either an automatic or manual process to call
WriteSchema
down the road, we have plans for the ability to "stage" a schema change so you can do a progressive rollout
but that's the future
l
that recommendation sounds doable in my situation
thanks :)
96 Views