]> git.openstreetmap.org Git - rails.git/blob - db/migrate/054_refactor_map_bug_tables.rb
Modernise use of find and update_all in database migrations
[rails.git] / db / migrate / 054_refactor_map_bug_tables.rb
1 require 'migrate'
2
3 class RefactorMapBugTables < ActiveRecord::Migration
4   def self.up
5     create_table :map_bug_comment do |t|
6       t.column :bug_id, :bigint, :null => false
7       t.boolean :visible, :null => false 
8       t.datetime :date_created, :null => false
9       t.string :commenter_name
10       t.string :commenter_ip
11       t.column :commenter_id, :bigint
12       t.string :comment
13     end
14
15     remove_column :map_bugs, :text 
16
17     change_column :map_bug_comment, :id, :bigint
18
19     add_index :map_bug_comment, [:bug_id], :name => "map_bug_comment_id_idx"
20
21     add_foreign_key :map_bug_comment, [:bug_id], :map_bugs, [:id]
22     add_foreign_key :map_bug_comment, [:commenter_id], :users, [:id]
23   end
24
25   def self.down
26     remove_foreign_key :map_bug_comment, [:commenter_id]
27     remove_foreign_key :map_bug_comment, [:bug_id]
28
29     remove_index :map_bugs, :name => "map_bug_comment_id_idx"
30
31     add_column :map_bugs, :text, :string
32
33     drop_table :map_bug_comment
34   end
35 end