# Schema Changes

Monitors can track structural changes to your database schemas, alerting you when tables, columns, or types are added, dropped, or altered.

![monitor-notification](https://3453272330-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M93cpHl7B7NPZlDrubS%2Fuploads%2Fgit-blob-085dbc08d17a3742f7b52c00949fce54c3de0f6b%2Fmonitor-notification.png?alt=media)

## Schema Change Detection

Schema change detection captures the full column-level state of your database on each monitor run and compares it against the previous state. Any differences — new tables, dropped columns, type changes — are recorded as events.

### Configuration

Enable schema change detection with the `schemata` block:

```yaml
connection: MY_POSTGRES

schemata:
  enabled: true

objects:
  "public.*":
    metadata: true
```

| Key       | Type      | Default       | Description                                               |
| --------- | --------- | ------------- | --------------------------------------------------------- |
| `enabled` | bool      | `false`       | Enable schema change detection                            |
| `exclude` | string\[] | `["*.*_tmp"]` | Glob patterns for objects to exclude from schema tracking |

{% hint style="warning" %}
Schema change detection requires `metadata: true` on the monitored objects. Without metadata collection, Sling cannot compare schema states between runs.
{% endhint %}

### Exclude Patterns

Use `exclude` to skip objects that change frequently or are not relevant:

```yaml
schemata:
  enabled: true
  exclude:
    - "temp_schema.*"
    - "*.staging_*"
    - "*.*_backup"
```

{% hint style="info" %}
When `exclude` is not set, the default pattern `["*.*_tmp"]` excludes temporary tables automatically. Set `exclude: []` (empty array) to disable all exclusions.
{% endhint %}

### Detected Events

| Event                 | Description                                 |
| --------------------- | ------------------------------------------- |
| `schema_added`        | A new schema was detected                   |
| `schema_dropped`      | A schema was removed                        |
| `table_added`         | A new table or view was detected            |
| `table_dropped`       | A table or view was removed                 |
| `table_recreated`     | A table was dropped and re-created          |
| `column_added`        | A new column was added to an existing table |
| `column_dropped`      | A column was removed from an existing table |
| `column_type_altered` | A column's data type was changed            |

Each event includes the database name, schema name, object name, and object type. For `column_type_altered` events, both the old and new data types are recorded.

### Example

Monitor all tables in multiple schemas for structural changes:

```yaml
connection: MY_POSTGRES

schemata:
  enabled: true
  exclude:
    - "*.tmp_*"

objects:
  "public.*":
    metadata: true
  "analytics.*":
    metadata: true
  "staging.*":
    metadata: true
```

### Notifications

Enable **On Schema Change** in your monitor job's notification settings to receive alerts when schema drift is detected.
