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

# Dynamic fields

> Computed contact fields derived live from your connected database — any table, joins and aggregates included

## Overview

When your database is connected ([Supabase Connection](https://docs.minimo.it/product/data-sync/supabase.md)), every contact in Minimo can carry **dynamic fields**: values computed from your data, not copied by hand.

Two shapes:

* **Column fields** — mirror a column of your contacts table (`plan`, `last_sign_in_at`, `trial_ends_at`). Created in the mapping wizard, or by an agent with the `minimo_connection_ensure-dynamic-field` MCP tool.
* **Computed fields** — derived from **any other table**, through joins and aggregates. Examples: *number of orders*, *date of the next booked appointment*, *start of the next tournament a player is registered to* (a `MIN` over a junction table). One contact, one value — the aggregate is what turns many rows into the one value a segment or automation can use.

> [!NOTE]
>
> Minimo reads your database directly, in read-only mode. If the data lives in your connected database, it is reachable as a contact field — there is no separate "import" step to keep in sync.

## Create a computed field with Ask Mo

Describe the value in plain language and Mo plans the query against your real schema, shows you its interpretation, and creates the field.

> Create a dynamic field NEXT\_TOURNAMENT\_START (datetime): for each contact, the minimum of `tornei.inizio` across the tournaments in `tornei_iscritti` where the person is registered, with `tornei.stato = 'iscrizioni'` and a start date in the future.

Mo resolves the tables and join path from the schema analysis, asks a clarifying question when the request is ambiguous, and backfills the field for every contact right after creating it.

> [!TIP]
>
> Name the tables with `@` (e.g. `@tornei_iscritti`) to pin where Mo should look first.

## Create a computed field from an exact query (advanced)

When you (or your agent) know the schema and the exact logic, skip the planner and pass the SELECT itself. The MCP tool is `minimo_custom-field_create-from-query`. The SELECT must return exactly two columns, in order: the **contact key** and the **value**.

```sql theme={null}
SELECT p.id, MIN(t.inizio)
FROM tornei_iscritti ti
JOIN tornei t ON t.id = ti.torneo_id
JOIN profili p ON p.id IN (ti.utente_id, ti.compagno_id)
WHERE t.stato = 'iscrizioni' AND t.inizio > now()
GROUP BY p.id
```

* `contactKey` tells Minimo what the first column is: `external_id` (the synced row id, default), `email`, or `phone`.
* **Preview first** (`mode: "preview"`, the default): you get sample rows plus **coverage** (how many of your contacts would receive a value), and nothing is saved.
* **Then create** (`mode: "create"` + `key` + `displayName` + `type`): the field is persisted and backfilled for every contact in one set-based read.

Execution is strictly guarded: single statement, SELECT-only, read-only transaction with a statement timeout and a row cap; DDL/DML, data-modifying CTEs and catalog schemas are rejected. It runs against your own connected database with the same read-only access as the rest of the sync.

### Prompt or SQL?

* **Prompt (Ask Mo / `minimo_custom-field_plan-dynamic-from-prompt`)**: you describe the value, the planner finds tables and joins from the schema analysis. Best when you don't know (or don't want to write) the exact query. It asks for clarification when ambiguous. Over MCP, persist the chosen plan with `minimo_custom-field_save-planned`.
* **Query (`minimo_custom-field_create-from-query`)**: you are an agent or developer with the schema in front of you, or the logic doesn't fit the planner (an OR across two junction columns, a custom aggregate). You stay in full control of the SQL; Minimo adds the guard rails, the preview, the backfill and the refresh wiring.

Both paths land in the SAME engine: the field they create behaves identically (segments, merge fields, triggers, refresh).

## How values stay fresh

A dynamic field is recomputed, per contact, when:

* **The field is created** — an immediate backfill runs over all contacts.
* **Your data changes** — when a computed field is created, Minimo automatically installs change triggers on every table the field reads (the source table and each joined table), so a row change re-resolves the affected contact's value.
* **An automation checks a goal** — goal evaluation refreshes the fields it depends on just in time.

> [!WARNING]
>
> A value that changes with the passage of time alone (like "the NEXT tournament", which changes when a tournament starts even if no row changed) is only recomputed on the events above, not continuously. Anchor automations to data changes (a new registration, a status change) rather than to the field drifting over time.

## Use them everywhere

Dynamic fields behave like any custom field: segment on them, reference them in templates with merge fields, and trigger automations when they change (the **Field updated** trigger).


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