<commit_before>using OrchardCore.Autoroute.Drivers;
using OrchardCore.Autoroute.Models;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.ContentManagement.Metadata.Settings;
using OrchardCore.ContentManagement.Records;
using OrchardCore.Data.Migration;
using YesSql.Sql;

namespace OrchardCore.Autoroute
{
    public class Migrations : DataMigration
    {
        private IContentDefinitionManager _contentDefinitionManager;

        public Migrations(IContentDefinitionManager contentDefinitionManager)
        {
            _contentDefinitionManager = contentDefinitionManager;
        }

        public int Create()
        {
            _contentDefinitionManager.AlterPartDefinition("AutoroutePart", builder => builder
                .Attachable()
                .WithDescription("Provides a custom url for your content item."));

            SchemaBuilder.CreateMapIndexTable<AutoroutePartIndex>(table => table
                .Column<string>("ContentItemId", c => c.WithLength(26))
                .Column<string>("ContainedContentItemId", c => c.WithLength(26))
                .Column<string>("JsonPath", c => c.Unlimited())
                .Column<string>("Path", col => col.WithLength(AutoroutePart.MaxPathLength))
                .Column<bool>("Published")
                .Column<bool>("Latest")
            );

            SchemaBuilder.AlterIndexTable<AutoroutePartIndex>(table => table
                .CreateIndex("IDX_AutoroutePartIndex_ContentItemIds", "ContentItemId", "ContainedContentItemId")
            );

            SchemaBuilder.AlterIndexTable<AutoroutePartIndex>(table => table
                .CreateIndex("IDX_AutoroutePartIndex_State", "Published", "Latest")
            );

            // Return 4 to shortcut the second migration on new content definition schemas.
            return 4;
        }

        // Migrate PartSettings. This only needs to run on old content definition schemas.
        // This code can be removed in a later version.
        public int UpdateFrom1()
        {
            _contentDefinitionManager.MigratePartSettings<AutoroutePart, AutoroutePartSettings>();

            return 2;
        }

        // This code can be removed in a later version.
        public int UpdateFrom2()
        {
            SchemaBuilder.AlterIndexTable<AutoroutePartIndex>(table => table
                .CreateIndex("IDX_AutoroutePartIndex_Published", "Published")
            );

            return 3;
        }

        // This code can be removed in a later version.
        public int UpdateFrom3()
        {
            SchemaBuilder.AlterIndexTable<AutoroutePartIndex>(table => table
                .AddColumn<string>("ContainedContentItemId", c => c.WithLength(26))
            );

            SchemaBuilder.AlterIndexTable<AutoroutePartIndex>(table => table
                .AddColumn<string>("JsonPath", c => c.Unlimited())
            );

            SchemaBuilder.AlterIndexTable<AutoroutePartIndex>(table => table
                .AddColumn<bool>("Latest", c => c.WithDefault(false))
            );

            SchemaBuilder.AlterIndexTable<AutoroutePartIndex>(table => table
                .DropIndex("IDX_AutoroutePartIndex_ContentItemId")
            );

            SchemaBuilder.AlterIndexTable<AutoroutePartIndex>(table => table
                .CreateIndex("IDX_AutoroutePartIndex_ContentItemIds", "ContentItemId", "ContainedContentItemId")
            );

            SchemaBuilder.AlterIndexTable<AutoroutePartIndex>(table => table
                .DropIndex("IDX_AutoroutePartIndex_Published")
            );

            SchemaBuilder.AlterIndexTable<AutoroutePartIndex>(table => table
                .CreateIndex("IDX_AutoroutePartIndex_State", "Published", "Latest")
            );

            return 4;
        }
    }
}<commit_msg>Update Autoroutes indexes (#7859)<commit_after>using OrchardCore.Autoroute.Models;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.ContentManagement.Metadata.Settings;
using OrchardCore.ContentManagement.Records;
using OrchardCore.Data.Migration;
using YesSql.Sql;

namespace OrchardCore.Autoroute
{
    public class Migrations : DataMigration
    {
        private IContentDefinitionManager _contentDefinitionManager;

        public Migrations(IContentDefinitionManager contentDefinitionManager)
        {
            _contentDefinitionManager = contentDefinitionManager;
        }

        public int Create()
        {
            _contentDefinitionManager.AlterPartDefinition("AutoroutePart", builder => builder
                .Attachable()
                .WithDescription("Provides a custom url for your content item."));

            SchemaBuilder.CreateMapIndexTable<AutoroutePartIndex>(table => table
                .Column<string>("ContentItemId", c => c.WithLength(26))
                .Column<string>("ContainedContentItemId", c => c.WithLength(26))
                .Column<string>("JsonPath", c => c.Unlimited())
                .Column<string>("Path", col => col.WithLength(AutoroutePart.MaxPathLength))
                .Column<bool>("Published")
                .Column<bool>("Latest")
            );

            SchemaBuilder.AlterIndexTable<AutoroutePartIndex>(table => table
                .CreateIndex("IDX_AutoroutePartIndex_DocumentId", "DocumentId")
            );

            // Return 5 to shortcut other migrations on new content definition schemas.
            return 5;
        }

        // Migrate PartSettings. This only needs to run on old content definition schemas.
        // This code can be removed in a later version.
        public int UpdateFrom1()
        {
            _contentDefinitionManager.MigratePartSettings<AutoroutePart, AutoroutePartSettings>();

            return 2;
        }

        // This code can be removed in a later version.
        public int UpdateFrom2()
        {
            return 3;
        }

        // This code can be removed in a later version.
        public int UpdateFrom3()
        {
            SchemaBuilder.AlterIndexTable<AutoroutePartIndex>(table => table
                .AddColumn<string>("ContainedContentItemId", c => c.WithLength(26))
            );

            SchemaBuilder.AlterIndexTable<AutoroutePartIndex>(table => table
                .AddColumn<string>("JsonPath", c => c.Unlimited())
            );

            SchemaBuilder.AlterIndexTable<AutoroutePartIndex>(table => table
                .AddColumn<bool>("Latest", c => c.WithDefault(false))
            );

            return 4;
        }

        // This code can be removed in a later version.
        public int UpdateFrom4()
        {
            SchemaBuilder.AlterIndexTable<AutoroutePartIndex>(table => table
                .CreateIndex("IDX_AutoroutePartIndex_DocumentId", "DocumentId")
            );

            return 5;
        }
    }
}
{'fraction_non_alphanumeric': 0.09194395796847636, 'fraction_numerical': 0.0049620548744892, 'mean_word_length': 2.286810551558753, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3869904', 'n_tokens_mistral': 1800, 'n_tokens_neox': 1714, 'n_words': 340}