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

# Database (booking lookup)

> Point equate at your PostgreSQL, MySQL / MariaDB or SQL Server database and bookings are looked up live at match time — always current, no feeds to maintain.

The **database connector** reads bookings from your own database at the moment an
invoice is matched. There's no export, no sync schedule and no stale data — the match
always runs against what's in your system right now. It's the recommended way to connect
[booking data](https://equatetravel.ai/docs/guides/booking-data.md) for production.

It works with three database engines:

| Database type | Covers | Default port | Per-engine notes |
| - | - | - | - |
| **PostgreSQL** | PostgreSQL, Supabase, Amazon RDS / Aurora, Azure and Google Cloud Postgres | `5432` | [Read-only login](#expose-a-clean-view) · [Supabase](#connecting-to-a-supabase-database) |
| **MySQL / MariaDB** | MySQL 5.7 and 8.x, MariaDB, Amazon RDS / Aurora MySQL, Azure and Google Cloud MySQL | `3306` | [MySQL and MariaDB](#mysql-and-mariadb) |
| **Microsoft SQL Server / Azure SQL** | SQL Server 2012 and later, Azure SQL Database, Azure SQL Managed Instance, Amazon RDS for SQL Server | `1433` | [SQL Server and Azure SQL](#microsoft-sql-server-and-azure-sql) |

Whatever the engine, equate behaves the same way: it connects for each lookup and
disconnects straight after, sends only `SELECT` statements naming the exact columns you
mapped, always with a row limit and a 5-second timeout, and passes every value (the
booking reference, the supplier name you searched for) as a bound parameter, never as
part of the SQL text.

## What equate needs

**1. Connection**

The **database type**, then host, port (leave it blank for the engine's default),
database name, encryption, and credentials for a database user. Credentials are
encrypted at rest and never shown again once saved.

**2. Where the bookings live**

The schema and table (or view) to read from.

**3. Which columns matter**

The column holding the **booking reference** (required), and optionally the
**supplier** and **total** columns for stronger matching.

**4. Test with a real lookup**

The [booking-data wizard](https://equatetravel.ai/docs/guides/booking-data.md) runs a live lookup before saving —
a wrong column or connection fails here, not silently at match time.

A **fuzzy match** toggle tolerates near-miss references (extra prefixes, dropped leading
zeros and the like) — useful for suppliers who restyle your reference on their invoices,
at the cost of a little more [review](https://equatetravel.ai/docs/guides/reviewing-exceptions.md).

> [!TIP]
>
> Not the right person for connection strings? Use **Save & send invite** in the
> wizard to hand the half-finished connector to your DBA or engineer, or invite them
> with the **Technical** role — integrations access without financial pages. See
> [members & roles](https://equatetravel.ai/docs/guides/members-and-roles.md).

## Expose a clean view

Rather than pointing equate at raw application tables, create a dedicated **read-only
view** that presents one row per booking with friendly columns:

```sql theme={null}
CREATE VIEW bookings_for_equate AS
SELECT
  b.public_ref      AS "reference",
  s.name            AS "supplier",
  b.total_amount    AS "totalCost",
  b.currency        AS "invoiceCurrency",
  b.lead_passenger  AS "leadName",
  b.departs_on      AS "cruiseEmbarkation"
FROM bookings b
JOIN suppliers s ON s.id = b.supplier_id
WHERE b.status NOT IN ('CANCELLED', 'DRAFT');
```

Column names line up with equate's booking schema (the same fields it extracts from
each invoice), though you don't have to rename anything — you map each column to a
field in the **Map** step. A view keeps the contract stable while your schema evolves,
lets you exclude rows that should never match (cancellations, drafts), and pairs
naturally with a locked-down user. On PostgreSQL:

```sql theme={null}
CREATE USER equate_reader WITH PASSWORD '…';
GRANT CONNECT ON DATABASE travel TO equate_reader;
GRANT USAGE ON SCHEMA public TO equate_reader;
GRANT SELECT ON bookings_for_equate TO equate_reader;
```

The example above is PostgreSQL. The same view works on the other engines with their own
quoting (`` `reference` `` on MySQL, `[reference]` on SQL Server); their read-only logins
are under [MySQL and MariaDB](#mysql-and-mariadb) and
[SQL Server and Azure SQL](#microsoft-sql-server-and-azure-sql).

equate only ever **reads** — a `SELECT`-only user on a single view is all it needs.

## Index the reference column

Lookups are by reference, so make sure the underlying column is indexed — at volume,
every invoice triggers at least one lookup:

```sql theme={null}
-- PostgreSQL
CREATE INDEX CONCURRENTLY idx_bookings_public_ref ON bookings (public_ref);

-- MySQL / MariaDB
CREATE INDEX idx_bookings_public_ref ON bookings (public_ref);

-- SQL Server / Azure SQL (ONLINE needs Enterprise edition or Azure SQL)
CREATE INDEX idx_bookings_public_ref ON dbo.bookings (public_ref) WITH (ONLINE = ON);
```

If you enable **fuzzy match**, an expression index on the normalised form keeps the
fallback fast too (e.g. on `upper(public_ref)` if your references vary in case).

## Encryption

The connector's **Encryption** setting means the same thing on every engine:

| Setting | PostgreSQL | MySQL / MariaDB | SQL Server / Azure SQL |
| - | - | - | - |
| **Require** (recommended) | TLS, certificate not checked | TLS required, certificate not checked | `Encrypt` on, server certificate trusted |
| **Require + verify certificate** | TLS, certificate and host name checked | TLS, certificate and host name checked | `Encrypt` on, certificate validated |
| **None** | No TLS | No TLS | No encryption — **Azure SQL refuses this** |

Use **verify certificate** when the server presents a certificate from a public
authority (most managed services do); **Require** suits a server with a self-signed
certificate. Avoid **None** outside a private network.

Under **Additional security** you can paste a **certificate authority (PEM)** for
*verify certificate* when the server's certificate isn't from a public authority: a
private CA, or the Amazon RDS / Azure bundle. It is stored encrypted like the password.

## Security

| Control | What it does |
| - | - |
| **Read-only login** | equate only ever issues bounded `SELECT`s, and asks the engine for a read-only session where it can. A login with read access to the bookings table (or a view) is all it needs. |
| **A view or a replica** | Expose a view with only booking columns, ideally on a read replica, so equate never touches production load or columns it has no business seeing. See [use a replica](#use-a-replica-not-production). |
| **Encryption** | TLS by default (*Require*); *verify certificate* also checks the server's identity, with your own CA if needed. |
| **Encryption at rest** | The username, password and CA certificate are encrypted with AES-256-GCM before storage, under a key held outside the database, and never shown again. |
| **Query safety** | Identifiers are validated and quoted; every value is bound; one statement per connection; a connect and statement timeout on every query; nothing pooled across lookups. |
| **Address checks** | The host must resolve to a public address; private and loopback addresses are refused. |

**Rotating the password**: create the new password, enter it on the connector and
save, then retire the old one on the server. See
[connector security](https://equatetravel.ai/docs/connectors/security.md).

## MySQL and MariaDB

Pick **MySQL / MariaDB** as the database type. The default port is `3306`.

* **Schema = database.** MySQL has no separate schema level, so the table picker lists
  `database.table` for every database the login can read. You can connect to one
  database and read a view in another, as long as the login has `SELECT` on it.
* **Read-only.** Each lookup runs inside `START TRANSACTION READ ONLY`, so the server
  itself refuses any write.
* **Timeouts.** equate sets `MAX_EXECUTION_TIME` (MySQL) or `max_statement_time`
  (MariaDB) to 5 seconds for its session, and gives up on its side after 5 seconds too.
* **Case.** Supplier searches compare lower-cased values, so they match whatever your
  column's collation.

A read-only login, limited to one view (replace `%` with the addresses you allow, if
you restrict by host):

```sql theme={null}
CREATE USER 'equate_reader'@'%' IDENTIFIED BY '…' REQUIRE SSL;
GRANT SELECT ON travel.bookings_for_equate TO 'equate_reader'@'%';
```

`REQUIRE SSL` makes the server refuse an unencrypted connection from this login, which
pairs with the connector's **Require** setting. On **Amazon RDS / Aurora**, **Azure
Database for MySQL** and **Google Cloud SQL**, allow equate's connection in the
instance's security group, firewall rules or authorised networks.

> [!NOTE]
>
> A MySQL login is tied to the host it connects from. If the test says the host "is not
> allowed to connect", the login's host part doesn't cover equate's connection — create
> it for `'%'` (or the addresses we give you) rather than `localhost`.

## Microsoft SQL Server and Azure SQL

Pick **Microsoft SQL Server / Azure SQL** as the database type. The default port is
`1433`.

* **Host.** For Azure SQL Database it's `<server>.database.windows.net`; for a Managed
  Instance, its public endpoint is `<instance>.public.<dns-zone>.database.windows.net`
  on port `3342`. For an on-premises **named instance**, enter `server\INSTANCE` and
  leave the port blank — equate finds the instance's port through the SQL Server Browser
  service (UDP `1434`, which must be reachable).
* **Schema.** Tables default to the `dbo` schema; the table picker shows the others with
  their schema in front (`sales.bookings`).
* **Sign-in.** Use a **SQL login** (user name and password). Windows and Microsoft Entra
  ID sign-in aren't supported, so on-premises servers need SQL Server authentication
  ("mixed mode") enabled.
* **Read-only.** SQL Server has no read-only transaction for an ordinary login, so the
  login itself is what keeps equate read-only: give it read access and nothing more.
  equate only ever sends `SELECT` statements, each with `TOP` / `FETCH` row limits and a
  5-second timeout.

A read-only login, limited to one view, on **SQL Server** (or a Managed Instance):

```sql theme={null}
-- Once, on the server (in master)
CREATE LOGIN equate_reader WITH PASSWORD = '…', CHECK_POLICY = ON;

-- In the bookings database
CREATE USER equate_reader FOR LOGIN equate_reader;
GRANT SELECT ON OBJECT::dbo.bookings_for_equate TO equate_reader;
-- …or every table and view in the database:
-- ALTER ROLE db_datareader ADD MEMBER equate_reader;
```

On **Azure SQL Database**, a contained database user is simpler — no server login, and
it can only ever reach the one database. Run this connected to the bookings database
(not `master`):

```sql theme={null}
CREATE USER equate_reader WITH PASSWORD = '…';
GRANT SELECT ON OBJECT::dbo.bookings_for_equate TO equate_reader;
```

### Azure SQL firewall

Azure SQL refuses every connection from an address it hasn't been told to allow. If the
test says the client IP address "is not allowed to access the server":

1. In the Azure portal, open the **SQL server** (not the database) → **Security →
   Networking**.
2. Under **Public access**, choose **Selected networks**.
3. Add a **firewall rule** for each of equate's addresses —
   [ask us](mailto:support@equatetravel.ai) for the current list.
4. Save, wait a minute for the rule to apply, and test again.

The **Allow Azure services and resources to access this server** checkbox doesn't cover
equate, and a private endpoint on its own isn't reachable from outside your network. The
same applies to an on-premises server: open `1433` (and UDP `1434` for a named instance)
in its firewall to equate's addresses only.

## Use a replica, not production

If you run a **read replica** or reporting mirror, point equate at that instead of the
primary. Match-time lookups are light, but isolation is cheap insurance:

* replication lag of seconds is harmless — bookings exist long before invoices arrive;
* your primary's performance is untouchable by anything equate does;
* network allow-listing is simpler on a replica that already serves reporting tools.

## Connecting to a Supabase database

If your bookings live in **Supabase**, the connection details you pick matter — the
default "direct" connection won't work from equate, and the symptom is a connection
that times out or "can't reach host" even though the credentials are correct.

Supabase exposes three connection options (Dashboard → **Connect**, or **Project
Settings → Database**):

| Option | Host / port | Network | Use with equate |
| - | - | - | - |
| **Direct connection** | `db.<ref>.supabase.co` : `5432` | **IPv6 only** by default | ❌ Not unless you've bought the IPv4 add-on |
| **Session pooler** | `aws-0-<region>.pooler.supabase.com` : `5432` | IPv4 | ✅ **Recommended** |
| **Transaction pooler** | `aws-0-<region>.pooler.supabase.com` : `6543` | IPv4 | ⚠️ Works, but session pooler is safer |

### Why the direct connection fails

Supabase's direct connection is **IPv6-only** on the free and pro tiers — an IPv4
address is a paid add-on. equate connects from a cloud environment that reaches your
database over **IPv4**, so a direct (`db.<ref>.supabase.co:5432`) connection has nothing
to route to and the test fails. You have two ways round it:

* **Use the session pooler** (recommended) — it's IPv4-native and needs no add-on.
* **Buy the Supabase IPv4 add-on** if you specifically need the direct connection.

### Recommended: the session pooler

The session pooler behaves like an ordinary Postgres connection (one connection per
session), so it supports everything equate does — including the read-only transaction it
opens for every lookup. Map the pooler's details into the connector form like this:

| Field | Value |
| - | - |
| **Host** | `aws-0-<region>.pooler.supabase.com` |
| **Port** | `5432` (session pooler) |
| **Database** | `postgres` |
| **User** | `<your-readonly-role>.<project-ref>` — the pooler requires the `.<project-ref>` suffix |
| **SSL mode** | **Require** |

> [!NOTE]
>
> The username **must** carry the `.<project-ref>` suffix when connecting through either
> pooler (e.g. `equate_reader.abcdefghijklmnop`). A bare `equate_reader` works on the
> direct connection but is rejected by the pooler. The exact strings are shown under
> **Connect** in your Supabase dashboard — copy the host and the username from there.

The [read-only view and `equate_reader` user](#expose-a-clean-view) above apply unchanged
— create them as normal, then connect to that role through the pooler.

The transaction pooler (port `6543`) also works over IPv4, but it recycles a server
connection per transaction and doesn't keep session state, so prefer the **session
pooler** unless you have a specific reason to use it.

## Prefer an API in front of your data?

If a database connection isn't possible — managed platform, security policy, or the
bookings live behind a service — use the [booking API connector](https://equatetravel.ai/docs/connectors/booking-api.md)
instead: same live-lookup behaviour, over REST.

> [card] [Next: connect it as booking data](https://equatetravel.ai/docs/guides/booking-data.md)
>
> Add the connector under Booking Data, map the columns, and run the live test.


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