Search Results for

    Show / Hide Table of Contents

    Custom metadata for the VersionInfo table

    By implementing the IVersionTableMetaData interface you can change the defaults for the VersionInfo table. The interface exposes six properties:

    Property Default value Description
    SchemaName (empty) The schema where the version table is stored
    TableName "VersionInfo" The table where the version information is stored
    ColumnName "Version" The name of the column where the version numbers are stored
    DescriptionColumnName "Description" The name of the last migration applied
    AppliedOnColumnName "AppliedOn" The datetime of when the last migration was applied
    UniqueIndexName "UC_Version" The name of the unique constraint for the version column

    In the same assembly that your migrations are located, create a new class (it must be public) that implements the IVersionTableMetaData interface and decorate the class with the VersionTableMetaDataAttribute. FluentMigrator will automatically find this and use it instead of the default settings.

    Note

    The custom IVersionTableMetaData is filtered by the values in the TypeFilterOptions. This allows different IVersionTableMetaData for every database.

    A common use case is changing the default schema so that you can have a migration assembly per schema.

    using FluentMigrator.Runner.VersionTableInfo;
    
    namespace Migrations
    {
        [VersionTableMetaData]
        public class CustomVersionTableMetaData : IVersionTableMetaData
        {
            public virtual string SchemaName => "";
    
            public virtual string TableName => "VersionInfo";
    
            public virtual string ColumnName => "Version";
    
            public virtual string UniqueIndexName => "UC_Version";
    
            public virtual string AppliedOnColumnName => "AppliedOn";
    
            public virtual string DescriptionColumnName => "Description";
    
            public virtual bool OwnsSchema => true;
        }
    }
    

    Finally, register it via Microsoft Dependency Injection:

    serviceCollection.AddScoped(typeof(IVersionTableMetaData), typeof(CustomVersionTableMetaData));
    

    Overriding the DefaultVersionTableMetaData class

    If you want to keep most of the default values and just change one or two of the properties. Then you can create a class that inherits from DefaultVersionTableMetaData and override the property to be changed. Don't forget to add the VersionTableMetaData attribute to the class.

    [VersionTableMetaData]
    public class VersionTable : DefaultVersionTableMetaData
    {
        public override string ColumnName
        {
            get { return "Version"; }
        }
    }
    

    Finally, register it via Microsoft Dependency Injection:

    serviceCollection.AddScoped(typeof(IVersionTableMetaData), typeof(VersionTable));
    
    • Edit this page
    In this article
    Back to top
    Copyright © 2018 Fluent Migrator Project
    Generated by DocFX
    Creative Commons License
    FluentMigrator Documentation by FluentMigrator Project is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.