summaryrefslogtreecommitdiff
path: root/db/migrate/20141007100818_add_visibility_level_to_snippet.rb
blob: 7f125acb5d1d2803e15ab6f88533796373749518 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class AddVisibilityLevelToSnippet < ActiveRecord::Migration
  def up
    add_column :snippets, :visibility_level, :integer, :default => 0, :null => false

    Snippet.where(private: true).update_all(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
    Snippet.where(private: false).update_all(visibility_level: Gitlab::VisibilityLevel::INTERNAL)

    add_index :snippets, :visibility_level

    remove_column :snippets, :private
  end

  def down
    add_column :snippets, :private, :boolean, :default => false, :null => false
    
    Snippet.where(visibility_level: Gitlab::VisibilityLevel::INTERNAL).update_all(private: false)
    Snippet.where(visibility_level: Gitlab::VisibilityLevel::PRIVATE).update_all(private: true)
    
    remove_column :snippets, :visibility_level
  end
end