protected override void Generate(RenameIndexOperation operation, IModel model, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); if (model == null) { throw new NotSupportedException(string.Format(NotSupported, operation.GetType().Name)); } var index = FindEntityType(model, null, operation.Table).GetIndexes().Single(i => _annotations.For(i).Name == operation.NewName); var dropIndexOperation = new DropIndexOperation { Name = operation.Name, IsDestructiveChange = true, Table = operation.Table }; builder.EndCommand(); Generate(dropIndexOperation, model, builder); var createIndexOperation = new CreateIndexOperation { Columns = index.Properties.Select(p => p.Name).ToArray(), IsUnique = index.IsUnique, Name = operation.NewName, Table = operation.Table }; builder.EndCommand(); Generate(createIndexOperation, model, builder); }
/// <summary> /// Builds commands for the given <see cref="RenameIndexOperation" /> /// by making calls on the given <see cref="MigrationCommandListBuilder" />. /// </summary> /// <param name="operation"> The operation. </param> /// <param name="model"> The target model which may be <see langword="null" /> if the operations exist without a model. </param> /// <param name="builder"> The command builder to use to build the commands. </param> protected override void Generate(RenameIndexOperation operation, IModel model, MigrationCommandListBuilder builder) { var index = model?.GetRelationalModel().FindTable(operation.Table, operation.Schema) ?.Indexes.FirstOrDefault(i => i.Name == operation.NewName); if (index == null) { throw new NotSupportedException( SqliteStrings.InvalidMigrationOperation(operation.GetType().ShortDisplayName())); } var dropOperation = new DropIndexOperation { Schema = operation.Schema, Table = operation.Table, Name = operation.Name }; dropOperation.AddAnnotations(index.GetAnnotations()); Generate(dropOperation, model, builder, terminate: false); builder.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator); Generate(CreateIndexOperation.For(index), model, builder); }
/// <summary> /// Builds commands for the given <see cref="RenameIndexOperation"/> by making calls on the /// given <see cref="MigrationCommandListBuilder"/>. /// </summary> /// <param name="operation">The operation.</param> /// <param name="model"> /// The target model which may be <c>null</c> if the operations exist without a model. /// </param> /// <param name="builder">The command builder to use to build the commands.</param> protected override void Generate(RenameIndexOperation operation, IModel model, MigrationCommandListBuilder builder) { var index = FindEntityTypes(model, operation.Schema, operation.Table) ?.SelectMany(t => t.GetDeclaredIndexes()).Where(i => i.Relational().Name == operation.NewName) .FirstOrDefault(); if (index == null) { throw new NotSupportedException( SqliteStrings.InvalidMigrationOperation(operation.GetType().ShortDisplayName())); } var dropOperation = new DropIndexOperation { Schema = operation.Schema, Table = operation.Table, Name = operation.Name }; dropOperation.AddAnnotations(_migrationsAnnotations.ForRemove(index)); var createOperation = new CreateIndexOperation { IsUnique = index.IsUnique, Name = operation.NewName, Schema = operation.Schema, Table = operation.Table, Columns = index.Properties.Select(p => p.Relational().ColumnName).ToArray(), Filter = index.Relational().Filter }; createOperation.AddAnnotations(_migrationsAnnotations.For(index)); Generate(dropOperation, model, builder, terminate: false); builder.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator); Generate(createOperation, model, builder); }
protected override void Generate(RenameIndexOperation operation, IModel model, MigrationCommandListBuilder builder) { throw new NotSupportedException(SqliteStrings.InvalidMigrationOperation(operation.GetType().ShortDisplayName())); }