]> git.openstreetmap.org Git - rails.git/blob - db/migrate/046_alter_user_roles_and_blocks.rb
Fix rubocop warnings
[rails.git] / db / migrate / 046_alter_user_roles_and_blocks.rb
1 require "migrate"
2
3 class AlterUserRolesAndBlocks < ActiveRecord::Migration[4.2]
4   class UserRole < ApplicationRecord
5   end
6
7   def self.up
8     # the initial granter IDs can be "self" - there are none of these
9     # in the current live DB, but there may be some in people's own local
10     # copies.
11     add_column :user_roles, :granter_id, :bigint
12     UserRole.update_all("granter_id = user_id")
13     change_column :user_roles, :granter_id, :bigint, :null => false
14     add_foreign_key :user_roles, :users, :column => :granter_id, :name => "user_roles_granter_id_fkey"
15
16     # make sure that [user_id, role] is unique
17     add_index :user_roles, [:user_id, :role], :name => "user_roles_id_role_unique", :unique => true
18
19     # change the user_blocks to have a creator_id rather than moderator_id
20     rename_column :user_blocks, :moderator_id, :creator_id
21
22     # change the "end_at" column to the more grammatically correct "ends_at"
23     rename_column :user_blocks, :end_at, :ends_at
24   end
25
26   def self.down
27     rename_column :user_blocks, :ends_at, :end_at
28     rename_column :user_blocks, :creator_id, :moderator_id
29     remove_index :user_roles, :name => "user_roles_id_role_unique"
30     remove_column :user_roles, :granter_id
31   end
32 end