]> git.openstreetmap.org Git - rails.git/blob - db/migrate/018_move_to_innodb.rb
Fixing the migration so that it will better match the live databetter.
[rails.git] / db / migrate / 018_move_to_innodb.rb
1 class MoveToInnodb < ActiveRecord::Migration
2   @@conv_tables = ['nodes', 'ways', 'way_tags', 'way_nodes',
3     'current_way_tags', 'relation_members',
4     'relations', 'relation_tags', 'current_relation_tags']
5
6   @@ver_tbl = ['nodes', 'ways', 'relations']
7
8   def self.up
9     execute 'DROP INDEX current_way_tags_v_idx ON current_way_tags'
10     execute 'DROP INDEX current_relation_tags_v_idx ON current_relation_tags'
11
12     @@ver_tbl.each { |tbl|
13       change_column tbl, "version", :bigint, :limit => 20, :null => false
14     }
15
16     @@conv_tables.each { |tbl|
17       execute "ALTER TABLE #{tbl} ENGINE = InnoDB"
18     }
19
20     @@ver_tbl.each { |tbl|
21       add_column "current_#{tbl}", "version", :bigint, :limit => 20, :null => false
22       execute "UPDATE current_#{tbl} SET version = " +
23         "(SELECT max(version) FROM #{tbl} WHERE #{tbl}.id = current_#{tbl}.id)"
24     }
25   end
26
27   def self.down
28     raise IrreversibleMigration.new
29   end
30 end