Skip to content

Schema & Reconciliation ​

JASE.Database does not hide schema behind opaque migrations. You describe tables in metadata (TableInfo / column attributes), compare that model to the live database, and apply the resulting DDL deliberately.

Mental model ​

PieceRole
POCO + attributesDeclares the desired shape ([Table], [PrimaryKey], column attributes, indexes, …)
TableInfoCached metadata for a type (or a hand-built table). Created via TableInfo.GetOrCreate(typeof(T)) or constructed and Validate()d
ColumnInfoPer-column type, nullability, defaults, dialect specifics
CompareTableDiff: live DB table vs model → TableDifferences
SchemaReconciliationWalks model types, compares, optionally emits/applies DDL

Reflection is front-loaded: once TableInfo exists, materializers and binders reuse it.

From POCOs to metadata ​

csharp
ITableInfo table = TableInfo.GetOrCreate(typeof(Customer));
// or hand-build columns, then:
table.Validate();

Use hand-built TableInfo when the table is not owned by a single POCO (views, shared DDL, metadata-first design). Invalid POCO shapes should fail at GetOrCreate, not on first GetByPk.

Reconciliation ​

csharp
using JASE.Database;

// Discover types marked with [Table] / System.ComponentModel TableAttribute
IReadOnlyList<Type> models = SchemaReconciliation.GetTableModels(typeof(Customer).Assembly);

TableInfoOptions tableOptions = new(); // naming, dialect defaults
SchemaReconciliationOptions? options = null;

Models.SchemaVersion? version = await SchemaReconciliation.Execute(
    session,
    models,
    tableOptions,
    options);

Overloads accept lists for emitted DdlStatements and non-blocking SchemaChangeWarnings (for example indexes dropped because a referenced column is leaving).

Soft-release posture: treat reconcile as powerful DDL tooling — review statements in non-prod first. Prefer explicit apply paths in production hosts rather than “always auto-migrate on startup.”

What reconcile is good for ​

  • Bringing a database up to match attribute-driven models
  • Detecting drift between code and DB
  • Generating dialect-aware create/alter for SQL Server and PostgreSQL