5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/mover/table.rb', line 5
def create_movable_table(type, options={})
movable_table = [ type, table_name ].join('_')
columns =
if options[:columns]
options[:columns].collect { |c| "`#{c}`" }.join(', ')
else
'*'
end
engine = options[:engine]
engine ||=
if connection.class.to_s.include?('Mysql')
"ENGINE=InnoDB"
end
if table_exists? and !connection.table_exists?(movable_table)
connection.execute("CREATE TABLE \#{movable_table} \#{engine}\nAS SELECT \#{columns}\nFROM \#{table_name}\nWHERE false;\n")
options[:indexes] ||= indexed_columns(table_name)
options[:indexes].each do |column|
connection.add_index(movable_table, column)
end
end
end
|