https://authzed.com logo
Title
r

romil

12/20/2022, 8:02 AM
Hello, Any view how to delete the Spiceb schema via rest api or cli ? I am using PostgreSQL and had a specific schema loaded. I wish to delete the same and push a new one which seems to fail. Don't see delete API nor via zed cli any option to delete ? Any view ?
v

vroldanbet

12/20/2022, 10:53 AM
👋🏻 there is no delete operation because the write schema API method replaces the entirety of the schema stored. If you are hitting an error is because you have relationships stored, so you'll need to first delete relationships and then write the new schema
this is a mechanism to prevent unitended data loss. SpiceDB checks what
definition
are deleted on your WriteSchema call, and checks if there are any relationships associated with any of the `relation`s in that
definition
r

romil

12/21/2022, 6:05 AM
Thanks
I deleted all required relation which were based on say xyz schema , now via rest api I am able to write new schema and 200 response , but now if I try to read the schema neither I see old xyz schema nor the new one ? and error says no schema defined with 404 error code
{
  "code": 5,
  "message": "No schema has been defined; please call WriteSchema to start",
  "details": []
}
@vroldanbet @Joey
v

vroldanbet

12/21/2022, 11:21 AM
are you using the same prefix as before or a different one?
r

romil

12/21/2022, 12:06 PM
Do you mean namespace ? Yes I am using different namespace, I was under assumption that if all existing schema specific relation are deleted then we can update the existing schema and add more definition which could be under different namespace
v

vroldanbet

12/21/2022, 12:29 PM
Yeah no, I believe you have to use the same namespace prefix
Think the prefix as your tenant identifier. Everything you write has to have that prefix.
r

romil

12/21/2022, 4:19 PM
Let me share an example, If I use rest api to write following schema [v1/schema/write] and fetch the same via read [v1/schema/read] it fails But if same schema is pushed via Python script and then read via rest read api , it works .
curl --location --request POST 'http://localhost:8443/v1/schema/write' \
--header 'Authorization: Bearer graphToken' \
--header 'Content-Type: application/json' \
--data-raw '{
    "schemaText": "definition authznamespace/namespace {}\n\ndefinition authznamespace/user {}"
}'
Any reason why write of above schema via rest api is not working ? [Note, rest api response is 200 ] @vroldanbet
j

Joey

12/21/2022, 4:21 PM
@romil it probably wants
schema_text
actually, its
schema
r

romil

12/21/2022, 4:22 PM
Just tried that as well and it didnt work , still returns 200 but then the read is not returning same schema . Also the swagger api says it has to be
schemaText
read schema is
schemaText
write schema is
schema
r

romil

12/21/2022, 4:23 PM
ah that worked !! thanks for correcting
j

Joey

12/21/2022, 4:24 PM
the reason it didn't give an error is that an empty schema is valid; its just ignored
r

romil

12/21/2022, 4:24 PM
yeah, thought so