Table of Contents

Method UpdateSchema

Namespace
YndigoBlue.Velocity.Engine
Assembly
YndigoBlue.Velocity.dll

UpdateSchema(Schema, bool)

Updates an existing schema to match the provided schema definition by adding, modifying, or removing objects.

public void UpdateSchema(Schema schema, bool ignoreWarnings = false)

Parameters

schema Schema

A Schema object containing the desired schema state.

ignoreWarnings bool

If true, ignores warnings for operations not supported by the database.

Examples

using (var m = new Manager(conn))
{
    var schema = m.LoadSchema("app");

    // --- Scenario 1: Add a new table ---
    // CreateTable adds the table to the schema but does not mark it for creation.
    // Set SchemaUpdate = true so UpdateSchema creates it in the database.
    var newTable = schema.CreateTable("products");
    newTable.SchemaUpdate = true;
    newTable.CreateColumn("id", DataType.Integer, autoGenerate: true);
    newTable.CreateColumn("name", DataType.VarChar, notNull: true, size: 100);
    newTable.CreateColumn("price", DataType.Decimal, precision: 10, scale: 2);
    newTable.CreatePrimaryKey("pk_products", "id");

    // --- Scenario 2: Add a column to an existing table ---
    // AddColumn automatically sets Column.SchemaUpdate = true.
    var usersTable = schema["users"];
    usersTable.AddColumn("phone", DataType.VarChar, size: 20);

    // --- Scenario 3: Modify an existing column ---
    // Modify* methods automatically set Column.ColumnUpdate = true.
    usersTable["email"].ModifySize(200);

    // --- Apply all flagged changes to the database ---
    m.UpdateSchema(schema);
}

Remarks

Warning

The UpdateSchema method is not available in the Community Edition of Velocity. It requires the Full Edition.

UpdateSchema uses opt-in flags on tables and columns to determine what changes to apply. Only objects explicitly marked for update are processed — objects without a flag set are treated as already in sync with the database and are left untouched.

Table.SchemaUpdate — Set to true on a table to create it as a new table in the database. When a table has SchemaUpdate = true, all of its columns, constraints, and indexes are also created as part of the same operation. This flag must be set explicitly after calling schema.CreateTable().

Column.SchemaUpdate — Set to true on a column to add it to an existing table in the database. This flag is set automatically when you call table.AddColumn(), so you do not need to set it manually when adding columns to existing tables.

Column.ColumnUpdate — Set to true on a column to modify its properties in the database (data type, size, nullability, or precision/scale). This flag is set automatically by the column's Modify*() methods: ModifyDataType(), ModifySize(), ModifyNotNull(), and ModifyPrecisionScale().

Constraint.SchemaUpdate — Set to true on a constraint to add it to an existing table. Constraints on tables that already have Table.SchemaUpdate = true are always created regardless of this flag.

Exceptions

DbException

Thrown when a database error occurs.