Track Three Versions Instead of One Commit Hash
A green apply can still be the start of an outage. A version is replaced, an additive migration runs, and a column is dropped two releases later. The previous version still exists and still deploys cleanly, but it writes a column that no longer exists, so the rollback turns a data problem into a request failure.
Three identities move on different clocks. The artifact is the bytes, the runtime contract is how those bytes are wired, and the data position is what the persisted state expects. A commit hash names the first only at build time, and none of them at runtime.
A commit is an input, not an identity. The same commit produces two artifacts when the lockfile, bundler or a build-time constant changes, and one artifact can serve two contracts when staging and production bind different resources. Neither difference appears in the hash.
Reproducibility is not identity. Two builds can both be reproducible and still differ from each other when the toolchain differs. Pinning the runtime, the package manager and the bundler is what makes the digest mean "the same bytes", rather than "the same recipe".
The contract is the part reviewers forget to version. Bindings, compatibility date and flags, and Durable Object lifecycle entries are all snapshotted with the version. A flag change with identical bytes is still a different runtime, and a binding change with identical bytes is a different set of capabilities.
The data position advances outside Git. The migration ledger records what ran, a Durable Object records its own storage schema, and a queue holds messages written by an older producer. No clone of the repository contains any of it.
The ledger answers a question the plan cannot. The d1_migrations table records which files ran, including a file applied by a hotfix job that no pipeline remembers. The plan shows a database resource, not the schema inside it, which is why the ledger tail belongs in the release record.
| Identity | Question it answers | Recorded from | Moves when |
|---|---|---|---|
| Artifact | Which bytes are shipping? | module content_sha256 and the assets manifest | a module, asset or entry point changes |
| Runtime contract | How are those bytes wired? | bindings, flags, lifecycle entries | a target, flag or class declaration changes |
| Data position | What does the state expect? | ledger tail, object schema version, envelope version | a migration, storage change or message shape ships |
| Commit | What source produced this? | the Git SHA | source changes, and nothing else |
A release record is four fields, not one. Name the artifact digest, the contract fingerprint, the data position and the restore point. The restore point is the only field that is useless until the day it is essential.
Put the toolchain versions in the header. Terraform 1.17.1 and cloudflare/cloudflare 5.28.1 belong in the record for the same reason the digest does: a replay under a different provider is a different release.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
SRC["Commit, lockfile,
pinned bundler"] --> ART["Artifact
module content_sha256
and assets manifest"]
SRC --> CFG["Runtime contract
bindings, compatibility flags
and class lifecycle"]
SRC --> DAT["Data position
ledger tail, storage schema
and envelope version"]
ART --> REC["Release record
one line per environment"]
CFG --> REC
DAT --> REC
REC --> GATE{"All four values recorded
for this environment?"}
GATE -->|"yes"| PROMOTE["Freeze the artifact
and promote it"]
GATE -->|"no"| BLOCK["Block the release
a commit cannot answer for it"]
COMMIT["Commit hash alone"] -.->|"claims to identify"| ART
COMMIT -.->|"says nothing about"| DAT
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class SRC,REC,GATE primary;
class ART,CFG secondary;
class DAT,PROMOTE ok;
class BLOCK,COMMIT danger;
Read the gate as an equality check. All four values must describe the same release; a value borrowed from the previous release passes a checklist and fails an audit.
The dangerous mismatch is a contract ahead of the artifact. A binding that names a class the uploaded code does not export produces no plan diff at all. The upload succeeds, and the first request that resolves the binding fails.
Record the values from the saved plan, before the apply. Module hashes are computed during planning, and the bytes are read during create, so the record must be written between the two. A record typed after the deploy is a reconstruction, not evidence.
Provenance is three links, not one signature. The build records the source and toolchain, the plan records the digest and the contract, and the deployment records the version and the traffic split. A break in any link turns the record into a plausible story.
Name the fingerprint, do not store the secrets. A binding fingerprint hashes names, types and target identifiers in sorted order, and represents a secret by name only. That keeps the record auditable without turning it into a credential store.
The fingerprint comes from planned values, not from the source tree. A saved plan serialized as JSON contains the binding array and the compatibility flags as Terraform intends to send them. Hashing that projection is more honest than hashing the configuration, because it includes values resolved from variables and resource attributes.
A fingerprint that changes without a source change is the signal. The usual causes are a recreated database with a new identifier, a renamed queue, or a variable default that moved. Each one is a contract change with no code diff, and each one should force a plan review rather than a silent promotion.
A missing field blocks the promotion. The gate is deliberately boring: if the record cannot name all four values for this environment, the release is not ready. Warnings are for style; this one is for state.
The figure below places the three identities beside the release record and marks what the commit cannot supply.
The figure is a lock, not a dashboard. Each column can move alone, and the record is the only place where the three movements are compared.
Commit-only pipelines fail in the third column. Nothing in a build log reads the ledger tail or the message version, so a release can be perfectly reproducible and still incompatible with its own data.
The record also has a lifetime. Keep one line per release in version control or object storage, never in a chat thread, and compare the new line with the previous one during review. A record overwritten in place cannot answer which release advanced the schema head.
Use Expand-Contract Changes for SQL and Queue Messages
Expand-contract is a schedule, not a style preference. Expand adds a shape both versions can use, migrate fills it, switch moves the readers, and contract removes the old shape. Each phase is a separate deploy with its own evidence, and the schedule is what keeps a rollback available.
Expand must make the old code correct, not merely tolerant. A nullable column with a safe default lets the previous version keep inserting rows while the new version writes the extra value. If the old insert fails after the expand, the change was not additive.
A migration file is a unit of failure, not a transaction. Files apply in order and the ledger records the ones that finished, so a statement that fails can leave earlier statements in place with no ledger row. Guard the statements, keep each file small, and read the ledger before retrying rather than after the second failure.
Dual-write closes the gap between deploy and backfill. Rows written after the new version starts but before the backfill runs would otherwise miss the new shape. Writing both shapes for one release makes the backfill predicate stable and re-runnable.
Backfill is a job, not a migration file. Batch it by primary-key range, touch only rows where the new column is still null, and record the cursor so a restart resumes. One large update inside a migration file is how a schema change becomes an outage.
Verify the backfill with two numbers and one comparison. Count the rows that still have a null in the new column, and count the rows the batch job claims to have covered. Compare both with the pre-backfill count; a mismatch means the predicate or the cursor is wrong, and the contract is still weeks away.
Deferring foreign keys is a tool, not a license. A pragma at the top of a file can let a table rebuild proceed while constraints are checked at commit, but it does not make a destructive change reversible. Use it to get through the rebuild, then verify the relationships with a query rather than assuming the constraint proved them.
The read switch is its own release. Code after the switch prefers the new shape and keeps writing both. That separation is what lets you observe the new path with the old path still correct behind it.
The switch is where you compare answers, not only errors. Dual-read the old and new shapes for a sample of keys and log the differences before you trust the new path. A switch that watches only error rates cannot see a wrong value.
Contract waits for a drain horizon, and the horizon differs by store. For D1 it is the end of the rollout, for a queue it is retention plus the retry ceiling set by max_retries, and for a Durable Object it is the code-update delay. Contracting early is the most common way to make a rollback impossible.
| Change | Expand | Migrate | Contract only after |
|---|---|---|---|
| Add a nullable column | old insert stays valid | backfill by key range | the read switch has served a full rollout |
| Rename a column | add the new column and dual-write | backfill, then switch reads | no version reads the old name |
| Add an optional message field | consumer tolerates its absence | producer starts writing it | the consumer accepts both versions |
| Remove a message field | producer stops writing it | wait out retention and retries | no in-flight message carries it |
| Reinterpret a value | add a field or a version | dual-write and compare | the old meaning is no longer read |
A queue message is a schema with a delivery delay. The producer that wrote a message may be two releases behind the consumer that reads it, because the queue holds the old shape until retention expires.
Version the envelope, not the field names. Put a schema version beside the business key and let the consumer accept the current and previous versions. Unknown versions belong in the dead-letter queue with the original body and a reason, rather than in an infinite retry loop.
The envelope needs a business key so the expand phase can be idempotent. Delivery is at least once, and a retried batch may repeat work that already committed halfway. An upsert on the key makes the duplicate harmless.
Acknowledge per message when the batch can partially succeed. One failed message otherwise replays the whole batch, including the messages that already wrote rows. Per-message acknowledgement narrows the repeat to the message that actually failed.
A dead letter is an inbox, not a graveyard. Park the original body, the envelope version and the failure reason, then replay after the handler is fixed with the same key-based upsert. The dead-letter queue has its own retention, and a replay that starts after that window is a data loss you chose.
Deploy order follows the direction of the change. Additive optional fields can ship producer-first, required semantics need the tolerant consumer first, and removals always drain the producer before the consumer forgets the field.
| Message change | Deploy first | Minimum wait | Then |
|---|---|---|---|
| Optional field added | either side, consumer tolerant | none | producer begins writing |
| Required field added | consumer that accepts both | consumer at full traffic | producer writes it |
| Field removed | producer stops writing | retention plus retry ceiling | consumer stops reading |
| Field renamed | consumer accepts both names | one full release | retire the old name |
| Value meaning changed | new field or new version | one full rollout | stop reading the old field |
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
subgraph SQL["SQL and schema track"]
EXP["Expand
nullable column or optional field
old code still valid"] --> N1["Deploy N
write both shapes"]
N1 --> BF["Backfill by key range
idempotent and resumable"]
BF --> VER{"Row counts and nulls
match the expectation?"}
VER -->|"no"| HALT["Stop before any contract
fix forward in a new file"]
VER -->|"yes"| N2["Deploy N+1
read the new shape, write both"]
N2 --> DRAIN{"Drain horizon elapsed?
rollout complete, retention
and retry ceiling passed"}
DRAIN -->|"no"| HOLD["Keep both shapes
do not contract yet"]
HOLD --> DRAIN
DRAIN -->|"yes"| N3["Deploy N+2
stop old writes, drop old column"]
N3 --> IRREV["Contract is irreversible
old code has no column to write"]
end
subgraph MSG["Queue message track"]
QP["Producer writes envelope v2"] --> QB["Queue holds v1 and v2"]
QB --> QC["Consumer accepts v1 and v2"]
QC --> UQ{"Envelope version
understood?"}
UQ -->|"no"| DLQ["Dead-letter the original body
with a reason, do not retry blindly"]
UQ -->|"yes"| OK["Upsert on the business key
acknowledge per message"]
end
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class EXP,VER primary;
class N1,N2,QP,QB secondary;
class BF,QC,OK ok;
class N3,IRREV,HALT danger;
class DRAIN,HOLD,UQ,DLQ warn;
The failure branch is the part of the diagram that protects the data. A verification that does not match stops the release before the contract, when a fix is still a normal deploy.
Contract is the step that converts a rollback into a forward fix. After the old column is gone, the previous version has nothing to write to, and no amount of traffic shifting changes that.
The contract should be the smallest release you ship. One dropped column, one removed field, and no feature work. If it fails, the diff is small enough to explain; if it succeeds, there is nothing else that has to be rolled back with it.
Preserve Durable Object and Workflow Compatibility
A Durable Object has three identities, and Terraform stores one of them. The class name is a string in a binding, the lifecycle history is a declaration, and the storage schema lives inside every instance. A plan can compare the first two and never sees the third.
The class name is a string, so the provider checks a string. A binding that names the expected class is valid configuration even when the uploaded code exports a different one. The mismatch is a runtime error, not a validation error.
The lifecycle declaration is reconciled after upload. The declarative form, exports, compares code exports, configuration and provisioned namespaces, then reports created, renamed and deleted classes. The legacy migrations form instead carries a tag, and a Worker may use one form or the other. The reconciliation output is apply-time evidence, not a plan-time promise.
Read the notices, not just the action lines. An expected notice during a rename says the old class is still exported in code, which is the safe pattern. A stale tombstone means cleanup, and an unexpected rename means the release changed data topology that nobody reviewed.
The tag form is optimistic concurrency, and the export form is reconciliation. A tag catches a migration applied from a stale branch because the current tag must match the expected one. The export form has no tag, so it relies on the reconciliation output instead.
Storage is a database with a code-update window. An active object may keep its current code for up to 300 seconds by default, and the window can be extended to a day or forced to immediate. A gradual deployment assigns each object to a version rather than splitting its requests, so two class versions coexist across the namespace while each object runs one. Every storage change must therefore be an expand-contract change.
Storage migrations belong inside the object, and they must be quick. Check a schema version row at construction and run only the additive statements for that version. Long work belongs in an alarm, because holding the constructor blocks every event the object would otherwise handle.
A rename is three deploys and not a rollback window. Alias the new class under the old name, apply the rename while the alias is live, then remove the alias. A single deploy leaves a gap where the namespace points at a name the code has not exported yet.
The alias is code, not configuration. The first deploy re-exports the new class under the old name and leaves the lifecycle entries untouched, which is why it moves no namespace. Only the second deploy moves the pointer.
A delete tombstone fails closed, and that is the good outcome. The deploy refuses while the class is still exported or another Worker still binds it. That rejection is the last safety check before every object in the namespace is destroyed.
| Operation | Declared as | Data effect | Rollback across it |
|---|---|---|---|
| Create a class | live entry with SQLite storage | new empty namespace | allowed |
| Rename a class | renamed tombstone plus live target | storage follows the new name | blocked |
| Delete a class | deleted tombstone | namespace and every object destroyed | blocked, no trash |
| Transfer a class | transferred and expecting-transfer | namespace moves to another Worker | staged, not a rollback |
| Change the storage schema | code plus a schema table | rows rewritten in place | only while old code is compatible |
Rollback and lifecycle changes do not compose. A deployment rollback cannot cross a class rename or tombstone, and a gradual deployment cannot carry a lifecycle change at all. The version-only upload path does not apply lifecycle changes either, so a rename always requires the deploy path.
A transfer is four deploys, not a rename. The target declares that it expects the transfer, the source commits it, and only then does the target bind the class. Before the commit the move can be cancelled; after it, the only undo is another transfer.
A Workflow's step names are its storage keys. A completed step is cached by name, so renaming or reordering a step makes the engine miss the cache and run the work again. For a step that charges a card, that is a duplicate charge created by a refactor.
Top-level Workflow state must come from step returns. The engine can hibernate between steps and lose memory, so state assembled in local variables disappears. A code change that assumes otherwise fails on resume rather than on deploy.
A Workflow definition change is a data migration for every in-flight instance. Add steps at the end, branch on a version captured in the payload, and keep the old branch for at least the instance retention window. Drain before deleting a definition that still has live instances.
Deleting a definition removes the handle, not the instance state. Instance history has its own retention, and the name is a label rather than the identity. Inspect or export what you need before that window closes, because a deleted instance does not come back with the definition.
The figure below separates what Terraform declares, what the deploy reconciles, and what only the instance storage knows.
Terraform sees the declaration, Cloudflare reconciles it, and neither sees the rows. That is the boundary the figure draws, and it is why the deploy must assert what the plan cannot.
Write the three assumptions into the release record. The class is exported by the uploaded code, the storage backend is the one the namespace already uses, and the old code may still serve for the configured delay. Each one is checkable, and none of them is checked by the diff.
Promote the Bundle with Its Exact Bindings and Flags
Promotion repeats a decision; it does not make a new one. The artifact was chosen at build, the contract was chosen at plan, and the promotion only moves traffic to the version that already carries both. A rebuild during that window silently makes a third decision.
The planned digest is the review artifact, and the file on disk is the risk. Module hashes are computed at plan and the bytes behind content_file are read at create, so a file that changes in between is uploaded under a digest nobody approved. Freeze the output directory read-only and verify its checksums immediately before the apply.
A saved plan is necessary and not sufficient. Applying the plan file prevents a re-plan, but it does not stop the provider from reading a file that was rewritten on disk. The missing control is filesystem immutability, not another flag.
Versions are append-only, which makes a bad upload cheap to abandon. A replaced version resource creates a new version and leaves the old one in history. Point the deployment at the reviewed version and keep the bad one as evidence; deleting it is not required to recover.
The promotion sequence is short enough to rehearse. Freeze the artifact, plan, compare the planned digest, apply, compare again, then move traffic. Each step writes the same identifiers into the record, and no step is allowed to rebuild.
Bindings are part of the version, so the same artifact in another environment is a different version. That is expected: the artifact identity stays constant while the contract identity changes. The release record must show both, or a promotion looks like a rebuild.
A failed apply can still leave a version behind. If the provider created the version and then failed on the deployment, state may not record it. List the versions, match the digest, and import or remove deliberately; rerunning the build hides the orphan.
Flags are executable decisions. A compatibility flag can change runtime behavior with no source change, so it belongs in the tested artifact's record and in the review. Promoting a bundle with an untested flag is a code change without a diff.
The candidate check is about the contract, not only the status code. A version at one percent exercises the real binding set, the real flags and the real update mode. A preview URL that resolves production bindings is a production client with a different hostname, not a rehearsal.
Traffic and Durable Object update policy live on the deployment. Percentages are in the deployment resource, and the code-update strategy is a separate field in the deployment API. Because that field is write-only, a later deploy that omits it silently returns to the 300-second default.
The first Durable Object apply is two-phase, and that is a graph fact. A binding cannot resolve to a namespace that the same apply has not created yet. Deploy the class with its lifecycle entry, then add the binding, then let the application depend on it.
Promotion is per environment, and the record is per environment. The same artifact digest with a different contract fingerprint is the normal cross-environment case. Identical values in both places usually mean one of them was copied or rebuilt rather than promoted.
Remove the second deployer's credentials for the window. A deploy, a version upload or a secret rotation can create a version and move traffic outside the plan. The build job should be able to produce bytes and nothing else.
| Gate | Evidence | If it fails |
|---|---|---|
| Artifact | post-apply module digest equals the planned digest | stop; do not move traffic |
| Contract | binding fingerprint and flags equal the tested record | stop; the version is not the tested one |
| Schema | ledger tail equals the expected head | stop; migrate or roll back first |
| Classes | reconciliation shows only the intended changes | stop; a rename or tombstone is a data event |
| Candidate | probes pass on the candidate version | keep the previous version at full traffic |
| Deployment | percentages and update mode recorded | fix the deployment, not the artifact |
The figure below contrasts a frozen promotion with a rebuild, and adds the bypass that ends a canary.
The digest comparison is the moment the release becomes provable. Compare the post-apply module hashes with the planned values before any traffic moves; a mismatch is a stop, not a warning.
A failed deployment is cheaper than a failed apply. If the version exists at zero percent, fix the deployment and keep the artifact. Rebuilding to fix a traffic error discards the one property the release was designed to preserve.
A deployment rollback is a pointer move, and it is the only free move in the release. It restores traffic, not the contract or the data, so it is safe only while the schema and the lifecycle still accept the old version. That condition is worth checking before the incident, not during it.
Rehearse a Forward Fix and a Data Restore Decision
Recovery starts by classifying the change, not the symptom. An error after a deploy can come from code, contract or data, and each one has a different safe move. The classification is a property of what the release changed, not of the message in the log.
A rollback is a triple, and partial triples are the bug. Old artifact, old contract and old schema must be restorable together. Restoring one and not the others creates a mismatch that looks like a different failure and sends the next engineer in the wrong direction.
| Change | Code rollback | Data rollback | Safe recovery |
|---|---|---|---|
| Additive column or optional field | safe | not needed | rollback or forward fix |
| Read switch | safe | not needed | rollback |
| Contract, drop or rename | unsafe | only from a copy | forward fix, or restore |
| Class rename or tombstone | blocked | blocked | forward fix, or restore a copy |
| Queue purge or dead-letter expiry | safe | impossible | forward fix only |
| Workflow step side effect | unsafe | impossible | restart from the step, with idempotent effects |
The recovery order is pause, identify, choose, act, verify, resume. Pausing first stops new work from landing while the decision is open, which turns two moving targets into one. Verify with a row count and a ledger query, not with a dashboard that lags the database.
Expand-contract is what keeps rollback cheap. While the old shape exists, the previous version is a real option. After the contract, the previous version is a museum piece: it deploys, and then it fails on the first write.
A forward fix is usually the only honest move after a contract. The data has already moved, so the release that repairs it must be additive against the current schema, not a rewind to the old one. Rolling forward is a new release with its own record, not a rollback with a different name.
A forward fix obeys the same expand rule as a feature. It is a release with its own record and its own gates; emergency is a reason to shorten review, not to skip the record. The fix must read the current schema and tolerate the data that already moved.
A restore is a data decision, and it is destructive in place. Time Travel cancels in-flight queries and overwrites the database, returning the previous bookmark so the restore itself can be undone. It does not restore the code, the bindings or the class lifecycle.
A bookmark has a window, and a restore starts a new history. Time Travel keeps thirty days on paid plans and seven on free, and a restored database has a new bookmark. Beyond the window an export is the only copy, so the export schedule is part of the release design rather than an operational afterthought.
Restore into a new database when the data matters more than the handle. Export the last good state, import it into a fresh database, verify it, then repoint the binding in a new version. That path costs a binding change and buys a recovery that does not overwrite production.
Choose a restore target whose schema matches a version you can still deploy. A bookmark from before the expand plus the current code is the same mismatch in the other direction. The restore point and the artifact must be chosen together, or the recovery just moves the failure.
The pairing rule is the whole decision. Pick the artifact and the restore point as one unit: an old artifact with new data fails on a missing column, and a new artifact with old data fails on a missing value. Only one pairing is consistent, and the release record should name it before the incident.
A Workflow instance can be restarted, not rewound. A restart from a step reuses the cached results before that step and re-runs everything after it, so side effects after the cut can happen twice. A fresh create with the same ID is refused while the instance is within retention, and a restart is the supported way to re-run it.
The incident record is part of the release record. Write the chosen option, the bookmark, the artifact, the verification query and the time into the same line. The next incident then starts from evidence instead of from memory.
| Option | Restores | Leaves in place | Choose when |
|---|---|---|---|
| Roll back the triple | artifact, contract and schema | data written since | no contract has run |
| Forward fix | nothing, adds a compatible release | current data and schema | data advanced or a class changed |
| Restore in place | rows at a bookmark | code and bindings | the mismatch is data and the code is compatible |
| Restore to a new database | rows in a new handle | production untouched | the data matters and a binding change is acceptable |
| Replay the dead letters | the work that failed | code and schema | the handler is fixed and messages are retained |
Review a stateful release
Execution status: design-only. The trace below was written against Terraform 1.17.1 and cloudflare/cloudflare 5.28.1, checked on 6 November 2026. It was not executed against a live account, so every expected result is documented behavior rather than a measurement.
The change under test. An orders table with a coupon column, one queue message per order, a Durable Object per customer, and a Workflow that fulfils the order. The release adds a discount code, moves reads onto it, then drops the coupon in a later release.
Prerequisites. A disposable account, a token with Workers, D1, Queues and Workflows write access, a scratch repository, a frozen build output, and a migration directory with one file. Use the smallest plan that supports the products, and never point the restore step at a database holding anything you want to keep.
- Baseline the triple. Apply the configuration and re-plan to an empty diff. Record the artifact digest, the binding names, the ledger tail and the bookmark in one release record, and export the database before the first destructive step.
- Expand. Add a nullable discount code and deploy the version that writes both fields. Expect old rows to remain valid and new rows to carry both values.
- Backfill. Run the batched job, record the cursor, then run it again. Expect the second run to change no rows.
- Switch reads. Deploy the version that prefers the new field and still writes both. Place one order and confirm both columns are populated.
- Contract. Deploy the version that stops writing the old field, then drop the column in a later release. Write down the release after which rollback is no longer possible.
- Attempt the rollback. Redeploy the dual-write version from step 4 after the drop. Expect a missing-column failure on the first write; that error is the lesson, not a defect.
- Fix forward. Deploy the contract version again, or a hotfix on top of it, that writes only the new field. Expect one order to complete without the dropped column and the ledger to stay at the contract head.
- Restore without matching the code. Restore the bookmark from step 1 while the hotfix is live. Expect the new column to be absent and reads to fail; the restore fixed the data and broke the contract.
- Choose the restore path. Restore into a new database from the export, run the repair migration there to rebuild the new column from the old one, and repoint the binding in a new version. Do not overwrite production while newer code is live.
| Observation | Passing result | Failing result means |
|---|---|---|
| Second backfill run | zero rows changed | the predicate is not idempotent |
| Order after the switch | both columns populated | dual-write was dropped early |
| Rollback after the contract | a clear missing-column error | the contract did not actually run |
| Forward fix after the contract | an order completes without the old column | the new code still reads it |
| Restore under newer code | the mismatch is visible and explainable | the restore did not happen |
| Class reconciliation | only the intended entries | a rename or tombstone slipped in |
| Dead-letter replay | one effect per business key | the consumer is not idempotent |
Decision rule. If the contract has run, roll forward. If the data is wrong and the code is compatible, restore. If both are true, restore to a new database and repoint the binding in a new version.
Cost and cleanup. A D1 database, one queue and a few Workflow steps sit in the lowest tiers, so the real cost is the account and the time to tear it down. Destroy the root, confirm the database, any restored copy, the queue and the definition are gone, and keep the release record rather than the token.
Sources. The provider schema for 5.28.1 was read directly, and the behavior above follows Cloudflare's documentation for D1 migrations, D1 Time Travel, queue batching and retries, Durable Object class exports, Durable Object code updates, Workflows rules, Workers infrastructure as code, and gradual deployments with Durable Objects.