Commit 3b77a078 authored by Stan Hu's avatar Stan Hu

Fix more SQL migrations to use raw commands

gitlab-org/gitlab-development-kit#109
parent 0631a1e9
class UserColorScheme < ActiveRecord::Migration
include Gitlab::Database
def up
add_column :users, :color_scheme_id, :integer, null: false, default: 1
User.where(dark_scheme: true).update_all(color_scheme_id: 2)
execute("UPDATE users SET color_scheme_id = 2 WHERE dark_scheme = #{true_value}")
remove_column :users, :dark_scheme
end
......
class AddVisibilityLevelToProjects < ActiveRecord::Migration
include Gitlab::Database
def self.up
add_column :projects, :visibility_level, :integer, :default => 0, :null => false
Project.where(public: true).update_all(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
execute("UPDATE projects SET visibility_level = #{Gitlab::VisibilityLevel::PUBLIC} WHERE public = #{true_value}")
remove_column :projects, :public
end
def self.down
add_column :projects, :public, :boolean, :default => false, :null => false
Project.where(visibility_level: Gitlab::VisibilityLevel::PUBLIC).update_all(public: true)
execute("UPDATE projects SET public = #{true_value} WHERE visibility_level = #{Gitlab::VisibilityLevel::PUBLIC}")
remove_column :projects, :visibility_level
end
end
class MigrateAlreadyImportedProjects < ActiveRecord::Migration
include Gitlab::Database
def up
Project.where(imported: true).update_all(import_status: "finished")
Project.where(imported: false).update_all(import_status: "none")
execute("UPDATE projects SET import_status = 'finished' WHERE imported = #{true_value}")
execute("UPDATE projects SET import_status = 'none' WHERE imported = #{false_value}")
remove_column :projects, :imported
end
def down
add_column :projects, :imported, :boolean, default: false
Project.where(import_status: 'finished').update_all(imported: true)
execute("UPDATE projects SET imported = #{true_value} WHERE import_status = 'finished'")
end
end
......@@ -2,8 +2,8 @@ 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)
execute("UPDATE snippets SET visibility_level = #{Gitlab::VisibilityLevel::PRIVATE} WHERE private = true")
execute("UPDATE snippets SET visibility_level = #{Gitlab::VisibilityLevel::INTERNAL} WHERE private = false")
add_index :snippets, :visibility_level
......@@ -12,10 +12,10 @@ class AddVisibilityLevelToSnippet < ActiveRecord::Migration
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)
execute("UPDATE snippets SET private = false WHERE visibility_level = #{Gitlab::VisibilityLevel::INTERNAL}")
execute("UPDATE snippets SET private = true WHERE visibility_level = #{Gitlab::VisibilityLevel::PRIVATE}")
remove_column :snippets, :visibility_level
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment