DeclarationBreaksFacts. The refusal names each change and how to make it.
Use column migrations for supported
renames and casts. For other changes, evolve the table in steps with
application mutations. Retire a non-empty table with
drop("<table>").
What deploy accepts
Deploy first compares the installed declaration with the new one. A change the types alone prove safe is accepted without reading any fact:
Without a matching migration, any other change is accepted only if a single fact about the table’s
current facts holds. The current facts are the table’s facts now (every
valid-time slice, for a series or timeline) and the facts each open branch
has written but not yet landed:
A field that refuses
null holds a value in every fact, so only an empty
table proves it empty.
Without a cast, a narrowed type is refused while the field holds values,
even if every value would pass the new type.
Deploy decides these facts from counts. The store keeps two
counts exact at every write, at every place the table’s facts live: how
many current facts the table holds, and how many of them hold a value of
each field that accepts null. A fact of a series or timeline counts while
any of its valid-time slices holds the value. Deploy reads one count per
place, so the check costs the same however many facts the table holds. An
open branch counts every fact it reads, including facts it
inherited when it was created: while it still reads a value its parent has
since removed, deploy refuses the change until it lands or is dropped.
A field whose values the table keeps sealed (a protected or erasable table,
or a shared-unit field) has no such count, because a count kept per fact
would reveal whether each sealed value is null. Deploy accepts a change
to such a field only once the table is empty, and otherwise refuses it with
DeclarationConditionSealed.
Use t.default(type, literal) to supply a value to earlier facts when a
deploy adds a field. New writes supply the field as part of the fact.
Check before you deploy
bijection check records each table’s declared shape in bijection.lock,
as a table <path> <shape> line, so a review sees the table diff. It
compares the derived shapes with the committed lock and lists every table
change. For each change, it reports either that the change is safe, or the
condition deploy needs before it accepts the change. A matching migration
is named in the same diff.
bijection check --write-lock also records each declared migration. Commit
the reviewed lock with the app changes. Deploy checks the target’s facts.
Declare a column rename or cast
Change the table declaration and list the instructions beside the root app tree. In this example, the installedcustomers table had fullName
and stored balance as text.
bijection/app.ts
"string", "number", "int", or
"boolean". Casts preserve absent fields and values already of the target
type. A string cast represents null as "null". Other casts preserve null.
Conversions include finite numeric text to numbers, whole
numbers in range to 64-bit integers, and the exact text true or false to booleans.
Rename, cast, rekey, and relabel apply to app tables. The deploy validates
current facts before activation and publishes the new declaration with the
carried facts. Carried facts keep their IDs, erasure units, and holds.
The column rewrite budget is 4,096 facts.
Declare a changed key as { rekey: { table: customers, key: ["name"] } }.
A collision in the new key among current facts refuses with
DeclarationBreaksRows. A rekey carries history when the key fields
are renamed in the same order. Declare endsHistory for any other rekey.
A downward relabel requires { relabel: { table: customers, release } }.
The cutover records the release in sys.disclosures and moves current facts.
The deployer needs live clearance for every declared place its checks inspect.
Keep the same instructions on later deploys if the successor schema still
matches them. The installed program records which instructions it already
applied.
Read across a deploy
A table keeps its identity as its layout changes. A new table that reuses a dropped name starts a fresh identity. A query at an earlier version reads the relation at that cut and applies the declared migration chain. A cast that cannot convert every old value requires anotherwise literal. A total cast must omit it. A cast cannot
write a field used by a key or label selector. A field in a unique index can
be cast, otherwise included: the deploy rebuilds the index over current and
retained facts and refuses with Exists (UniqueTaken) if two facts convert
to the same value.
Refinements such as bounds, lengths, patterns,
finiteness, and File media types and size limits bind writes from the deploy on.
Earlier values carry unchanged. A field whose static type narrows needs a cast.
A cast can declare { cast: { table: orders, field: "quantity", to: "int", otherwise: 0n } }.
The cast keeps a value the successor type admits, tries the optional conversion,
then uses the literal if the conversion fails or its result is refused. A
completed cast carries historical id points and id-order ranges. A partial cast
needs endsHistory. Renames, widening casts, nullable or defaulted additions,
field projections, and compatible index edits can also carry history.
Declare an ending with { endsHistory: customers }. Check and deploy refuse
an undeclared end with Invalid and reason MigrationEndsHistory.
The lock and bijection deploy --trial show which boundaries carry or end
history. A read across an ending boundary refuses Expired with reason
SchemaChanged. Use ctx.call(query, args, { in: version, program: version })
to run the query installed at the cut while its history is retained.
Historical reads need clearance for the original fact’s label and the
table’s current label. A lens can serve id points, id-order ranges, and
keyed selections with an order the generation chain carries. An aggregate
reads from the generation that held its definition at the selected version.
A request that predates its definition refuses with SchemaChanged.
Change a deferred function contract
A deferred invocation records its function path and calling-contract digest. The active program resolves the recorded call through the accepted chain. Check and deploy compare declarations for continuation handlers, target performers and answer handlers, and internal runs.Invalid with reason
ContractNeedsMigration. A retired function or an argument the chain
cannot carry leaves its obligation stuck with ProgramContractChanged. A
declared retirement withdraws it with the declared message the next time
it is visited. A compatible handler already at head still accepts it.
A compatible deploy re-arms it at its label on its next visit and keeps its
attempts. Manual ctx.retry re-arms it and resets its attempts, and
ctx.withdraw closes it. A task whose run function was retired ends
Withdrawn (FunctionRetired) with the declared message, whether or not it
was claimed.
Add, migrate, then remove
Changes that need an application backfill follow three steps.- Add the new shape, in a form that is safe over the facts that exist.
- Migrate the facts in app code.
- Remove the old shape once no fact needs it.
Add a field
Declare the fieldt.maybe(x). Existing facts read it as null, and new
writes set it.
null can be added only to an empty table. To get a
required field over existing facts, declare a new table. The section
change a key or a label shows how.
Remove a field
If the field refusesnull, first declare it t.maybe(…), which is always
safe. Then deploy a mutation that writes null to the field in every fact,
and run it until no fact holds a value. Then remove the field.
orders.changes to clear the field as facts are
written.
Change or narrow a field’s type, or rename a field
When a column change needs an application backfill, move the data to a new field in stages.- Add a new field with the new type, as
t.maybe(…). - Backfill the new field from the old one in app code, and write both fields from now on.
- Move your readers to the new field, and stop writing the old one.
- Write
nullto the old field in every fact, after declaring itt.maybe(…)if it refusesnull. - Remove the old field.
Change a key or a label
Keep the existing key on a populated table. A label change that tightens access carries facts into the successor layout with their custody units intact. Historical reads still use the original relation and its labels.Remove a table
Either delete the table’s facts first and remove its declaration, or retire a non-empty table explicitly withdrop("<table>") from @bijectionhq/bijection
in app(tree, { migrations }):
bijection/app.ts
- Removing a table that still holds facts without declaring
droprefuses withDeclarationBreaksFacts. - Listing
dropfor a table the app tree still declares refuses withDropDeclaredTable. - Listing
dropfor a table already gone is a no-op, so a program may keep its drops across deploys.
drop activates, the table leaves the catalog and writes
close immediately. Its facts stay readable inside the table’s history window
(30 days by default), after which the collector reclaims every fact except
those kept by a standing legal hold. A held fact
outlives the dropped table until its hold is lifted, and a drop never refuses
because of a hold. A later table declared with the same name gets a fresh
address.
In the console, Delete table on a declared table shows the exact schema
edit and deploy command, and offers Clear facts (paged operator deletes)
to empty a table without a deploy. Retired tables still inside their history
window appear in the retired-tables list, where an operator with Deploy
can purge a table to end its retention immediately (refused with
PurgePinned while a live pin’s version is newer than the retirement; legal
holds are preserved silently).