Skip to main content

Types of Schema Changes

Understanding which types of schema changes are safe versus breaking is crucial for evolving your SharedTree schemas without disrupting existing applications. Writing a test using snapshotSchemaCompatibility is highly recommended to ensure any schema changes maintain your compatibility requirements. Knowledge of the details below will still be needed to design schemas such that the required future changes can be compatible, and to understand any errors detected by the test.

The tables below distinguish two directions of compatibility: backward compatibility (BC) lets a later view use earlier documents, while forward compatibility (FC) lets an earlier view use later documents.

A client may be required to upgrade a document's stored schema before viewing it. Such a client's view schema is still considered compatible, so long as upgrading the document would make it viewable.

important

These results assume that the client's installed Fluid Framework library versions support the required upgrade and that its application code applies it. Snapshot checks use the currently installed runtime for every historical schema, so verify deployed runtime support separately as described under Checking Compatibility.

All the examples below are modifying this schema:

class Note extends factory.object("Note", {
id: factory.string,
text: factory.string,
color: factory.optional([factory.string, factory.number]),
}) {}

Compatible Changes​

The following changes are backwards compatible. However, it's important that applications carefully review whether the change is forwards compatible inherently or if a staged rollout is necessary.

Adding Optional Fields​

BCFC
✅✅ if the older view's object schema allows unknown optional fields*
class Note extends factory.object("Note", {
id: factory.string,
text: factory.string,
color: factory.optional([factory.string, factory.number]),
height: factory.optional(factory.number), // New optional field
}) {}
caution

The table's forwards-compatibility result depends on the older clients, not just the new declaration shown above. Those clients must already enable allowUnknownOptionalFields to tolerate the added field. Although the option now defaults to true, check the settings and library versions of deployed clients before relying on that default.

If it's not already set, then adding a new optional field at the same time as enabling allowUnknownOptionalFields is not forwards compatible, since old clients without allowUnknownOptionalFields will reject the unknown field. In that case, a staged rollout is needed: first release a version that enables allowUnknownOptionalFields, then add the new field in a subsequent release.

class Note extends factory.object("Note", {
id: factory.string,
text: factory.string,
color: factory.optional([factory.string, factory.number]),
// Existing optional fields
}, { allowUnknownOptionalFields: true }) {}

Removing Optional Fields from a View​

BCFC
✅ if the newer view's object schema allows unknown optional fields*✅
// Remove the optional `color` field from application code.
// This does not remove it from existing stored documents.
class Note extends factory.object("Note", {
id: factory.string,
text: factory.string,
// color: factory.optional([factory.string, factory.number]), // REMOVED
}) {}

On an existing document, the reduced view treats color as unknown content. It can still read and edit id and text, and later compatible upgrades retain color with its allowed types, referenced node definitions, and data. Removing the view declaration therefore does not erase historical data or reduce document storage.

In contrast, a new document initialized with the reduced view has no color field in its stored schema. An older client that declares color must upgrade that document before using its view.

If a later release restores a compatible declaration with the same stored key, retained color data becomes accessible again. This does not permit reusing the key for an incompatible field; see the rollback example and data-loss warnings.

Making Required Fields Optional​

BCFC
✅❌

Note: There is currently no way to make this change in a forwards compatible way.

class Note extends factory.object("Note", {
id: factory.string,
text: factory.optional(factory.string), // previously required
color: factory.optional([factory.string, factory.number]),
}) {}

Adding New Allowed Types​

BCFC
✅❌
class Note extends factory.object("Note", {
id: factory.string,
text: [factory.string, factory.array(factory.string)],
color: factory.optional([factory.string, factory.number]),
}) {}

To achieve forwards compatibility, staged allowed types can be used to roll out support for reading before writing, allowing older clients to read data created with new types. See Rolling Out New Allowed Types for details.

Incompatible Changes​

These changes are not supported because they would otherwise make newer clients unable to open older documents and older clients unable to open newer documents. An upgrade can expand the set of content allowed by the stored schema, but it cannot teach a view to handle a value or missing field that the view no longer supports. For that reason, preserving existing content in an upgrade candidate is not enough to make these changes compatible.

Removing Required Fields​

// Breaking: Removing a required field
class Note extends factory.object("Note", {
id: factory.string,
// text: factory.string, // REMOVED
color: factory.optional([factory.string, factory.number]),
}) {}

Backward compatibility: this change prevents newer clients from opening documents created with the old schema, because those documents will have the text field, which such clients are not equipped to read, and require the text field on new Note instances, which such clients are not equipped to write.

Forward compatibility: this change prevents older clients from opening documents created with the new schema, because those documents will be missing the text field such clients want to read and write.

Making Optional Fields Required​

// Breaking: Making optional field required
class Note extends factory.object("Note", {
id: factory.string,
text: factory.string,
color: [factory.string, factory.number], // Was optional, now required - BREAKING!
}) {}

Backward compatibility: this change prevents newer clients from opening documents created with the old schema, because those documents may not have the color field, which such clients are expecting to be populated.

Forward compatibility: an older view still permits clearing color, so it cannot use a document whose stored schema requires that field. It may be able to upgrade the document to make color optional again, but this does not solve the new view's inability to read historical documents where color is absent. The change is therefore not safe for a rollout that must continue to support those documents.

Changing Field Types​

// Breaking: Changing field type
class Note extends factory.object("Note", {
id: factory.number, // Was factory.string - BREAKING!
text: factory.string,
color: factory.optional([factory.string, factory.number]),
}) {}

Backward compatibility: this change prevents newer clients from opening documents created with the old schema, because those documents will use the string type for the id field, which such clients read and write as number.

Forward compatibility: older clients expect string id values and cannot read the numbers permitted by the new document schema. An upgrade that retained both types would preserve existing content, but the older view would still lack number support. The upgrade must therefore be rejected rather than treating the larger type set as proof of compatibility.

Removing Allowed Types​

// Breaking: Removing allowed type
class Note extends factory.object("Note", {
id: factory.string,
text: factory.string,
color: factory.optional([factory.string]), // removed factory.number
}) {}

Backward compatibility: this change prevents newer clients from opening documents created with the old schema, because those documents can use the number type for the color field, which such clients read and write as string.

Forward compatibility: the older view still allows writing numbers to color, so it must upgrade a new string-only document before using it. Restoring number support can be safe for that older view, but the resulting document is no longer compatible with the narrowed, string-only view. The ability to perform that upgrade therefore does not make the two application versions compatible collaborators.

See Also​