Пример #1
0
        /// <summary>
        /// Internal add column routine
        /// </summary>
        internal async Task <(SyncContext context, bool dropped)> InternalDropColumnAsync(IScopeInfo scopeInfo, SyncContext context, string droppedColumnName, DbTableBuilder tableBuilder, DbConnection connection, DbTransaction transaction, CancellationToken cancellationToken, IProgress <ProgressArgs> progress)
        {
            if (tableBuilder.TableDescription.Columns.Count <= 0)
            {
                throw new MissingsColumnException(tableBuilder.TableDescription.GetFullName());
            }

            if (tableBuilder.TableDescription.PrimaryKeys.Count <= 0)
            {
                throw new MissingPrimaryKeyException(tableBuilder.TableDescription.GetFullName());
            }

            using var command = await tableBuilder.GetDropColumnCommandAsync(droppedColumnName, connection, transaction).ConfigureAwait(false);

            if (command == null)
            {
                return(context, false);
            }

            var(tableName, _) = this.Provider.GetParsers(tableBuilder.TableDescription, scopeInfo.Setup);

            var action = await this.InterceptAsync(new ColumnDroppingArgs(context, droppedColumnName, tableBuilder.TableDescription, tableName, command, connection, transaction), progress, cancellationToken).ConfigureAwait(false);

            if (action.Cancel || action.Command == null)
            {
                return(context, false);
            }

            await this.InterceptAsync(new DbCommandArgs(context, action.Command, connection, transaction), progress, cancellationToken).ConfigureAwait(false);

            await action.Command.ExecuteNonQueryAsync().ConfigureAwait(false);

            await this.InterceptAsync(new ColumnDroppedArgs(context, droppedColumnName, tableBuilder.TableDescription, tableName, connection, transaction), progress, cancellationToken).ConfigureAwait(false);

            action.Command.Dispose();

            return(context, true);
        }