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

# Database

> Infra extensions for schema, migrations, and naming in AI Parlance

# Database

**Infra** extensions on the `entity` model. Base: [crm-reference.aip](https://github.com/eudameron/aiparlance/blob/main/examples/crm-reference.aip). Spec: [Specification](https://docs.aiparlance.org/en/specification.md).

***

## Supported databases (v0.1)

| Database | Language (`app`) | Transpiler v0.1 |
| - | - | - |
| PostgreSQL | `postgres` | Preview (`aip emit sql` — DDL, indexes, seeds) |
| MySQL | `mysql` | Preview (`aip emit mysql`) |
| SQLite, MariaDB, MongoDB, … | Roadmap | — |

PostgreSQL: `aip emit sql`. MySQL: declare `database mysql` and run `aip emit mysql` (see [`examples/mysql-minimal.aip`](https://github.com/eudameron/aiparlance/blob/main/examples/mysql-minimal.aip)). Matrix: [Specification § Transpiler matrix](https://docs.aiparlance.org/en/specification.md#transpiler-matrix).

```aip theme={null}
app CRM @0.1 {
  database postgres
}
```

***

## Migrations

Generated from `entity` with implicit fields in DDL.

```sql theme={null}
CREATE TABLE users (
  id UUID PRIMARY KEY,
  name TEXT NOT NULL,
  email TEXT UNIQUE NOT NULL,
  created_at TIMESTAMPTZ NOT NULL,
  updated_at TIMESTAMPTZ NOT NULL
);
```

***

## `seed`

```aip theme={null}
seed User {
  name: "Administrator"
  email: "admin@example.com"
  role: admin
}
```

***

## Indexes and constraints

```aip theme={null}
index Lead {
  status
  created_at
}
```

| Modifier | SQL |
| - | - |
| `required` | `NOT NULL` |
| `unique` | `UNIQUE` |
| `belongs_to` | `REFERENCES …` |

***

## Naming

| Entity | Table | FK |
| - | - | - |
| `User` | `users` | `user_id` |
| `SalesOrder` | `sales_orders` | `sales_order_id` |

Rules: lowercase, `snake_case`, plural table names.

***

## UUID and audit

* `id`: `uuid` by default
* `timestamps`: `created_at`, `updated_at`
* `soft_delete`: nullable `deleted_at`

***

## Semantic types → PostgreSQL

| AI Parlance | PostgreSQL |
| - | - |
| `email` | `TEXT` + app validation |
| `json` | `JSONB` |
| `datetime` | `TIMESTAMPTZ` |
| `phone` | `TEXT` + normalization |

***

## Flow

```txt theme={null}
entity / index / seed (.aip)
↓
AST
↓
Database Generator
↓
DDL / migrations / ORM
```


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