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

# Create Patch

> Create a new patch against a source resource.

Records a patch definition with compatibility constraints. The patch
can later be applied to any compatible resource within the same project.

Returns:
    Created patch record with generated ID.



## OpenAPI

````yaml https://api.pragmatiks.io/openapi.json post /projects/{project_id}/patches/resources/{resource_id}
openapi: 3.1.0
info:
  title: Pragma API
  version: 0.1.0
servers: []
security: []
paths:
  /projects/{project_id}/patches/resources/{resource_id}:
    post:
      tags:
        - patches
      summary: Create Patch
      description: |-
        Create a new patch against a source resource.

        Records a patch definition with compatibility constraints. The patch
        can later be applied to any compatible resource within the same project.

        Returns:
            Created patch record with generated ID.
      operationId: patches-create_patch
      parameters:
        - name: resource_id
          in: path
          required: true
          schema:
            type: string
            title: Resource Id
        - name: project_id
          in: path
          required: true
          schema:
            type: string
            title: Project Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreatePatchRequest'
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Patch'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    CreatePatchRequest:
      properties:
        definition:
          $ref: '#/components/schemas/PatchDefinition'
        constraints:
          items:
            $ref: '#/components/schemas/CompatibilityConstraint'
          type: array
          title: Constraints
          default: []
      type: object
      required:
        - definition
      title: CreatePatchRequest
      description: |-
        Request body for creating a new patch.

        Attributes:
            definition: Patch content describing the action and parameters.
            constraints: Compatibility constraints for target resource eligibility.
    Patch:
      properties:
        patch_id:
          type: string
          title: Patch Id
        resource_id:
          type: string
          title: Resource Id
        definition:
          $ref: '#/components/schemas/PatchDefinition'
        constraints:
          items:
            $ref: '#/components/schemas/CompatibilityConstraint'
          type: array
          title: Constraints
          default: []
        status:
          $ref: '#/components/schemas/PatchStatus'
          default: pending
        created_by:
          type: string
          title: Created By
        created_at:
          type: string
          format: date-time
          title: Created At
        error:
          anyOf:
            - type: string
            - type: 'null'
          title: Error
      type: object
      required:
        - patch_id
        - resource_id
        - definition
        - created_by
      title: Patch
      description: >-
        A patch record stored in SurrealDB.


        Patches are migration scripts, schema diffs, or configuration changes

        recorded against a source resource. They can be applied to any
        compatible

        resource that satisfies the declared constraints.


        Attributes:
            patch_id: Unique identifier for this patch.
            resource_id: SurrealDB ID of the source resource this patch was created against.
            definition: Patch content (action, parameters, description).
            constraints: Compatibility constraints for target resource eligibility.
            status: Current lifecycle status (pending, applied, failed).
            created_by: User or agent ID that created the patch.
            created_at: When the patch was created.
            error: Error message if patch application failed.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    PatchDefinition:
      properties:
        patch_id:
          type: string
          title: Patch Id
        description:
          type: string
          title: Description
          default: ''
        constraints:
          items:
            $ref: '#/components/schemas/CompatibilityConstraint'
          type: array
          title: Constraints
          default: []
        payload:
          additionalProperties: true
          type: object
          title: Payload
          default: {}
        metadata:
          additionalProperties: true
          type: object
          title: Metadata
          default: {}
      additionalProperties: false
      type: object
      required:
        - patch_id
      title: PatchDefinition
      description: >-
        Definition of a patch to apply to a resource.


        Patches are migration scripts, schema diffs, or configuration changes

        that can be applied to a resource. They include compatibility
        constraints

        to ensure they are only applied to eligible resources.


        Attributes:
            patch_id: Unique identifier for this patch.
            description: Human-readable description of what this patch does.
            constraints: Compatibility constraints the resource must satisfy.
            payload: Patch-specific data (e.g., migration script, schema diff).
            metadata: Additional context about the patch (author, source, etc.).
    CompatibilityConstraint:
      properties:
        field:
          type: string
          title: Field
        operator:
          type: string
          enum:
            - '=='
            - '!='
            - '>'
            - '>='
            - <
            - <=
            - in
          title: Operator
        value:
          title: Value
      additionalProperties: false
      type: object
      required:
        - field
        - operator
        - value
      title: CompatibilityConstraint
      description: |-
        A single constraint expression for patch eligibility.

        Constraints are evaluated against the resource's current configuration
        to determine whether a patch can be applied.

        Attributes:
            field: Config field name to check (e.g., "postgresql_version").
            operator: Comparison operator (e.g., ">=", "==", "!=", "<", ">", "<=", "in").
            value: Value to compare against. Type depends on operator.
    PatchStatus:
      type: string
      enum:
        - pending
        - dispatched
        - applied
        - failed
      title: PatchStatus
      description: |-
        Lifecycle status of a patch record.

        Attributes:
            PENDING: Patch recorded but not yet applied.
            DISPATCHED: Patch event sent to provider, awaiting confirmation.
            APPLIED: Patch confirmed applied by the provider.
            FAILED: Patch application failed.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````