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

# introspect

> Read a live database schema and produce a schema file.

# `seedling introspect`

Reads a live database schema and writes it as a structured YAML or JSON file.

## Usage

```bash theme={null}
seedling introspect --db <DSN> [options]
```

## Flags

| Flag       | Description                      | Default  |
| ---------- | -------------------------------- | -------- |
| `--db`     | Database connection string       | Required |
| `--output` | Output file path                 | stdout   |
| `--format` | Output format (`yaml` or `json`) | `yaml`   |

## Examples

### Postgres

```bash theme={null}
seedling introspect \
  --db postgres://user:pass@localhost:5432/mydb \
  --output schema.yaml
```

### MySQL

```bash theme={null}
seedling introspect \
  --db mysql://user:pass@localhost:3306/mydb \
  --output schema.yaml
```

### JSON Output

```bash theme={null}
seedling introspect \
  --db postgres://localhost:5432/mydb \
  --format json --output schema.json
```

## Output Structure

```yaml theme={null}
tables:
  - name: users
    columns:
      - name: id
        type: serial
        nullable: false
        primary_key: true
      - name: email
        type: varchar
        nullable: false
        unique: true
      - name: role
        type: varchar
        nullable: true
    foreign_keys: []
  - name: orders
    columns:
      - name: id
        type: serial
        primary_key: true
      - name: user_id
        type: integer
        nullable: false
    foreign_keys:
      - column: user_id
        ref_table: users
        ref_column: id
```

## Auto-detection

The introspector auto-detects the database engine from the DSN:

* `postgres://` → Postgres (pgx driver)
* `mysql://` → MySQL/MariaDB (go-sql-driver)
