Skip to content

SQL Server Primary key/Unique contrainst index with options DATA_COMPRESSION #33145

Description

@deadcativan

In #30408 index options "DATA_COMPRESSION" is supported, I think there is another place where the same thing is needed. It's the primary key when creating a table for an entity.

Currently I create a custom class extends SqlServerAnnotationProvider to add annotation for data compression as following:

    public class ExtendedSqlServerAnnotationProvider : SqlServerAnnotationProvider
    {
        public ExtendedSqlServerAnnotationProvider(RelationalAnnotationProviderDependencies dependencies) : base(dependencies)
        {
        }

        public override IEnumerable<IAnnotation> For(IUniqueConstraint constraint, bool designTime)
        {
            foreach (var annotation in base.For(constraint, designTime))
            {
                yield return annotation;
            }

            if (!designTime)
            {
                yield break;
            }

            var key = constraint.MappedKeys.First();

            var table = constraint.Table;

            var dataCompression = key.GetDataCompression(StoreObjectIdentifier.Table(table.Name, table.Schema));
            if(dataCompression.HasValue)
            {
                yield return new Annotation(SqlServerAnnotationNames.DataCompression, dataCompression.Value);
            }

        }
    }

And then I extend SqlServerMigrationsSqlGenerator to build SQL for index options according to this annotation in AddPrimaryKeyOperation and AddUniqueConstraintOperation.

Finally I add extension methods xxx.UseDataCompression like the way index does.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions