> ## Documentation Index
> Fetch the complete documentation index at: https://proxy-docs.permify.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Partial Schema Update

As development teams regularly roll out new features or API endpoints, features each addition often necessitates corresponding updates to the Permify schema.

To streamline this process, we have published an endpoint allows authorized users to make partial updates to the schema by adding or modifying actions within individual entities.

## **Endpoint Definition**

**`/v1/tenants/{tenant_id}/schemas/partial-write`**

This endpoint allows authorized users to make partial updates to the schema by adding or modifying actions within individual entities.

**Request Payload Structure**

```bash theme={null}
PATCH /v1/tenants/{tenant_id}/schemas/partial-write
Content-Type: application/json
```

body:

```json theme={null}
{
  "metadata": {
    "schema_version": ""
  },
  "partials": {
		"<entity-name>": {
			"write": [],
			"delete": [],
			"update": []
		}
  }
}
```

### **Behavior Description**

When the **`schema_version`** in the request metadata is left empty, the system will default to using the latest(head) schema version as the base for updates.

* **`name`** (string): The name of the entity to be changed.
* **`write`** (string array): Conditions to be added. If a relation or permission/action already exists, it should return an error.
* **`delete`** (string array): Names (permissions/actions) to be deleted. If the relation/permission/action name does not exist, it should return an error. Note: specifying the name is enough as relation/permission/action names should be unique.
* **`update`** (string array): Conditions to be updated.

If **`schema_version`** is specified, the endpoint will perform the same update process on the given version and generate a new version thereafter.

**Partial Schema Endpoint Example Usage**

**Existing Schema**

```bash theme={null}
entity user {}

entity organization {
    relation admin @user
    relation member @user
}

entity team {
    relation owner @user
    relation org @organization

    permission edit = org.admin or owner
    permission delete = org.admin or owner
}
```

The code block above outlines the existing schema definitions for the **`user`**, **`organization`**, and **`team`** entities. This includes their respective relationships and permissions within the schema.

### Partial Schema Update Request

To update the **`team`** entity by introducing new permissions, the following PATCH request with the accompanying payload is sent:

```json theme={null}
{
  "metadata": {
    "schema_version": ""
  },
  "partials": {
		"team": {
		  "write": [
		    "relation member @user",
		    "permission invite = org.admin and (owner or member)",
		    "permission remove_user = owner"
		  ],
		  "delete": [
		    "edit"
		  ],
		  "update": [
		    "permission delete = member"
		  ]
		}
	}
}
```

By leaving the **`schema_version`** empty string, it signals the system to take the latest(head) schema version as a base for applying updates.

### **Resulting Schema After Update**

After the request is processed, the system outputs a new schema version where the **`team`** entity is revised to include the new permissions as illustrated below:

```json theme={null}
entity user {}

entity organization {
    relation admin @user
    relation member @user
}

entity team {
    relation owner @user
    relation member @user
    relation org @organization

    permission delete = member
    permission invite = org.admin and (owner or member)
    permission remove_user = owner
}
```

**`invite`** and **`remove_user`** permissions have been added, a **`member`** relation has been included, the **`edit`** permission has been deleted, and the **`delete`** permission has been updated.


## OpenAPI

````yaml patch /v1/tenants/{tenant_id}/schemas/partial-write
openapi: 3.0.0
info:
  title: Permify API
  description: >-
    Permify is an open source authorization service for creating fine-grained
    and scalable authorization systems.
  version: v1.7.6
  contact:
    name: API Support
    url: https://github.com/Permify/permify/issues
    email: hello@permify.co
  license:
    name: AGPL-3.0 license
    url: https://github.com/Permify/permify/blob/master/LICENSE
servers: []
security: []
tags:
  - name: Permission
  - name: Watch
  - name: Schema
  - name: Data
  - name: Bundle
  - name: Tenancy
paths:
  /v1/tenants/{tenant_id}/schemas/partial-write:
    patch:
      tags:
        - Schema
      summary: partially update your authorization model
      operationId: schemas.partial-write
      parameters:
        - name: tenant_id
          description: >-
            tenant_id is a string that identifies the tenant. It must match the
            pattern "[a-zA-Z0-9-,]+",

            be a maximum of 64 bytes, and must not be empty.
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PartialWriteBody'
        required: true
      responses:
        '200':
          description: A successful response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SchemaPartialWriteResponse'
        default:
          description: An unexpected error response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Status'
