---
url: https://docs.tailor.tech/sdk/deploying-to-production.md
description: >-
  Deploy a change to production or any workspace whose records must be kept:
  generate the migration and its backfill, rehearse it on a copy of the records,
  get approval before destructive commands, deploy, and confirm the deploy
  landed.
---

# Deploying to Production

Follow these steps when `tailor deploy` targets a workspace whose records must survive the change: production, or a shared staging workspace. When the project deploys that workspace from CI, such as a [tag target](github-actions.md#tag-target-recommended-for-production), steps 1 to 4 still apply. The CI workflow runs step 5.2 with `--yes`, so run step 5.1 yourself first, and treat what starts a CI deploy like `tailor deploy --yes` (step 4): pushing the tag, pushing or merging to a [branch target](github-actions.md#branch-target-recommended-for-staging)'s branch, or starting the workflow with `dry-run` off. A workflow generated with `--seed` also runs `tailor seed apply --upsert` on the workspace right after each deploy (see [Seeding the workspace after deploy](github-actions.md#seeding-the-workspace-after-deploy)), so the approval covers writing those records too.

Pass `-w <workspace>` to every command below that reads or writes the workspace. Without it, commands fall back to `TAILOR_PLATFORM_WORKSPACE_ID` or the profile (see [Workspace ID Priority](cli-reference.md#workspace-id-priority)), and `tailor deploy` then to the workspace last selected for this config (see Workspace Selection under [`deploy`](cli/application.md#deploy)). A `-w` on `tailor deploy` without `--dry-run` also becomes that saved selection, so keep passing `-w` on later deploys.

## 1. Read the starting state

* Run `tailor tailordb migration status -w <workspace>` (Beta) for the deployed checkpoint and the pending migrations.
* Record what the change touches with read-only queries (`tailor query -w <workspace> --engine sql` with `SELECT`): the row count of each table it changes, and the highest number each serial field it changes holds. Compare serial values by their number: as strings, `CUST_9` sorts above `CUST_10`.

Done when you know the workspace, its checkpoint, and the records each table change touches.

## 2. Generate the migration and its backfill (Beta)

With `migration` configured on a namespace, a table change reaches the workspace only through a migration: run `tailor tailordb migration generate` after the last table edit (see [Migration Workflow](services/tailordb/migration.md#migration-workflow)). A namespace without `migration` has no backfill step: [add migrations](services/tailordb/migration.md#adding-migrations-to-an-existing-project) and deploy them before you change a table that has records.

In `migrate.ts`, make the existing records satisfy the new schema: a value for each new required field, and no duplicates under a new unique constraint. When the script writes a serial field, set the field's `start` above the highest number the field holds once the script has run, and make the script throw before it writes a number at or above `start` (see [Generated Files](services/tailordb/migration.md#generated-files)). A deploy that already shipped a lower `start` is fixed by a migration that raises it.

Test each script locally (see [Testing Migrations Locally](services/tailordb/migration-testing.md#testing-migrations-locally)), then run `tailor tailordb migration validate -w <workspace> --strict`.

Done when `migration validate --strict` passes and the tests of each `migrate.ts` pass.

## 3. Rehearse on a copy of the records (Beta)

When a pending migration has a `migrate.ts`, or adds a required or unique constraint to a table with records, run `tailor tailordb migration test -w <workspace> --data clone`. It copies the workspace's records into a temporary workspace, runs the pending migrations there, and deletes it; the source workspace is not modified (see [Clone mode](services/tailordb/migration-testing.md#clone-mode)). Pass `--assert <file>` to check the migrated records. `--keep --keep-ttl 24h` keeps the copy to query yourself. Loading the copied records triggers no executors, but a kept copy runs them afterwards: schedules fire on time, and writes to the copy fire event executors. So prefer `--assert`, and delete a kept copy as soon as you are done.

Create test records only on such a copy.

Done when the rehearsal passes and the migrated records hold the values you expect.

## 4. Get approval for destructive commands

A request to deploy a change covers the steps on this page: read-only commands, the rehearsal, and `tailor deploy`. Run the commands below on the workspace only after its owner approves that command, including when an error's suggestion names it:

* Delete records, tables, or the workspace: `tailor deploy --yes`, which accepts everything a deploy asks to confirm (see the Confirmation list under [`deploy`](cli/application.md#deploy)), `tailor deploy --no-schema-check`, `tailor tailordb migration sync`, `tailor tailordb migration resolve`, `tailor tailordb truncate`, `tailor seed apply --truncate`, `tailor remove`, `tailor workspace delete`, and `tailor workspace prune`.
* Accept data loss or rewrite the migration history (Beta): `tailor tailordb migration script <N> --no-script`, `tailor tailordb migration generate --init`, and `tailor tailordb migration rebaseline`.
* Write records or run the app's code on them: `tailor query` that inserts, updates, or deletes, GraphQL mutations, `tailor seed apply`, `tailor executor trigger`, `tailor workflow start`, `tailor function run`, `tailor api` methods that change something, and any other command that writes to the workspace.
* Deploy a baseline over the workspace: `tailor tailordb migration test --target-workspace-id <workspace> --yes` (Beta).

## 5. Deploy

1. Run `tailor deploy -w <workspace> --dry-run --json`. Check that `changes` lists only what you meant to change. Secret Manager secrets and Auth connections appear as `update` whenever this checkout did not make the last deploy, and an update with `forcedBySdkVersion: true` only applies a resource again because the last deploy used another SDK version. `--dry-run` asks nothing: it prints to stderr each confirmation the deploy would ask for; bring each to the owner (step 4). The JSON holds only some of them in `warnings`, `conflicts`, and `takeovers`: removing a table from the config, for example, shows up only in `changes`, as `action: "delete"` (counted in `summary.delete`).
2. Run `tailor deploy -w <workspace>`. With `--json` or without a terminal, a deploy that needs a confirmation stops instead of applying. Pending migrations run before the new resolvers, executors, and workflows are deployed. With the default [maintenance mode](services/tailordb/migration-operations.md#maintenance-mode), the tables of each namespace with pending migrations refuse GraphQL writes until the migrations finish.
3. When it fails, read the error's `suggestion`. When a migration failed, follow [Failure Recovery](services/tailordb/migration-operations.md#failure-recovery).

## 6. Confirm the deploy landed

* `tailor deploy -w <workspace> --dry-run --json`: once the workspace runs the local code, `changes` holds nothing but the secrets and Auth connections step 5.1 mentions, so `summary.create`, `delete`, and `replace` are `0`, and so is `update` when the app has neither.
* `tailor tailordb migration status -w <workspace>` (Beta): no migration is pending.
* Read the records again and compare with step 1: they hold the step 1 state plus the intended change, such as the values the script filled in.
* `tailor executor jobs <name> -w <workspace>` lists an executor's jobs. A schedule executor queues its upcoming runs ahead of time as `PENDING` jobs. `tailor executor jobs <name> <job-id> -w <workspace>` shows a job's `scheduledAt`; the job is late only once that time has passed.

Done when the dry-run plans no other change, no migration is pending, and the records match step 1 plus the intended change.

## Schema check failures (Beta)

| Error                           | Cause                                              | Next step                                                                                                                                                                                                 |
| ------------------------------- | -------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `MIGRATION_SCHEMA_CHECK_FAILED` | The local tables differ from the latest migration. | Run `tailor tailordb migration generate`. When the latest migration is deployed to no workspace, you can instead delete its directory, generate it again, and carry your `migrate.ts` edits over.         |
| `MIGRATION_REMOTE_DRIFT`        | The deployed tables differ from their checkpoint.  | See [Remote schema drift detected](services/tailordb/migration-operations.md#remote-schema-drift-detected). A fix that rewrites the deployed tables, such as `migration sync`, needs approval (step 4). |

`--no-schema-check` skips both checks. It is not recommended for production (see [Remote schema drift detected](services/tailordb/migration-operations.md#remote-schema-drift-detected)), and it needs approval (step 4).
