Skip to content

MigrationUtils class

namespace: Serenity.Extensions   assembly: Serenity.Extensions

Helper methods for FluentMigrator migrations, including table creation with identity keys and database type detection.

public static class MigrationUtils

Public Members

name description
static AddConcurrencyVersionTrigger(…) Adds a database trigger that increments this column on every update, providing optimistic concurrency support for rows implementing Serenity.Data.IConcurrencyVersionRow. (2 methods)
static AddOracleIdentity(…) Adds an Oracle sequence and trigger to generate identity values for the specified column.
static AsUserIdType(…) Sets the column type based on the UserEntityOptions.IdFieldType, which can be Int32Field, Int64Field, StringField, or GuidField.
static AutoIncrement(…) Declares column as auto increment (e.g. Identity()) if the database is something other than Oracle, defines an Oracle sequence otherwise. It also calls NotNullable() as it is not possible for auto increment / sequence columns to be nullable. This assumes the column will NOT be set as PrimaryKey(), just as an auto incrementing value. As MySql does not support AUTO_INCREMENT without primary key or an index, this first creates the column as a regular one, then creates an index and modifies it to be an AUTO_INCREMENT.
static ClearAllPools(…) Clears the connection pools of the database provider for the specified connection key, so that connections opened before the database was created are not reused. Does nothing if the provider is not registered, or its connection type has no static ClearAllPools method.
static CreateTableWithId32(…) Please prefer IdentityKey(this) on the fluent column builder
static CreateTableWithId64(…) Please prefer IdentityKey(this) on the fluent column builder
static DropConcurrencyVersionTrigger(…) Drops the concurrency version trigger created by AddConcurrencyVersionTrigger.
static EnsureDatabase(…) Ensures the database for the specified connection key exists, creating it if necessary.
static GetConcurrencyVersionTriggerSql(…) Generates the SQL statements that create the concurrency version trigger for the given database type.
static GetDialect(…) Gets the SQL dialect for the database the migration is running against. It can be used to quote identifiers and strings in the statements passed to Execute.Sql.
static GetSystemUserId(…) Gets the ID of the user that rows inserted by migrations are attributed to, e.g. as their InsertUserId, from SystemUserId.
static HasIdentityUserId(…) Returns true if the user IDs are generated by the database, e.g. an identity column, which is the case for Int32Field and Int64Field IDs.
static IdentityKey(…) Declares column as Identity() if the database is something other than Oracle, defines an Oracle sequence otherwise. It sets the column as PrimaryKey() and also calls NotNullable() as it is not possible for identity / sequence columns to be nullable.
static If<TSyntax>(…) Invokes the callback only when the predicate is true, otherwise returns the syntax unchanged.
static IsDatabase(…) Determines whether the migration is running against a database whose type starts with the specified name. (2 methods)
static IsFirebird(…) Determines whether the migration is running against a Firebird database.
static IsMySql(…) Determines whether the migration is running against a MySql database.
static IsOracle(…) Determines whether the migration is running against an Oracle database.
static IsPostgres(…) Determines whether the migration is running against a Postgres database.
static IsSqlite(…) Determines whether the migration is running against a Sqlite database.
static IsSqlServer(…) Determines whether the migration is running against a SqlServer database.
static MapCollation(…) Gets the column collation for the specified comparison on the database the migration is running against, in the form to pass to AsString.
static TryMapCollation(…) Tries to get the column collation for the specified comparison on the database the migration is running against, in the form to pass to AsString.
static UserIdForeignKey<TNext,TNextFk>(…) Sets the foreign key for a user ID column based on the UserEntityOptions, linking it to the "Users" table and "UserId" column.

See Also