SpiceDB schema Migrations using SQL
# spicedb
f
Hello, I wonder whether it is safe to directly execute sql on spicedb datastore database table if there are incompatible schema change? Whether all functions will go well after a completely spicedb restart? The benefit for migrating directly using sql is simple and execute in a transaction.
v
We do no recommend this approach because it's going to be really hard to get it done correctly, and bork your cluster, as it requires you to understand how each datastore implements its MVCC mechanisms
f
thanks, then is there a way to migrate using grpc within a database-like transaction?
v
You mean that you want to transactionally do delete/create rels and write the schema?
f
yes
transactionally delete/create/query relationships
v
SpiceDB
WriteRelationships
supports transactional create/delete of relationships, but not querying. It allows you to do snapshot reads, tho. So you can read the state of the database at a given point in time and rest assured your client will not observe any changes after the snapshot. I think one approach to do this would be: 1. Get snapshot token X, and run backfill operation based on it. Use
QueryRelationships
at that specific token X, and transactionally create/delete using
WriteRelationships
2. Use
Watch API
to stream all changes that happened since token X and backfill them. Eventually your application we be caught up and all your relationships will be backfilled, and will continue to be backfilled as the
Watch API
events are streamed 3. Deploy the version of your application that includes writing the new relations. The
Watch API
backfiller should stop backfilling when it observes that the changes from the stream include the relationships that are meant to be backfilled. At that point, that backfiller can be stopped and the process is completed. 4. Deploy the new version of the application that uses the new relation in a permission.