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

# Supabase connector

> Use the Supabase connector to index data from a Supabase table or view.

export const Records = () => <Tooltip tip="A record is a searchable object in an Algolia index. Each record consists of named attributes." cta="Algolia records" href="/doc/guides/sending-and-managing-data/prepare-your-data#algolia-records">
    records
  </Tooltip>;

Use the Supabase connector to index <Records /> from a Supabase table or view without writing an indexing script.

In this quickstart, you create a Supabase source, transform the records, create an Algolia destination, and configure a synchronization task.

<Frame>
  <iframe width="644" height="363" src="https://www.youtube.com/embed/sLr6-K7_Av8" title="How to integrate Algolia with your Supabase project" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen className="video-embed" />
</Frame>

## Before you begin

Make sure you have:

* **An Algolia account**. [Create one for free](https://www.algolia.com/users/sign_up) if you don't already have one.
* **A Supabase project with the sample data in a `public.apparel` table**.
  Download the [Algolia apparel sample data](https://raw.githubusercontent.com/algolia/quickstarts/main/sample-data/apparel.csv)
  and follow Supabase's [data import instructions](https://supabase.com/docs/guides/database/import-data).
  Use `objectID` as the table's primary key.

## Set up the Supabase connector

Create a source, transformation, destination, and synchronization task.

<Steps>
  <Step title="Choose the Supabase connector">
    Go to the Algolia dashboard and select your Algolia application.

    Open the [**Connectors**](https://dashboard.algolia.com/connectors) page.

    Find [**Supabase** and select **Connect**](https://dashboard.algolia.com/connectors/supabase).
    Under **Quick setup**, select **Connect Supabase**.
  </Step>

  <Step title="Configure the Supabase source" id="source">
    For **Select a project**,
    choose the project containing the `public.apparel` table.
    The connector copies **Host**, **Port**, **Session Pooler Port**, **Database Name**, **Username**, and **Password** values from your Supabase project.

    For **SSL modes**, select **Prefer**.

    In **Connector name**,
    enter `Quickstart products Supabase source`,
    then select **Create source**.
  </Step>

  <Step title="Transform the records" id="transform">
    This transformation adds a `price_range` attribute to each record.
    After the connector indexes your records, you can display `price_range` or configure it as a facet.

    Select **Transform using the code editor** and replace the placeholder **Transformation code** with this function:

    ```js JavaScript icon=code expandable theme={"system"}
    async function transform(record, helper) {
        const price = Number(record.price);
        if (!Number.isFinite(price)) {
            return record;
        }
        if (price < 25) {
            record.price_range = "Under $25";
        } else if (price < 50) {
            record.price_range = "$25 to $49";
        } else if (price < 100) {
            record.price_range = "$50 to $99";
        } else {
            record.price_range = "$100 and up";
        }
        return record;
    }
    ```

    Select **Save**.
  </Step>

  <Step title="Choose the destination index">
    Under **Configure your destination**,
    select **Create a new destination**.

    Under **Search**,
    enter `quickstart-products` as the index name.

    <Warning>
      If you use an existing index,
      running the connector overwrites the records and settings in that index.
    </Warning>
  </Step>

  <Step title="Create the destination" id="destination">
    Under **Index credentials**,
    select **Create one for me**.

    To use an existing API key,
    choose one with the `addObject`, `deleteIndex`, and `editSettings`
    [access control list permissions](/doc/guides/security/api-keys#access-control-list-acl).

    In **Name**,
    enter `Supabase quickstart products destination`,
    then select **Create destination**.
  </Step>

  <Step title="Create and run an on-demand synchronization task" id="task">
    Under **Configure your task**,
    select **On demand** and clear **Scheduled**.

    Select **Full reindexing**.

    Select `apparel` as the source table.
    Select all columns.
    For **ObjectID**, select `objectID`.

    Select **Create task**,
    then **Run**,
    and wait for the task to finish.
  </Step>

  <Step title="Verify the indexed records">
    Open the
    [`quickstart-products` index in the Algolia dashboard](https://dashboard.algolia.com/explorer/browse/quickstart-products).

    Check that the index contains the imported product records,
    with attributes such as `title`, `description`, `product_type`,
    `price`, `price_range`, and `showcase_image`.
  </Step>
</Steps>

<Info>
  You can use this index as the data source for
  [Build your first search experience](/doc/guides/get-started/quickstart).

  Before you build the UI,
  [configure `product_type` as an attribute for faceting](/doc/guides/managing-results/refine-results/faceting/how-to/declaring-attributes-for-faceting-with-dashboard)
  in the `quickstart-products` index.
</Info>

## Index your own Supabase data

To index your own data:

* Use a populated Supabase table or view that the connector credentials can read.
* Follow the quickstart steps to create the [source](#source), [destination](#destination), and [task](#task). Replace the sample project, table, credentials, and destination index with your own values.
* Review or remove the sample transformation so that it matches your record structure. When you configure the task, select the columns you want to include in your Algolia records.
* Select the column to use as the Algolia `objectID`. This column must be present in every row, and its value must be unique and stable.

### Supabase database credentials

The quickstart uses the database settings imported from your Supabase project.
For your own data, create a dedicated Postgres login role for the connector.
Grant the role permission to:

* Connect to the database.
* Use the schema that contains the source data.
* Run `SELECT` queries on each table or view the connector needs to read.

If Row Level Security (RLS) is enabled,
add a `SELECT` policy that lets the connector role read the rows you want to index.

For more information, see [Postgres roles](https://supabase.com/docs/guides/database/postgres/roles) and
[Row Level Security](https://supabase.com/docs/guides/database/postgres/row-level-security).

### Configure the connector username

Supabase's session pooler details show the username for the default `postgres` role.
When you configure the source,
replace `postgres` with the dedicated connector role name,
but keep the project reference after the period.

For example, for a connector role named `algolia_connector`,
replace `postgres.PROJECT_REFERENCE` with `algolia_connector.PROJECT_REFERENCE`.

### Combine data with a Postgres view

An Algolia record can combine data from several Supabase tables.
For example, a product record might combine product details with review ratings and recent order data.

If your source data spans multiple tables,
create a Postgres view that joins and aggregates the required data.
Then, select the view as the source when you configure the synchronization [task](#task).

Make sure each row in the view includes a unique, stable column that you can use as the Algolia `objectID`.
This example creates a view that combines data from the `apparel` and `reviews` tables.

```sql SQL icon="database" theme={"system"}
create view apparel_search
with (security_invoker = true)
as
select
  p."objectID",
  p.title,
  p.description,
  p.price,
  avg(r.rating) as average_rating,
  count(distinct r.id) as review_count
from apparel as p
left join reviews as r on r.product_id = p."objectID"
group by p."objectID", p.title, p.description, p.price;
```

Create a separate synchronization task for each table or view you want to index.

For more information,
see [Prepare your data in Supabase](https://supabase.com/blog/algolia-connector-for-supabase#1-prepare-your-data-in-supabase).

### Transformations

Use transformations to add computed attributes or change values before the connector indexes your records.
To use a transformed attribute for search, faceting, or ranking,
update the relevant [index settings](/doc/api-reference/settings-api-parameters),
such as `searchableAttributes`, `attributesForFaceting`, or `customRanking`.

<Note>
  Test transformations with repeated task runs.
  Transformations that read from and write to the same attribute,
  or extract a value and then delete the source attribute,
  can produce different results when the task runs again.
</Note>

### Synchronization schedule

After you create a task,
you can [edit it in the Algolia dashboard](https://dashboard.algolia.com/connectors/tasks) to choose when the connector runs:

* **On demand**. Run the connector manually.
* **Scheduled**. Select a predefined schedule or enter a custom [cron expression](https://crontab.guru/).

### Indexing strategy

You can choose how the connector updates your index.
For information about full reindexing, full record updates, and partial record updates,
see [Data synchronization strategies](/doc/guides/sending-and-managing-data/send-and-update-your-data/in-depth/the-different-synchronization-strategies).

## Limitations

This connector is subject to the following limitations:

* [Connectors limits](/doc/guides/scaling/algolia-service-limits/#connectors-limits)
* [Transformation limits](/doc/guides/scaling/algolia-service-limits/#data-transformation-and-fetch-limits)

## See also

* [Connector overview](/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors)
* [Prepare your records for indexing](/doc/guides/sending-and-managing-data/prepare-your-data)
* [Transform your data with code](/doc/guides/sending-and-managing-data/send-and-update-your-data/how-to/transform-your-data-with-code)
