Sha256: be6a2a5702d2c040ebc419920296293916b55f91fd3582cd4571bc179d076994
Contents?: true
Size: 1.26 KB
Versions: 7
Compression:
Stored size: 1.26 KB
Contents
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 op_groups.last << op end op_groups.each do |ops| next if ops.empty? alter_table_sql_list(name, ops).each{|sql| execute_ddl(sql)} remove_cached_schema(name) end end end
Version data entries
7 entries across 7 versions & 1 rubygems