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

# type-contract

> Gate breaking changes in the generated TypeScript/Zod type contract between two schema sources.

Use `type-contract` to inspect breaking changes to the generated type surface.

`type-contract` diffs the type shapes of two schema sources (before vs after). It does not connect to a database.

`supaschema sync` runs type-safety gates through `workflow.type_safety`. The deploy gate compares the configured before and after source models, not the live target catalog. The default policy reports diagnostics without blocking; `deploy_blocking` makes those findings refuse target mutation. The standalone `type-contract --enforce` flag provides the same fail-closed behavior without running `sync`.

`type-contract --enforce` exits `2` when it finds a breaking change. Without `--enforce`, the command reports the findings and exits `0`.

## Use this when

* A migration must not break downstream TypeScript/Zod consumers.
* CI should gate breaking type-contract changes on a pull request.
* You want to understand the type-safety diagnostics that `sync` can block before apply.

## Run it

```bash theme={null}
npx supaschema type-contract --from git:HEAD --to dir:database/schemas
npx supaschema type-contract --from git:HEAD --enforce
```

With no flags, `--from` defaults to `git:HEAD` and `--to` to the declarative tree.

## Flags

<ParamField path="--from" type="source">
  Previous schema source. Defaults to `git:HEAD`.
</ParamField>

<ParamField path="--to" type="source">
  New schema source. Defaults to the declarative tree.
</ParamField>

<ParamField path="--reporter" type="text | json | github | sarif">
  Output format. An unknown value exits `2` with an error.
</ParamField>

<ParamField path="--enforce" type="boolean">
  Fail (exit `2`) on a breaking change in the standalone command. The `sync`
  deploy-safety gate is configured separately by `workflow.type_safety`.
</ParamField>

## What it flags as breaking

* a removed table;
* a removed column;
* a changed column type;
* a removed enum, or a removed enum value.

## Exit codes

| Code | Meaning                                                 |
| ---- | ------------------------------------------------------- |
| 0    | No breaking change, or report-only without `--enforce`. |
| 2    | Breaking change while `--enforce` is enabled.           |

## Related

<CardGroup cols={2}>
  <Card title="ORM-free apps" icon="database" href="/docs/concepts/orm-free-applications">
    See how generated types and validators replace ORM schema ownership.
  </Card>

  <Card title="Sync command" icon="refresh-cw" href="/docs/commands/sync">
    Run deploy-blocking type-safety and RLS-safety gates before apply.
  </Card>
</CardGroup>
