Optimizely CMS: How to Refactor Content Types and Properties
Introduction
In modern code-first Optimizely CMS architectures, compiled C# classes serve as the authoritative schema for both the underlying relational database and downstream headless delivery systems like Optimizely Graph. During application initialisation, the framework synchronisation engine reconciles these compiled types against system tables including tblContentType and tblPropertyDefinition .
Standard IDE refactoring, such as modifying a class identifier or property name without schema migration instructions, introduces three critical failure modes:
- Schema Link Detachment : The synchronisation engine encounters unfamiliar identifiers during boot and registers refactored classes as novel schema elements.
- Orphaned Database Records : Uncoordinated divergence leaves historical database rows orphaned in tblContentType and tblPropertyDefinition .
- API and Delivery Breakages : Unmanaged refactoring mutates the downstream GraphQL schema immediately, causing live production templates and headless consumers to render blank.
Safeguarding content integrity requires an operational approach across two primary vectors:
- Relational Identity Anchoring : Binding persistent database records directly to immutable [ContentType] GUIDs.
- Contract Preservation : Managing downstream API contracts and property renames through declarative migration APIs.
Following this structured implementation pattern ensures content models and properties refactor cleanly, maintaining uninterrupted content attachment across enterprise continuous integration and deployment pipelines.
Overview and Architectural Context of Code-First Content Modeling
Optimizely CMS synchronises compiled types inheriting from PageData or BlockData during application startup, as detailed in Synchronization - Optimizely Developer Documentation . The initialisation pipeline scans loaded assemblies and reconciles C# properties with relational definitions in tblContentType and tblPropertyDefinition .
Renaming a model from OldArticlePage to ArticlePage without migration metadata causes the synchronisation engine to treat the renamed class as an unmapped entity. This breakdown impacts the runtime environment in two distinct ways:
- Administrative State Fragmentation : The CMS provisions a new type entry while existing database records remain bound to the legacy identifier, surfacing in the administrative interface as "missing code".
- Runtime Null References : Public-facing templates referencing the refactored class fail to bind historical content instances, returning null references in production.

The Model GUID Rule and Database Identity Anchoring
The fundamental defence against identity fragmentation is the GUID parameter assigned in the [ContentType] attribute, documented in Refactor content type classes - Optimizely Developer Documentation :
[ContentType(
DisplayName = "Article Page",
GUID = "9F8E7D6C-5B4A-3210-FEDC-BA9876543210",
Description = "Standard article page model."
)]
public class ArticlePage : PageData { }
The framework utilises this immutable GUID as the primary key linking the C# class to its row in tblContentType . Retaining this exact GUID maintains relational integrity across model refactoring:
- Automatic Schema Updates : Renaming the C# class updates the display name and type mapping directly in the database without creating duplicate records.
- Identity Continuity : The persistent GUID maintains historical content linkage across all existing page instances.
- Immutability Mandate : Never generate a new GUID when refactoring an existing model, as this forces a fork in tblContentType .

MigrationStep Mechanics and Implementation Blueprint
Property-level renames and legacy system name mappings require implementing EPiServer.DataAbstraction.Migration.MigrationStep . Discovered automatically via reflection during boot without manual dependency injection registration, concrete implementations override AddChanges() using a fluent mapping syntax:
using EPiServer.DataAbstraction.Migration;
public class RefactorArticlePageMigration : MigrationStep
{
public override void AddChanges()
{
ContentType("ArticlePage")
.UsedToBeNamed("OldArticlePage");
ContentType("ArticlePage")
.Property("MainBody")
.UsedToBeNamed("IntroText");
}
}
When constructing concrete migration steps, enforce two structural implementation rules:
- Target the New Model : Property mappings must chain directly from the new content type name ( ArticlePage ), not the historical identifier.
- Batch Modifications : Consolidate multiple property and class transitions within a single migration class or across modular migration files.

Execution Sequence and Startup Synchronization Order of Operations
During initialisation, Optimizely CMS executes synchronisation across three distinct sequential phases:
- Assembly Discovery & Validation : Scans assemblies for [ContentType] classes and verifies that no conflicting GUIDs exist.
- Migration Step Execution : Executes unapplied MigrationStep classes, renaming existing records directly within tblContentType and tblPropertyDefinition in place to prevent destructive recreate cycles.
- Database Schema Commit : Updates runtime schema metadata.
Operational Caveat : Direct manual configuration changes applied via CMS Admin Mode take precedence over code-defined attributes until an administrator explicitly triggers a "Revert to Default" action.
Optimizely Graph Synchronisation Warning : In modern headless architectures, executing a MigrationStep intrinsically mutates the downstream GraphQL schema. Maintaining headless delivery continuity requires two mandatory coordination steps:
- Optimizely Graph Push : Developers must execute an explicit push to Optimizely Graph to synchronise the updated schema structure.
- Frontend Query Alignment : Frontend GraphQL queries must be refactored concurrently to match the new property names, preventing null references and query-level breaking changes.

Visual Suggestion : Chronological sequence diagram of CMS initialization showing Assembly Scan, MigrationStep Execution, and Database Schema Commit.
Production Deployment, Verification Testing, and Risk Mitigation
Deploying refactored content models requires disciplined pipeline controls across five operational areas:
- Automated CI Validation : Replace passive discipline with structural enforcement by implementing specialised Roslyn Analyzers or reflection-based CI gates. These test fixtures programmatically diff the [ContentType] attributes of the main branch against the feature branch during pull requests to proactively fail builds if an existing GUID is altered or duplicated.
- Type Alteration Limits : UsedToBeNamed() handles rename operations exclusively. Modifying data types (such as string to XhtmlString ) requires custom migration routines using IContentRepository , because dynamic property values persist across specialised typed value columns ( LongString , Number ) in the SQL database.
- Commerce Scope : MigrationStep applies strictly to CMS content types; it does not support Commerce catalogue MetaFields .
- Zero-Downtime Deployment : For blue-green deployments , configure ContentModelOptions.EnableModelSyncCommit = false in application settings to prevent premature schema commits on staging slots.
- Class Retirement : Retain migration classes in the codebase until all target environments and legacy database restore windows have been updated.

Conclusion & Strategic Advice
Code-first schema refactoring in Optimizely CMS requires systematic architecture across dual fronts: relational SQL preservation and downstream API contract management. Retaining immutable [ContentType] GUIDs secures macro-level identity anchoring, while MigrationStep provides precise, in-place property reconciliation.
To execute stable schema migrations in enterprise environments, apply three strategic practices:
- Declarative Renames : Rely on declarative MigrationStep definitions for routine class and property renames.
- Type Mutations : Pair naming updates with programmatic IContentRepository batch scripts when executing data type mutations.
- Staging Validation : Validate all schema migrations against a sanitised production database restore before deploying code to live environments, using programmatic CI gates to enforce structural integrity.
How does your team safeguard content models during rolling deployments in Optimizely DXP? Drop your experiences below💬 and share this blueprint with your engineering team! ♻️
Further Reading
- Refactor content type classes - Optimizely Developer Documentation
- Synchronization - Optimizely Developer Documentation
- Microsoft .NET Application Architecture: Common Web Application Architectures
- Optimizely World: Content Model Synchronization & Database Architecture
More From Me
Original Article: Read on LinkedIn | Read on Substack