components:
  schemas:
    PartialWriteBody:
      type: object
      properties:
        metadata:
          $ref: '#/components/schemas/SchemaPartialWriteRequestMetadata'
        partials:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Partials'
          title: Map of entity name with the values needed to be updated
      title: >-
        It contains the tenant_id to identify the tenant and metadata of the
        schema to be edited,

        with the corresponding edits to various entities
    SchemaPartialWriteResponse:
      type: object
      properties:
        schema_version:
          type: string
          description: >-
            schema_version is the string that identifies the version of the
            written schema.
      description: >-
        SchemaPartialWriteResponse is the response message for the Parietal
        Write method in the Schema service.

        It returns the requested schema.
    Status:
      type: object
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string
        details:
          type: array
          items:
            $ref: '#/components/schemas/Any'
    SchemaPartialWriteRequestMetadata:
      type: object
      properties:
        schema_version:
          type: string
          description: >-
            schema_version is the string that identifies the version of the
            schema to be read.
      description: >-
        SchemaPartialWriteRequestMetadata provides additional information for
        the Schema Partial Write request.

        It contains schema_version to specify which version of the schema should
        be read.
    Partials:
      type: object
      properties:
        write:
          type: array
          items:
            type: string
        delete:
          type: array
          items:
            type: string
        update:
          type: array
          items:
            type: string
      title: Partials contains the write, update and delete definitions
    Any:
      type: object
      properties:
        '@type':
          type: string
          description: >-
            Identifies the type of the serialized Protobuf message with a URI
            reference

            consisting of a prefix ending in a slash and the fully-qualified
            type name.


            Example: type.googleapis.com/google.protobuf.StringValue


            This string must contain at least one `/` character, and the content
            after

            the last `/` must be the fully-qualified name of the type in
            canonical

            form, without a leading dot. Do not write a scheme on these URI
            references

            so that clients do not attempt to contact them.


            The prefix is arbitrary and Protobuf implementations are expected to

            simply strip off everything up to and including the last `/` to
            identify

            the type. `type.googleapis.com/` is a common default prefix that
            some

            legacy implementations require. This prefix does not indicate the
            origin of

            the type, and URIs containing it are not expected to respond to any

            requests.


            All type URL strings must be legal URI references with the
            additional

            restriction (for the text format) that the content of the reference

            must consist only of alphanumeric characters, percent-encoded
            escapes, and

            characters in the following set (not including the outer backticks):

            `/-.~_!$&()*+,;=`. Despite our allowing percent encodings,
            implementations

            should not unescape them to prevent confusion with existing parsers.
            For

            example, `type.googleapis.com%2FFoo` should be rejected.


            In the original design of `Any`, the possibility of launching a type

            resolution service at these type URLs was considered but Protobuf
            never

            implemented one and considers contacting these URLs to be
            problematic and

            a potential security issue. Do not attempt to contact type URLs.
      additionalProperties: {}
      description: >-
        `Any` contains an arbitrary serialized protocol buffer message along
        with a

        URL that describes the type of the serialized message.


        In its binary encoding, an `Any` is an ordinary message; but in other
        wire

        forms like JSON, it has a special encoding. The format of the type URL
        is

        described on the `type_url` field.


        Protobuf APIs provide utilities to interact with `Any` values:


        - A 'pack' operation accepts a message and constructs a generic `Any`
        wrapper
          around it.
        - An 'unpack' operation reads the content of an `Any` message, either
        into an
          existing message or a new one. Unpack operations must check the type of the
          value they unpack against the declared `type_url`.
        - An 'is' operation decides whether an `Any` contains a message of the
        given
          type, i.e. whether it can 'unpack' that type.

        The JSON format representation of an `Any` follows one of these cases:


        - For types without special-cased JSON encodings, the JSON format
          representation of the `Any` is the same as that of the message, with an
          additional `@type` field which contains the type URL.
        - For types with special-cased JSON encodings (typically called
        'well-known'
          types, listed in https://protobuf.dev/programming-guides/json/#any), the
          JSON format representation has a key `@type` which contains the type URL
          and a key `value` which contains the JSON-serialized value.

        The text format representation of an `Any` is like a message with one
        field

        whose name is the type URL in brackets. For example, an `Any` containing
        a

        `foo.Bar` message may be written `[type.googleapis.com/foo.Bar] { a: 2
        }`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.