---
title: "View source for Schema Contracts - DreamFactory Wiki"
source: "http://wiki.dreamfactory.com/index.php?action=edit&title=Schema_Contracts"
canonical_url: "http://wiki.dreamfactory.com/index.php?action=edit&title=Schema_Contracts"
converted_at: "2026-11-23T03:10:44.145Z"
format: "markdown"
converted_by: "html-to-md-ai"
---
[]()
	
	
	
	# View source for Schema Contracts

	
		
		← [Schema Contracts](/Schema_Contracts)
		
		
		
		[Jump to navigation](#mw-head)
		[Jump to search](#searchInput)
		You do not have permission to edit this page, for the following reason:

The action you have requested is limited to users in the group: [Users](/index.php?title=DreamFactory_Wiki:Users&action=edit&redlink=1).---

You can view and copy the source of this page.

{{#seo:
|title=Schema Contracts - DreamFactory Documentation
|title_mode=replace
|description=Lock the public shape of a SQL-backed API, detect drift against the live database, and optionally enforce the contract at runtime
|keywords=schema contract, drift detection, breaking change, API contract, schema lock, runtime enforcement, OpenAPI
|og:title=Schema Contracts
|og:type=article
|og:site_name=DreamFactory Documentation
|og:description=Lock the public shape of a SQL-backed API, detect drift against the live database, and optionally enforce the contract at runtime
}}
'''Lock the public shape of a SQL-backed API, detect drift against the live database, and optionally enforce the contract at runtime'''

&lt;span id="schema-contracts">&lt;/span>
= Schema Contracts =

A generated API follows your database. That is the point — and also the risk: someone drops a column, renames a field, or widens a type, and every consumer of the API discovers it at runtime.

'''Schema Contracts''' let you lock the shape a SQL service exposes, then tell you when the live database drifts away from it. You can stop there and treat drift as information, or turn on runtime enforcement and have DreamFactory hold the API to the locked shape until you deliberately promote a new one.

Contracts are managed under &lt;code>/api/v2/system/schema_contract/...&lt;/code> and in the admin UI under '''Schema Contracts'''.

-----

&lt;span id="the-workflow">&lt;/span>
== The workflow ==

# '''Lock''' a table — DreamFactory captures a snapshot of its current shape as the active contract.
# '''Diff''' — drift is computed against the live database whenever you look, so it is always current rather than a cached verdict.
# '''Promote''' — when the drift is intended, promote to make the current shape the new contract.

-----

&lt;span id="locking-a-table">&lt;/span>
== Locking a table ==

&lt;syntaxhighlight lang="bash">curl -X POST \
  "https://{instance}/api/v2/system/schema_contract/{service}/tables/{table}/lock" \
  -H "X-DreamFactory-API-Key: {api_key}"&lt;/syntaxhighlight>
Each lock stores a versioned snapshot. Previous versions are retained as archives — see [[#retention|Retention]] below.

-----

&lt;span id="reading-contracts-and-drift">&lt;/span>
== Reading contracts and drift ==

{| class="wikitable"
|-
! Endpoint
! Returns
|-
| &lt;code>GET /system/schema_contract/{service}&lt;/code>
| Service-level contract status
|-
| &lt;code>GET /system/schema_contract/{service}/tables&lt;/code>
| Every table and its contract status
|-
| &lt;code>GET /system/schema_contract/{service}/tables/{table}/snapshot&lt;/code>
| The active locked contract
|-
| &lt;code>GET /system/schema_contract/{service}/tables/{table}/snapshots&lt;/code>
| Snapshot history (append &lt;code>/{version}&lt;/code> for one)
|-
| &lt;code>GET /system/schema_contract/{service}/tables/{table}/diff&lt;/code>
| Drift for one table
|-
| &lt;code>GET /system/schema_contract/{service}/diff&lt;/code>
| Drift across the whole service
|-
| &lt;code>GET /system/schema_contract/{service}/tables/{table}/openapi&lt;/code>
| OpenAPI schema generated from the contract
|-
| &lt;code>GET /system/schema_contract/{service}/openapi&lt;/code>
| OpenAPI for the whole service
|}

&lt;span id="drift-severity">&lt;/span>
=== Drift severity ===

Every difference is classified, which is what makes drift actionable rather than just a list of changes:

{| class="wikitable"
|-
! Severity
! Meaning
|-
| &lt;code>breaking&lt;/code>
| Consumers will break — a column the contract promised is gone or incompatible
|-
| &lt;code>potentially_breaking&lt;/code>
| May break consumers depending on how they use the field
|-
| &lt;code>additive&lt;/code>
| New surface; existing consumers are unaffected
|-
| &lt;code>cosmetic&lt;/code>
| No consumer-visible effect
|}

-----

&lt;span id="testing-and-promoting">&lt;/span>
== Testing and promoting ==

Validate a table against its contract without changing anything:

&lt;syntaxhighlight lang="bash">curl -X POST \
  "https://{instance}/api/v2/system/schema_contract/{service}/tables/{table}/test" \
  -H "X-DreamFactory-API-Key: {api_key}"&lt;/syntaxhighlight>
Accept the current shape for the whole service:

&lt;syntaxhighlight lang="bash">curl -X POST \
  "https://{instance}/api/v2/system/schema_contract/{service}/promote" \
  -H "X-DreamFactory-API-Key: {api_key}"&lt;/syntaxhighlight>
{{Note|title=Promotion requires a mode|A service whose &lt;code>mode&lt;/code> is &lt;code>none&lt;/code> cannot be promoted — the call fails with a message telling you to set &lt;code>mode&lt;/code> to &lt;code>auto&lt;/code> or &lt;code>strict&lt;/code> first, via &lt;code>PATCH /system/schema_contract/{service}&lt;/code>.}}

Remove a contract with &lt;code>DELETE .../tables/{table}&lt;/code> for one table, or &lt;code>DELETE .../{service}&lt;/code> for the whole service.

-----

&lt;span id="service-settings">&lt;/span>
== Service settings ==

&lt;code>PATCH /api/v2/system/schema_contract/{service}&lt;/code> configures how a service treats its contracts:

{| class="wikitable"
|-
! Setting
! Values
! Meaning
|-
| &lt;code>mode&lt;/code>
| &lt;code>none&lt;/code>, &lt;code>auto&lt;/code>, &lt;code>strict&lt;/code>
| Whether contracts apply to this service at all, and how snapshots are managed. &lt;code>none&lt;/code> also blocks promotion.
|-
| &lt;code>runtime_enforcement&lt;/code>
| &lt;code>off&lt;/code>, &lt;code>shape_response&lt;/code>, &lt;code>strict&lt;/code>
| Whether the contract is enforced on live traffic. See below.
|-
| &lt;code>archive_retention_count&lt;/code>
| integer
| How many archived snapshots to keep per table.
|-
| &lt;code>enabled&lt;/code>
| boolean
| Master switch for the service's contracts.
|}

-----

&lt;span id="runtime-enforcement">&lt;/span>
== Runtime enforcement ==

By default (&lt;code>off&lt;/code>) a contract is documentation and a drift signal — it never touches live traffic. The other two modes change that:

'''&lt;code>shape_response&lt;/code>''' — on the way out, response fields that are not in the table's active locked contract are stripped. This applies to ''every'' verb's response body, including the rows returned by &lt;code>POST&lt;/code>, &lt;code>PUT&lt;/code>, &lt;code>PATCH&lt;/code> and &lt;code>DELETE&lt;/code> acknowledgements via &lt;code>?fields=&lt;/code>, so a column added to the database stays invisible to consumers until you re-lock or promote.

'''&lt;code>strict&lt;/code>''' — everything &lt;code>shape_response&lt;/code> does, plus writes are rejected before they run when the payload references fields outside the contract, or writes to fields the contract marks read-only. Payloads are inspected in any of the shapes DreamFactory accepts: wrapped in &lt;code>resource&lt;/code>, a bare list, or a bare record.

{{Warning|title=shape_response hides new columns from consumers|This is the intended behaviour — a locked contract means the API's shape does not change under consumers' feet — but it does mean that adding a column to the database and expecting it in API responses will appear to do nothing until the contract is promoted. If a new field is "missing" from responses on a service with enforcement on, check the contract before checking the database.}}

-----

&lt;span id="command-line">&lt;/span>
== Command line ==

&lt;syntaxhighlight lang="bash"># Emit the canonical JSON schema for a service (or one table)
php artisan schema-contracts:describe {service} [--table=orders] [--pretty]

# Delete surplus archived snapshots per each service's archive_retention_count
php artisan schema-contracts:prune [--service=name] [--dry-run]&lt;/syntaxhighlight>
&lt;code>--dry-run&lt;/code> reports what would be deleted without applying it.

-----

&lt;span id="retention">&lt;/span>
== Retention ==

Every lock and promotion archives the previous snapshot. &lt;code>archive_retention_count&lt;/code> caps how many are kept per table, and &lt;code>schema-contracts:prune&lt;/code> applies that policy — run it on a schedule if you lock frequently.

-----

&lt;span id="next-steps">&lt;/span>
== Next steps ==

* '''[[Generating_Database_Backed_Api|Generating a Database-Backed API]]''': Create the service a contract locks
* '''[[Security/Role_Based_Access|Role-Based Access Control]]''': Restrict who may lock or promote

== See also ==
* [[Event_Scripts|Event Scripts]]
* [[Api_Keys|API Keys]]
* [[Interacting_With_Api|Interacting With the API]]

[[Category:Schema_Contract]]
[[Category:Drift_Detection]]
[[Category:Breaking_Change]]
[[Category:API]]
[[Category:Difficulty_Advanced]]

[[Category:API]]
Templates used on this page:

- [Template:Note](/Template:Note) ([view source](/index.php?title=Template:Note&action=edit))
- [Template:Warning](/Template:Warning) ([view source](/index.php?title=Template:Warning&action=edit))

Return to [Schema Contracts](/Schema_Contracts).

Retrieved from "[https://wiki.dreamfactory.com/Schema_Contracts](https://wiki.dreamfactory.com/Schema_Contracts)"