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

# Restore a CodeGen script version

> Makes the text of `version` the script the pipeline runs, through the same store path as a regenerate but with no model call: it becomes a NEW latest version (origin `restore-version`) and keeps the model that wrote it. A built-in script object is replaced; a repository-backed script gets a new commit. The pipeline's definition version does not change. When the version's text is already the live script, nothing is written (no version, no commit) and the current entry is returned with `noop: true`. Refused, with nothing changed, when the version was written for a different instruction or source schema than the pipeline has now, or for another script contract version (422), and when the repository file was edited since the recorded commit (409). Requires `pipeline:update` (agent-policy action `pipeline:update:codegen-scripts`). Audited as `codegen-script-restore-version:<kind>`.



## OpenAPI

````yaml /openapi.yaml post /api/v1/pipelines/{name}/codegen-scripts/{kind}/versions/{version}/restore
openapi: 3.0.3
info:
  title: Datris API
  description: >
    REST API for the Datris AI Data Platform. Ingest, validate, transform,
    store, and retrieve data.


    For AI agent integration, use the [MCP
    Server](https://docs.datris.ai/mcp-server) instead.
  version: 1.28.0
  contact:
    name: Datris
    url: https://datris.ai
  license:
    name: Apache 2.0
servers:
  - url: http://localhost:8080
    description: Local development
security:
  - ApiKeyAuth: []
paths:
  /api/v1/pipelines/{name}/codegen-scripts/{kind}/versions/{version}/restore:
    post:
      tags:
        - Pipelines
      summary: Restore a CodeGen script version
      description: >-
        Makes the text of `version` the script the pipeline runs, through the
        same store path as a regenerate but with no model call: it becomes a NEW
        latest version (origin `restore-version`) and keeps the model that wrote
        it. A built-in script object is replaced; a repository-backed script
        gets a new commit. The pipeline's definition version does not change.
        When the version's text is already the live script, nothing is written
        (no version, no commit) and the current entry is returned with `noop:
        true`. Refused, with nothing changed, when the version was written for a
        different instruction or source schema than the pipeline has now, or for
        another script contract version (422), and when the repository file was
        edited since the recorded commit (409). Requires `pipeline:update`
        (agent-policy action `pipeline:update:codegen-scripts`). Audited as
        `codegen-script-restore-version:<kind>`.
      parameters:
        - name: name
          in: path
          required: true
          schema:
            type: string
        - in: path
          name: kind
          required: true
          schema:
            type: string
            enum:
              - dataQuality
              - transformation
        - in: path
          name: version
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: The script entry, now carrying the new `version`
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CodegenScript'
        '400':
          description: Unknown kind, or the pipeline has no AI instruction of that kind
        '404':
          description: Unknown pipeline or version
        '409':
          description: >-
            The script's file was edited in the code repository since the
            recorded commit; nothing was committed.
        '422':
          description: >-
            The version was written for a different instruction, source schema
            or script contract than the pipeline has now; nothing was changed.
        '502':
          description: The script could not be stored; the current script is unchanged
components:
  schemas:
    CodegenScript:
      type: object
      description: A stored CodeGen script (AI data-quality rule or AI transformation).
      properties:
        kind:
          type: string
          enum:
            - dataQuality
            - transformation
        instruction:
          type: string
        script:
          type: string
          nullable: true
        generatedAt:
          type: string
          format: date-time
          nullable: true
        model:
          type: string
          nullable: true
          description: The CodeGen model that wrote the script.
        modelIsCurrent:
          type: boolean
          description: False when the CodeGen model setting has changed since.
        status:
          type: string
          enum:
            - ready
            - pending
        pendingReason:
          type: string
          nullable: true
        origin:
          type: string
          enum:
            - save
            - run
            - regenerate
            - repository
            - restore
            - restore-version
          nullable: true
          description: >-
            How the current script was recorded. `repository` means an edit made
            in the code repository was adopted with the pull endpoint; `restore`
            means it was imported from a catalog archive; `restore-version`
            means an earlier script version was restored.
        version:
          type: integer
          description: >-
            Number of the live script in its version history. Absent for a
            script stored before script versioning (it is numbered 1 on the
            first change or history read).
        fingerprint:
          type: string
          nullable: true
          description: >-
            sha-256 of the instruction and source schema the script was written
            for; a restore keeps the archived value.
        storage:
          type: string
          description: >-
            Script store: `minio` for the built-in object store, `github` for
            the configured code repository.
          nullable: true
        repoPath:
          type: string
          nullable: true
          description: >-
            Code repository only. Path of the script file on the configured
            branch: `<pathPrefix>pipelines/<pipeline>/data-quality.py` or
            `.../transformation.py`.
        commitSha:
          type: string
          nullable: true
          description: Code repository only. The commit every run executes.
        drift:
          type: boolean
          description: >-
            True when the file at the head of the configured branch differs from
            the recorded commit (it was edited in the repository). Runs keep
            using the recorded commit until the edit is pulled. Always false for
            built-in storage.
        headSha:
          type: string
          description: >-
            Present when `drift` is true. The branch-head commit the pull
            endpoint would record.
        conflict:
          type: boolean
          description: >-
            True while a new script was not committed because the file was
            edited in the code repository since the recorded commit. Runs keep
            executing the recorded commit, without the new instruction or schema
            and with no model call, until the edit is pulled or the script is
            regenerated with `overwrite=true`. Present when the script has a
            record.
        conflictReason:
          type: string
          description: >-
            Present when `conflict` is true. The warning the save or regenerate
            returned.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: Optional API key for authentication (enabled via application.yaml)

````

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