openstreetmap-website/db/migrate/014_move_to_innodb.rb
Gabriel Ebner 9274a6010a api06: Fix the version-numbers-on-current-tables migration: We want the rows
in the current table to have the same version number as the latest one in the
history table (the latest version is kept in both the current and the history
tables.)
2008-05-04 10:04:07 +00:00

30 lines
949 B
Ruby

class MoveToInnodb < ActiveRecord::Migration
@@conv_tables = ['nodes', 'ways', 'way_tags', 'way_nodes',
'current_way_nodes', 'current_way_tags', 'relation_members',
'relations', 'relation_tags', 'current_relation_tags']
@@ver_tbl = ['nodes', 'ways', 'relations']
def self.up
execute 'DROP INDEX current_way_tags_v_idx ON current_way_tags'
execute 'DROP INDEX current_relation_tags_v_idx ON current_relation_tags'
@@ver_tbl.each { |tbl|
change_column tbl, "version", :bigint, :limit => 20, :null => false
}
@@conv_tables.each { |tbl|
execute "ALTER TABLE #{tbl} ENGINE = InnoDB"
}
@@ver_tbl.each { |tbl|
add_column "current_#{tbl}", "version", :bigint, :limit => 20, :null => false
execute "UPDATE current_#{tbl} SET version = " +
"(SELECT max(version) FROM #{tbl} WHERE #{tbl}.id = current_#{tbl}.id)"
}
end
def self.down
raise IrreversibleMigration.new
end
end