BigW Consortium Gitlab

20141007100818_add_visibility_level_to_snippet.rb 947 Bytes
Newer Older
1
# rubocop:disable all
2
class AddVisibilityLevelToSnippet < ActiveRecord::Migration
3
  include Gitlab::Database::MigrationHelpers
4

5 6 7
  def up
    add_column :snippets, :visibility_level, :integer, :default => 0, :null => false

8 9
    execute("UPDATE snippets SET visibility_level = #{Gitlab::VisibilityLevel::PRIVATE} WHERE private = #{true_value}")
    execute("UPDATE snippets SET visibility_level = #{Gitlab::VisibilityLevel::INTERNAL} WHERE private = #{false_value}")
10 11 12 13 14 15 16 17

    add_index :snippets, :visibility_level

    remove_column :snippets, :private
  end

  def down
    add_column :snippets, :private, :boolean, :default => false, :null => false
18

19 20
    execute("UPDATE snippets SET private = #{false_value} WHERE visibility_level = #{Gitlab::VisibilityLevel::INTERNAL}")
    execute("UPDATE snippets SET private = #{true_value} WHERE visibility_level = #{Gitlab::VisibilityLevel::PRIVATE}")
21

22 23 24
    remove_column :snippets, :visibility_level
  end
end