<commit_before>using System.Data;
using Umbraco.Cms.Infrastructure.Migrations.Expressions.Alter.Expressions;
using Umbraco.Cms.Infrastructure.Migrations.Expressions.Common.Expressions;
using Umbraco.Cms.Infrastructure.Migrations.Expressions.Create.Expressions;
using Umbraco.Cms.Infrastructure.Persistence;
using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
using Umbraco.Cms.Infrastructure.Persistence.DatabaseModelDefinitions;

namespace Umbraco.Cms.Infrastructure.Migrations.Expressions.Alter.Table;

public class AlterTableBuilder : ExpressionBuilderBase<AlterTableExpression, IAlterTableColumnOptionBuilder>,
    IAlterTableColumnTypeBuilder,
    IAlterTableColumnOptionForeignKeyCascadeBuilder
{
    private readonly IMigrationContext _context;

    public AlterTableBuilder(IMigrationContext context, AlterTableExpression expression)
        : base(expression) =>
        _context = context;

    public ColumnDefinition CurrentColumn { get; set; } = null!;

    public ForeignKeyDefinition CurrentForeignKey { get; set; } = null!;

    public void Do()
    {
        if (_context.Database.DatabaseType.IsSqlite())
        {
            throw new NotSupportedException($"SQLite do not support ALTER TABLE operations.Instead you will have to:{Environment.NewLine}1. Create a temp table.{Environment.NewLine}2. Copy data from existing table into temp table.{Environment.NewLine}3. Delete existing table.{Environment.NewLine}4. Create new table with existing name but new signature{Environment.NewLine}5. Copy data from temp table into the new table.{Environment.NewLine}6. Delete temp table.");
        }
        Expression.Execute();
    }

    public IAlterTableColumnOptionBuilder WithDefault(SystemMethods method)
    {
        CurrentColumn.DefaultValue = method;
        return this;
    }

    public IAlterTableColumnOptionBuilder WithDefaultValue(object value)
    {
        if (CurrentColumn.ModificationType == ModificationType.Alter)
        {
            var dc = new AlterDefaultConstraintExpression(_context)
            {
                TableName = Expression.TableName,
                ColumnName = CurrentColumn.Name,
                DefaultValue = value,
            };

            Expression.Expressions.Add(dc);
        }

        CurrentColumn.DefaultValue = value;<commit_msg>Grammar (do -> does) and some extra text<commit_after>using System.Data;
using Umbraco.Cms.Infrastructure.Migrations.Expressions.Alter.Expressions;
using Umbraco.Cms.Infrastructure.Migrations.Expressions.Common.Expressions;
using Umbraco.Cms.Infrastructure.Migrations.Expressions.Create.Expressions;
using Umbraco.Cms.Infrastructure.Persistence;
using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
using Umbraco.Cms.Infrastructure.Persistence.DatabaseModelDefinitions;

namespace Umbraco.Cms.Infrastructure.Migrations.Expressions.Alter.Table;

public class AlterTableBuilder : ExpressionBuilderBase<AlterTableExpression, IAlterTableColumnOptionBuilder>,
    IAlterTableColumnTypeBuilder,
    IAlterTableColumnOptionForeignKeyCascadeBuilder
{
    private readonly IMigrationContext _context;

    public AlterTableBuilder(IMigrationContext context, AlterTableExpression expression)
        : base(expression) =>
        _context = context;

    public ColumnDefinition CurrentColumn { get; set; } = null!;

    public ForeignKeyDefinition CurrentForeignKey { get; set; } = null!;

    public void Do()
    {
        if (_context.Database.DatabaseType.IsSqlite())
        {
            throw new NotSupportedException($"SQLite does not support ALTER TABLE operations. Instead you will have to:{Environment.NewLine}1. Create a temp table.{Environment.NewLine}2. Copy data from existing table into the temp table.{Environment.NewLine}3. Delete the existing table.{Environment.NewLine}4. Create a new table with the name of the table you're trying to alter, but with a new signature{Environment.NewLine}5. Copy data from the temp table into the new table.{Environment.NewLine}6. Delete the temp table.");
        }
        Expression.Execute();
    }

    public IAlterTableColumnOptionBuilder WithDefault(SystemMethods method)
    {
        CurrentColumn.DefaultValue = method;
        return this;
    }

    public IAlterTableColumnOptionBuilder WithDefaultValue(object value)
    {
        if (CurrentColumn.ModificationType == ModificationType.Alter)
        {
            var dc = new AlterDefaultConstraintExpression(_context)
            {
                TableName = Expression.TableName,
                ColumnName = CurrentColumn.Name,
                DefaultValue = value,
            };

            Expression.Expressions.Add(dc);
        }

        CurrentColumn.DefaultValue = value;
{'fraction_non_alphanumeric': 0.0748572636921125, 'fraction_numerical': 0.0025375343624444912, 'mean_word_length': 3.6739130434782608, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '6747351', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1220, 'n_words': 280}