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

# GitHub Actions

> Automate updates to your models and products from JSON config files in your GitHub repo.

## Overview

Prequel offers GitHub Actions to automate updates to your **models** and **products** based on `.json` config files stored in your GitHub repo.

Use these to:

* Keep your model/product configs version-controlled
* Automatically sync changes to Prequel on every commit
* Define your data contract directly in code

## Supported actions

You can use the following GitHub Actions provided by Prequel:

* `prequel-co/apply-model-configs@v1`, upserts models
* `prequel-co/apply-product-configs@v1`, upserts products

These GitHub actions utilize the Prequel API and apply config files from your repo directly into your Prequel instance.

**Note that the sample is set up to update configs for your `production` environment in Prequel.** To set up an action that will update `staging` configs, update the `branches` field to point to your staging branch, and pass it your `PREQUEL_STAGING_API_KEY` instead of the production one.

```yaml title="prequel_cd.yaml" theme={null}
# This is a basic workflow to help you get started with Prequel Actions

name: Prequel Continuous Delivery

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "main" branch
  push:
    branches: [ "main" ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  sync:
    name: Sync with Prequel
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Upsert Models
        uses: prequel-co/apply-model-configs@v1
        with:
          host: https://api.prequel.co
          api_key: ${{ secrets.PREQUEL_API_KEY }}
          mode: export
          dir: prequel/models/*.json

      - name: Upsert Products
        uses: prequel-co/apply-product-configs@v1
        with:
          host: https://api.prequel.co
          api_key: ${{ secrets.PREQUEL_API_KEY }}
          mode: export
          dir: prequel/products/*.json
```

## Model config format

Model config files live in your repo. The default locations `prequel/models/*.json` and `prequel/products/*.json` can be overwritten with the `dir` field). Each file describes **one model** and is passed into the `apply-model-configs` action. Data model configuration is documented in full below.

* [Data model configuration](/export/concepts/models#data-model-configuration)
* [Model API Reference](/export/api-reference/models/create-model)

```json title="example_model_config.json" theme={null}
{
  "model_name": "logs",
  "columns": [
    {
      "name_in_source": "id",
      "name_in_destination": "id",
      "data_type": "text",
      "is_primary_key": true,
      "is_last_modified": false
    },
    {
      "name_in_source": "log",
      "name_in_destination": "event_log",
      "description":"A descriptive text entry of the event that occurred.",
      "data_type": "text",
      "is_primary_key": false,
      "is_last_modified": false
    },
    {
      "name_in_source": "updated_at",
      "name_in_destination": "updated_at",
      "data_type": "timestamp",
      "is_primary_key": false,
      "is_last_modified": true
    }
  ],
  "source_table": "source_schema.application_logs",
  "source_name": "Example Production Source",
  "organization_column": "organization_id"
}
```

<Note>
  Tip: Using `source_name` instead of `source_id` provides stability across both staging and prod environments, whereas `source_id` is environment-specific.
</Note>

## Product config format

Product config files live in your repo (e.g. `prequel/products/*.json`) and define which models are grouped together into a "product" for sync. Each file defines **one product**. Product configuration is documented in more detail below.

* [Product configuration](/export/concepts/products#getting-started-with-products)
* [Product API Reference](/export/api-reference/products/create-product)

```json title="transactions_product.json" theme={null}
{
  "models": ["transactions"]
}
```

<Note>
  Currently, you cannot attach a model to a product **from the model config itself**, products must reference the model explicitly using this method.
</Note>

## FAQ

<AccordionGroup>
  <Accordion title="Can I use branch names to isolate models per environment?">
    Yes. A common pattern is to override `model_name` based on branch name to prevent collisions. This can be done using custom scripting in your workflow or naming conventions in your files.
  </Accordion>

  <Accordion title="Where should I store these config files?">
    These should live in your GitHub repo (e.g., `prequel/models/*.json`, `prequel/products/*.json`). They are pulled by the GitHub Action and applied to Prequel automatically.
  </Accordion>
</AccordionGroup>

## Additional resources

* [Model API reference](/export/api-reference/models/create-model)
* [Product API reference](/export/api-reference/products/create-product)
* [Model overview](/export/concepts/models)
* [Destination setup guides](/export/destinations/overview)
