module Sequel::Database::SplitAlterTable

Private Instance Methods

apply_alter_table(name, ops) click to toggle source

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.

   # File lib/sequel/adapters/utils/split_alter_table.rb
11 def apply_alter_table(name, ops)
12   modified_columns = []
13   op_groups = [[]]
14   ops.each do |op|
15     case op[:op]
16     when :add_column, :set_column_type, :set_column_null, :set_column_default
17       if modified_columns.include?(op[:name])
18         op_groups << []
19       else
20         modified_columns << op[:name]
21       end
22     when :rename_column
23       if modified_columns.include?(op[:name]) || modified_columns.include?(op[:new_name])
24         op_groups << []
25       end
26       modified_columns << op[:name] unless modified_columns.include?(op[:name])
27       modified_columns << op[:new_name] unless modified_columns.include?(op[:new_name])
28     end
29     if split_alter_table_op?(op)
30       op_groups << []
31     end
32     op_groups.last << op
33   end
34 
35   op_groups.each do |opgs|
36     next if opgs.empty?
37     alter_table_sql_list(name, opgs).each{|sql| execute_ddl(sql)}
38     remove_cached_schema(name)
39   end
40 end
split_alter_table_op?(op) click to toggle source

Whether the given alter table op should start a new group.

   # File lib/sequel/adapters/utils/split_alter_table.rb
43 def split_alter_table_op?(op)
44   false
45 end