]> git.openstreetmap.org Git - rails.git/blob - db/migrate/20110521142405_rename_bugs_to_notes.rb
Merge remote-tracking branch 'osmlab/welcome-2'
[rails.git] / db / migrate / 20110521142405_rename_bugs_to_notes.rb
1 require 'migrate'
2
3 class RenameBugsToNotes < ActiveRecord::Migration
4   def self.up
5     rename_enumeration "map_bug_status_enum", "note_status_enum"
6     rename_enumeration "map_bug_event_enum", "note_event_enum"
7
8     rename_table :map_bugs, :notes
9     rename_index :notes, "map_bugs_pkey", "notes_pkey"
10     rename_index :notes, "map_bugs_changed_idx", "notes_updated_at_idx"
11     rename_index :notes, "map_bugs_created_idx", "notes_created_at_idx"
12     rename_index :notes, "map_bugs_tile_idx", "notes_tile_status_idx"
13
14     remove_foreign_key :map_bug_comment, [:bug_id], :map_bugs, [:id]
15     rename_column :map_bug_comment, :author_id, :commenter_id
16     remove_foreign_key :map_bug_comment, [:commenter_id], :users, [:id]
17     rename_column :map_bug_comment, :commenter_id, :author_id
18
19     rename_table :map_bug_comment, :note_comments
20     rename_column :note_comments, :bug_id, :note_id
21     rename_index :note_comments, "map_bug_comment_pkey", "note_comments_pkey"
22     rename_index :note_comments, "map_bug_comment_id_idx", "note_comments_note_id_idx"
23
24     add_foreign_key :note_comments, [:note_id], :notes, [:id]
25     add_foreign_key :note_comments, [:author_id], :users, [:id]
26   end
27
28   def self.down
29     remove_foreign_key :note_comments, [:author_id], :users, [:id]
30     remove_foreign_key :note_comments, [:note_id], :notes, [:id]
31
32     rename_index :note_comments, "note_comments_note_id_idx", "map_bug_comment_id_idx"
33     rename_index :notes, "note_comments_pkey", "map_bug_comment_pkey"
34     rename_column :note_comments, :note_id, :bug_id
35     rename_table :note_comments, :map_bug_comment
36
37     rename_column :map_bug_comment, :author_id, :commenter_id
38     add_foreign_key :map_bug_comment, [:commenter_id], :users, [:id]
39     rename_column :map_bug_comment, :commenter_id, :author_id
40     add_foreign_key :map_bug_comment, [:bug_id], :notes, [:id]
41
42     rename_index :notes, "notes_tile_status_idx", "map_bugs_tile_idx"
43     rename_index :notes, "notes_created_at_idx", "map_bugs_created_idx"
44     rename_index :notes, "notes_updated_at_idx", "map_bugs_changed_idx"
45     rename_index :notes, "notes_pkey", "map_bugs_pkey"
46     rename_table :notes, :map_bugs
47
48     rename_enumeration "note_event_enum", "map_bug_event_enum"
49     rename_enumeration "note_status_enum", "map_bug_status_enum"
50   end
51 end