Sha256: d31847b7c02cc514bc4020038b6ee0ad1e8e51d5ed76227ab2a90c21a1b106a6

Contents?: true

Size: 1.47 KB

Versions: 155

Compression:

Stored size: 1.47 KB

Contents

# frozen-string-literal: true

module Sequel::Database::SplitAlterTable
  private

  # Preprocess the array of operations.  If it looks like some operations depend
  # on results of earlier operations and may require reloading the schema to
  # work correctly, split those operations into separate lists, and between each
  # list, remove the cached schema so that the later operations deal with the
  # then current table schema.
  def apply_alter_table(name, ops)
    modified_columns = []
    op_groups = [[]]
    ops.each do |op|
      case op[:op]
      when :add_column, :set_column_type, :set_column_null, :set_column_default
        if modified_columns.include?(op[:name])
          op_groups << []
        else
          modified_columns << op[:name]
        end
      when :rename_column
        if modified_columns.include?(op[:name]) || modified_columns.include?(op[:new_name])
          op_groups << []
        end
        modified_columns << op[:name] unless modified_columns.include?(op[:name])
        modified_columns << op[:new_name] unless modified_columns.include?(op[:new_name])
      end
      if split_alter_table_op?(op)
        op_groups << []
      end
      op_groups.last << op
    end

    op_groups.each do |opgs|
      next if opgs.empty?
      alter_table_sql_list(name, opgs).each{|sql| execute_ddl(sql)}
      remove_cached_schema(name)
    end
  end

  # Whether the given alter table op should start a new group.
  def split_alter_table_op?(op)
    false
  end
end

Version data entries

155 entries across 136 versions & 2 rubygems

Version Path
sequel-5.69.0 lib/sequel/adapters/utils/split_alter_table.rb
sequel-5.68.0 lib/sequel/adapters/utils/split_alter_table.rb
sequel-5.67.0 lib/sequel/adapters/utils/split_alter_table.rb
sequel-5.66.0 lib/sequel/adapters/utils/split_alter_table.rb
sequel-5.65.0 lib/sequel/adapters/utils/split_alter_table.rb
sequel-5.64.0 lib/sequel/adapters/utils/split_alter_table.rb
sequel-5.63.0 lib/sequel/adapters/utils/split_alter_table.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/sequel-5.62.0/lib/sequel/adapters/utils/split_alter_table.rb
sequel-5.62.0 lib/sequel/adapters/utils/split_alter_table.rb
sequel-5.61.0 lib/sequel/adapters/utils/split_alter_table.rb
sequel-5.60.1 lib/sequel/adapters/utils/split_alter_table.rb
sequel-5.60.0 lib/sequel/adapters/utils/split_alter_table.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/sequel-5.59.0/lib/sequel/adapters/utils/split_alter_table.rb
sequel-5.59.0 lib/sequel/adapters/utils/split_alter_table.rb
sequel-5.58.0 lib/sequel/adapters/utils/split_alter_table.rb
sequel-5.57.0 lib/sequel/adapters/utils/split_alter_table.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/sequel-5.56.0/lib/sequel/adapters/utils/split_alter_table.rb
sequel-5.56.0 lib/sequel/adapters/utils/split_alter_table.rb
sequel-5.55.0 lib/sequel/adapters/utils/split_alter_table.rb
sequel-5.54.0 lib/sequel/adapters/utils/split_alter_table.rb